Commit f0bd3b4d authored by dgt's avatar dgt Committed by azul

Some preparations for rails 5.1

update some gems, replace before_filter / after_filter by before_action / after_action
and some more config changes (mostly commented out) and scripts generated by rails app:update task
parent 1189f70b
......@@ -11,6 +11,7 @@ end
##
# Rails is the framework we use.
#gem 'rails', '~> 5.1.6'
gem 'rails', '~> 5.0.7'
# Security updates
......@@ -30,7 +31,7 @@ gem 'i18n', '~> 0.7'
# improved gem to access mysql database
# locking in to latest major to fix API
gem 'mysql2', '~> 0.3.18'
gem 'mysql2', '~> 0.5.2'
# parsing and generating JSON
# locking in to latest major to fix API
......@@ -38,8 +39,8 @@ gem 'json', '~> 1.8'
# Markup language that uses indent to indicate nesting
# locking in to latest major to fix API
gem 'haml', '~> 4.0'
gem 'haml-rails', '~> 0.9.0'
gem 'haml', '~> 5.0'
gem 'haml-rails', '~> 1.0'
# Extendet scriptable CSS language
# locking in to latest major to fix API
......@@ -56,6 +57,7 @@ gem 'sass'
# tests do not pass
#gem 'prototype-rails', github: 'rails/prototype-rails', branch: '4.2'
gem 'prototype-rails', path: 'vendor/gems/prototype-rails'
#gem 'prototype-rails', path: '/home/dora/Dev/crabgrass_project/2018/august/prototype-rails-5-1'
# Full text search for the database
gem 'thinking-sphinx', '~> 3.4.2'
......@@ -150,6 +152,9 @@ gem 'greencloth', require: 'greencloth',
# version is rather strict for now as api may still change.
gem 'crabgrass_media', '~> 0.3.0', require: 'media',
path: 'vendor/gems/crabgrass-media'
#gem 'crabgrass_media', '~> 0.4.0', require: 'media',
# path: '/home/dora/Dev/crabgrass_project/crabgrass-media'
##
## not required, but a really good idea
......
......@@ -106,12 +106,13 @@ GEM
activesupport (>= 4.2.0)
gpgme (2.0.16)
mini_portile2 (~> 2.3)
haml (4.0.7)
haml (5.0.4)
temple (>= 0.8.0)
tilt
haml-rails (0.9.0)
haml-rails (1.0.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 4.0.6, < 5.0)
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
html2haml (2.1.0)
......@@ -143,7 +144,7 @@ GEM
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.10.3)
mysql2 (0.3.21)
mysql2 (0.5.2)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
......@@ -219,6 +220,7 @@ GEM
sqlite3 (1.3.13)
sys-uname (0.9.0)
ffi (>= 1.0.0)
temple (0.8.0)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
......@@ -274,8 +276,8 @@ DEPENDENCIES
factory_bot_rails
faker (~> 1.0.0)
greencloth!
haml (~> 4.0)
haml-rails (~> 0.9.0)
haml (~> 5.0)
haml-rails (~> 1.0)
http_accept_language (~> 2.0)
i18n (~> 0.7)
json (~> 1.8)
......@@ -283,7 +285,7 @@ DEPENDENCIES
mail-gpg (~> 0.3.3)
mime-types
minitest (~> 5.10.3)
mysql2 (~> 0.3.18)
mysql2 (~> 0.5.2)
nokogiri (~> 1.8.5)
phantomjs-binaries (~> 2.1.1)
poltergeist (~> 1.5)
......
class AssetsController < ApplicationController
before_filter :symlink_public_asset, only: :show
before_action :symlink_public_asset, only: :show
after_action :verify_authorized
prepend_before_filter :fetch_asset, only: %i[show destroy]
prepend_before_action :fetch_asset, only: %i[show destroy]
def show
authorize @asset
......
......@@ -71,7 +71,7 @@ module Common::Application::Authentication
session[:return_to] = nil
end
# When called with before_filter :login_from_cookie will check for an :auth_token
# When called with before_action :login_from_cookie will check for an :auth_token
# cookie and log the user back in if apropriate
def login_from_cookie
return unless cookies[:auth_token] && !logged_in?
......@@ -85,7 +85,7 @@ module Common::Application::Authentication
end
# note: this method is not automatically called. if you want to enable HTTP
# authentication for some action(s), you must put a prepend_before_filter in
# authentication for some action(s), you must put a prepend_before_action in
# place.
# however, a user who successfully uses HTTP auth on an action for which it
# was enabled will stay logged in and can then go and see other things.
......
......@@ -14,10 +14,10 @@ module Common::Application::BeforeFilters
included do
# the order of these filters matters. change with caution.
before_filter :set_session_locale
before_filter :set_session_timezone
before_filter :header_hack_for_ie6
before_filter :redirect_unverified_user
before_action :set_session_locale
before_action :set_session_timezone
before_action :header_hack_for_ie6
before_action :redirect_unverified_user
end
private
......@@ -48,11 +48,11 @@ module Common::Application::BeforeFilters
#
# To not require logins for specific actions, use this in your controllers:
#
# skip_before_filter :login_required, :only => [ :view, :index ]
# skip_before_action :login_required, :only => [ :view, :index ]
#
# To not require them for any action:
#
# skip_before_filter :login_required
# skip_before_action :login_required
#
def login_required
process_login
......
......@@ -217,7 +217,7 @@ module Common::Application::RescueErrors
def render_error_js(exception = nil, options = {})
error exception if exception.present?
log_exception(exception)
return if performed? # error in after_filter
return if performed? # error in after_action
render template: 'error/alert', locals: { exception: exception },
status: options[:status]
end
......
#
# controllers including this must have a before_filter setup()
# controllers including this must have a before_action setup()
# which must set @entity and @success_url
#
......
......@@ -12,10 +12,10 @@ module Common::Requests
helper_method :current_state
helper_method :request_path
helper_method :requests_path
before_filter :fetch_request, only: %i[update destroy show]
before_action :fetch_request, only: %i[update destroy show]
after_filter :create_notices, only: :create
after_filter :dismiss_notices, only: :update
after_action :create_notices, only: :create
after_action :dismiss_notices, only: :update
end
#
......
......@@ -4,7 +4,7 @@
#
# This module makes creating the records from the controller easy.
#
# If you follow the conventions all you need to do is add a after_filter for
# If you follow the conventions all you need to do is add a after_action for
# the actions you want to track:
#
# class Groups::GroupsController < ...
......@@ -12,7 +12,7 @@
# ...
#
# This will have the same effect as an after filter for track_action:
# after_filter :track_action, only: [:create, :destroy]
# after_action :track_action, only: [:create, :destroy]
#
# track_action will call Action.track(:create_group, options). It will include
# the following default arguments if the corresponding variables are set:
......@@ -54,7 +54,7 @@ module Common::Tracking::Action
module ClassMethods
def track_actions(*actions)
options = actions.extract_options!
after_filter :track_action, options.merge(only: actions)
after_action :track_action, options.merge(only: actions)
end
end
end
......@@ -9,7 +9,7 @@
#
class CronController < ActionController::Base
before_filter :allow_only_requests_from_localhost
before_action :allow_only_requests_from_localhost
def run
case params[:id]
......
if Rails.env.development?
class DebugController < ApplicationController
before_filter :authorization_required
before_action :authorization_required
# make the user assume the identity of another user
def become
......
......@@ -13,7 +13,7 @@
#
class EntitiesController < ApplicationController
before_filter :login_required
before_action :login_required
LIMIT = 20
......
class Group::AvatarsController < Group::BaseController
include_controllers 'common/avatars'
include_controllers 'common/always_perform_caching'
before_filter :setup
before_action :setup
protected
......
class Group::BaseController < ApplicationController
before_filter :fetch_group
before_action :fetch_group
# default permission for all group controllers
before_filter :login_required
before_action :login_required
after_action :verify_authorized
helper 'group/links'
......
class Group::DirectoryController < ApplicationController
before_filter :login_required
# skip_before_filter :login_required
before_action :login_required
# skip_before_action :login_required
# ^^ for now, disable public directories. The old behavior was to require
# authentication to browse the directory, so we don't want to change this
# unexpectedly without either giving groups some warning or adding an
# additional level to the permissions.
before_filter :set_default_path
before_action :set_default_path
helper 'group/directory'
......
class Group::GroupsController < Group::BaseController
include Common::Tracking::Action
before_filter :initialize_group, only: %w[new create]
before_filter :fetch_group, only: :destroy
before_filter :fetch_associations, only: :destroy
before_action :initialize_group, only: %w[new create]
before_action :fetch_group, only: :destroy
before_action :fetch_associations, only: :destroy
after_filter :notify_former_users, only: :destroy
after_action :notify_former_users, only: :destroy
def new
......
class Group::HomeController < Group::BaseController
skip_before_filter :login_required
skip_before_action :login_required
before_filter :fetch_wikis
after_filter :track_visit, if: :logged_in?
before_action :fetch_wikis
after_action :track_visit, if: :logged_in?
layout 'sidecolumn'
helper 'wikis/base', 'wikis/sections'
......
class Group::PagesController < Group::BaseController
skip_before_filter :login_required
skip_before_action :login_required
include_controllers 'common/page_search'
......
class Group::ProfilesController < Group::BaseController
before_filter :fetch_profile
before_action :fetch_profile
helper :profile
def edit
......
class Me::AvatarsController < Me::BaseController
include_controllers 'common/avatars'
include_controllers 'common/always_perform_caching'
before_filter :setup
before_action :setup
def destroy
if avatar = @entity.avatar
......
......@@ -2,7 +2,7 @@
# Abstract super class of all the Me controllers.
#
class Me::BaseController < ApplicationController
before_filter :login_required, :fetch_user
before_action :login_required, :fetch_user
protected
......
class Me::NoticesController < Me::BaseController
before_filter :fetch_notice, only: %i[destroy]
before_action :fetch_notice, only: %i[destroy]
def index
@notices = Notice.for_user(current_user)
......
......@@ -5,7 +5,7 @@
class Me::PostsController < Me::BaseController
include_controllers 'common/posts'
prepend_before_filter :fetch_data
prepend_before_action :fetch_data
after_action :verify_authorized
# /me/discussions/green/posts
......
class Me::ProfileController < Me::BaseController
before_filter :fetch_profile
before_action :fetch_profile
helper :profile
def edit; end
......
......@@ -5,7 +5,7 @@
#
class Page::AttributesController < Page::SidebarsController
before_filter :login_required
before_action :login_required
track_actions :update
def update
......
......@@ -5,8 +5,8 @@
class Page::BaseController < ApplicationController
public
before_filter :login_required, except: :show
before_filter :bust_cache, only: :show
before_action :login_required, except: :show
before_action :bust_cache, only: :show
after_action :verify_authorized
layout 'page'
......@@ -18,16 +18,16 @@ class Page::BaseController < ApplicationController
## (the order matters!)
##
prepend_before_filter :default_fetch_data, except: :new
prepend_before_action :default_fetch_data, except: :new
append_before_filter :default_setup_options
append_before_filter :load_posts
append_before_action :default_setup_options
append_before_action :load_posts
# after_filters are processed the inside out.
# after_actions are processed the inside out.
# So whatever is defined first will be processed last
# ... after all the others
after_filter :save_if_needed, except: :create
after_filter :update_viewed, only: :show
after_action :save_if_needed, except: :create
after_action :update_viewed, only: :show
include Page::BeforeFilters
......
......@@ -15,8 +15,8 @@
class Page::CreateController < ApplicationController
include Common::Tracking::Action
before_filter :login_required
before_filter :init_options, :set_owner, :catch_cancel
before_action :login_required
before_action :init_options, :set_owner, :catch_cancel
after_action :verify_authorized, only: :create
helper 'page/share', 'page/owner', 'page/creation'
track_actions :create
......
class Page::HistoryController < Page::SidebarsController
before_filter :login_required
before_action :login_required
def show
authorize @page, :update?
......
......@@ -11,7 +11,7 @@
class Page::ParticipationsController < Page::SidebarsController
helper 'page/participation', 'page/share'
before_filter :fetch_data
before_action :fetch_data
track_actions :update
# this is used for ajax pagination
......
......@@ -5,8 +5,8 @@ class Page::PostsController < ApplicationController
helper 'page/post'
prepend_before_filter :fetch_data
before_filter :login_required, except: :show
prepend_before_action :fetch_data
before_action :login_required, except: :show
after_action :verify_authorized
track_actions :create, :update, :destroy
......
......@@ -25,8 +25,8 @@
class Page::SharesController < Page::SidebarsController
helper 'page/share', 'page/participation'
before_filter :close_popup, only: :update, if: :cancel_update?
before_filter :add_recipients, only: :update, if: :add_recipients?
before_action :close_popup, only: :update, if: :cancel_update?
before_action :add_recipients, only: :update, if: :add_recipients?
track_actions :update
# display the share or notify forms.
......@@ -44,9 +44,9 @@ class Page::SharesController < Page::SidebarsController
# there are four ways to submit the forms:
#
# (1) cancel button (params[:cancel]==true)
# -> before_filter :close_popup
# -> before_action :close_popup
# (2) add button or return in add field (params[:add]==true)
# -> before_filter :add_recipients
# -> before_action :add_recipients
# (3) share button (params[:share_button]==true)
# (3) notify button (params[:notify_button]==true)
#
......
......@@ -5,9 +5,9 @@
class Page::SidebarsController < ApplicationController
include Common::Tracking::Action
before_filter :fetch_page
before_filter :login_required
after_filter :verify_authorized
before_action :fetch_page
before_action :login_required
after_action :verify_authorized
layout false
helper 'page/base', 'page/sidebar'
......
class Page::TagsController < Page::SidebarsController
before_filter :authorize_page
before_action :authorize_page
helper 'page/tags'
SUGGESTION_COUNT = 6
......
class Person::BaseController < ApplicationController
before_filter :fetch_person
before_action :fetch_person
after_action :verify_authorized
helper 'people/base'
......
class Person::DirectoryController < ApplicationController
before_filter :login_required
before_action :login_required
# ^^ for now, disable public directories. The old behavior was to require
# authentication to browse the directory, so we don't want to change this
# unexpectedly without either giving people some warning or adding an
# additional level to the permissions.
before_filter :prepare_path
before_action :prepare_path
def index
@query ||= finder.query_term
......
class Person::FriendRequestsController < Person::BaseController
before_filter :login_required
before_action :login_required
def new
@request = RequestToFriend.new recipient: @user, created_by: current_user
......
......@@ -6,7 +6,7 @@
#
class PicturesController < ApplicationController
before_filter :fetch_picture
before_action :fetch_picture
#
# for now, all pictures are public.
......
......@@ -4,7 +4,7 @@
class SessionController < ApplicationController
layout 'notice'
skip_before_filter :redirect_unverified_user
skip_before_action :redirect_unverified_user
def login
return unless request.post?
......
......@@ -23,7 +23,7 @@
class StarsController < ApplicationController
include Common::Tracking::Action
before_filter :fetch_starred
before_action :fetch_starred
track_actions :create
def create
......@@ -43,7 +43,7 @@ class StarsController < ApplicationController
@starred = Post.find(params[:post_id])
@star = @starred.stars.where(user_id: current_user).first
# Prevent sending notifcation if the action will result in a noop.
# redirects in a before filter skip the action and after_filters.
# redirects in a before filter skip the action and after_actions.
redirect_to @starred if @star.blank? && action?(:destroy)
redirect_to @starred if @star.present? && action?(:create)
end
......
......@@ -35,7 +35,7 @@ class ThemeController < ApplicationController
# don't cache css if '_refresh' is in the theme or stylesheet name.
# useful for debugging.
prepend_before_filter :get_theme
prepend_before_action :get_theme
def get_theme
self.cache_css = true
[params[:name], *params[:file]].each do |param|
......
class Wiki::AssetsController < Wiki::BaseController
before_filter :fetch_assets, only: :new
before_action :fetch_assets, only: :new
def new
# FIXME: Authorize needed because BaseController wants us to
......
class Wiki::BaseController < ApplicationController
before_filter :fetch_wiki
before_filter :login_required
before_action :fetch_wiki
before_action :login_required
after_action :verify_authorized
helper 'wikis/base'
......
......@@ -8,7 +8,7 @@
class Wiki::WikisController < Wiki::BaseController
include Common::Tracking::Action
skip_before_filter :login_required, only: :show
skip_before_action :login_required, only: :show
track_actions :update
helper 'wikis/sections'
......
......@@ -39,7 +39,7 @@
# The needed user_participation and group_partication objects will get saved
# unless page is modified, in which case they will not get saved.
# (assuming that page.save will get called eventually, which will then save
# the new participation objects. BasePageController has an after_filter that
# the new participation objects. BasePageController has an after_action that
# auto saves the @page if has been changed.)
#
......
......@@ -136,7 +136,7 @@ module User::Pages
# should trigger a notification to page watchers. Also, if a page state changes
# from pending to resolved, we also update everyone's user participation.
# The page is not saved here, because it might still get more changes.
# An after_filter should finally save the page if it has not already been saved.
# An after_action should finally save the page if it has not already been saved.
#
# options:
# :resolved -- user's participation is resolved with this page
......
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || bundle install"
# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# system "cp config/database.yml.sample config/database.yml"
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system "bin/rake db:setup"
system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
system "rm -f log/*"
system "rm -rf tmp/cache"
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system "touch tmp/restart.txt"
system! 'bin/rails restart'
end
......@@ -16,6 +16,8 @@ module Crabgrass
class Application < Rails::Application
info 'LOAD CONFIG BLOCK'
# config.load_defaults 5.1
config.autoload_paths << "#{Rails.root}/lib"
config.autoload_paths << "#{Rails.root}/app/models"
......
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' # Set up gems listed in the Gemfile.
# Load the rails application
require File.expand_path('../application', __FILE__)
require_relative 'application'
# Initialize the rails application
Crabgrass::Application.initialize!
......@@ -36,4 +36,29 @@ Crabgrass::Application.configure do
##
require "#{Rails.root}/lib/crabgrass/debug.rb"
# FIXME: the following additional options were suggested by
# rails app:update for Rails 5.1
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.