From: Andy Allan Date: Wed, 20 Mar 2019 14:07:33 +0000 (+0100) Subject: Use a lambda in order to pass parameters in before_actions X-Git-Tag: live~3188^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/dad36f2fca68142c53875cdacc55192d1561effd 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. --- diff --git a/app/controllers/api/changesets_controller.rb b/app/controllers/api/changesets_controller.rb index 8841d4b3b..fb6523f4e 100644 --- a/app/controllers/api/changesets_controller.rb +++ b/app/controllers/api/changesets_controller.rb @@ -12,7 +12,6 @@ module Api 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_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_timeout, :except => [:upload] diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 0fccbb506..ebdd2cd80 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -3,7 +3,7 @@ class BrowseController < ApplicationController before_action :authorize_web before_action :set_locale - before_action(:except => [:query]) { |c| c.check_database_readable(true) } + before_action -> { check_database_readable(true) } before_action :require_oauth around_action :web_timeout authorize_resource :class => false diff --git a/app/controllers/changeset_comments_controller.rb b/app/controllers/changeset_comments_controller.rb index 05b28eacf..4abffb90e 100644 --- a/app/controllers/changeset_comments_controller.rb +++ b/app/controllers/changeset_comments_controller.rb @@ -4,7 +4,7 @@ class ChangesetCommentsController < ApplicationController authorize_resource - before_action(:only => [:index]) { |c| c.check_database_readable(true) } + before_action -> { check_database_readable(true) } around_action :web_timeout ## diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index fff9f543b..32d9fd733 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -7,7 +7,7 @@ class ChangesetsController < ApplicationController skip_before_action :verify_authenticity_token, :except => [:index] before_action :authorize_web 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