Use a lambda in order to pass parameters in before_actions

This avoid calling methods on a new instance of the controller, and
therefore allows these methods to be marked as private.

As a bonus, rubocop can now parse them and warn when they refer to
actions that don't exist in the controller.
This commit is contained in:
Andy Allan 2019-03-20 15:07:33 +01:00
parent 94d19ae567
commit dad36f2fca
4 changed files with 3 additions and 4 deletions

View file

@ -12,7 +12,6 @@ module Api
before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe] before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe] before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe]
before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :subscribe, :unsubscribe] before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :subscribe, :unsubscribe]
before_action(:only => [:index, :feed]) { |c| c.check_database_readable(true) }
around_action :api_call_handle_error around_action :api_call_handle_error
around_action :api_call_timeout, :except => [:upload] around_action :api_call_timeout, :except => [:upload]

View file

@ -3,7 +3,7 @@ class BrowseController < ApplicationController
before_action :authorize_web before_action :authorize_web
before_action :set_locale before_action :set_locale
before_action(:except => [:query]) { |c| c.check_database_readable(true) } before_action -> { check_database_readable(true) }
before_action :require_oauth before_action :require_oauth
around_action :web_timeout around_action :web_timeout
authorize_resource :class => false authorize_resource :class => false

View file

@ -4,7 +4,7 @@ class ChangesetCommentsController < ApplicationController
authorize_resource authorize_resource
before_action(:only => [:index]) { |c| c.check_database_readable(true) } before_action -> { check_database_readable(true) }
around_action :web_timeout around_action :web_timeout
## ##

View file

@ -7,7 +7,7 @@ class ChangesetsController < ApplicationController
skip_before_action :verify_authenticity_token, :except => [:index] skip_before_action :verify_authenticity_token, :except => [:index]
before_action :authorize_web before_action :authorize_web
before_action :set_locale before_action :set_locale
before_action(:only => [:index, :feed]) { |c| c.check_database_readable(true) } before_action -> { check_database_readable(true) }, :only => [:index, :feed]
authorize_resource authorize_resource