diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2019-05-13 15:50:23 +0700 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2019-05-15 17:36:50 +0700 |
commit | bedb9a3e6d644e4d8c71f92038ce31c9383e0887 (patch) | |
tree | 81f13a4061a2bd00518a975e3e0b11c4c0a3bab3 /app/controllers/concerns | |
parent | 224c01033fa8eafe53dd1b1d2dfdd90605a000bb (diff) | |
download | gitlab-ce-bedb9a3e6d644e4d8c71f92038ce31c9383e0887.tar.gz |
Avoid passing not_found_or_authorized_proc around
Since this needs to be called on every find_routable!(Project, ...
we can instead move it to a RoutableActions check.
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/project_unauthorized.rb | 14 | ||||
-rw-r--r-- | app/controllers/concerns/routable_actions.rb | 12 |
2 files changed, 15 insertions, 11 deletions
diff --git a/app/controllers/concerns/project_unauthorized.rb b/app/controllers/concerns/project_unauthorized.rb index d42363b8b17..7238840440f 100644 --- a/app/controllers/concerns/project_unauthorized.rb +++ b/app/controllers/concerns/project_unauthorized.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true module ProjectUnauthorized - def project_unauthorized_proc - lambda do |project| - if project - label = project.external_authorization_classification_label + module ControllerActions + def self.on_routable_not_found + lambda do |routable| + return unless routable.is_a?(Project) + + label = routable.external_authorization_classification_label rejection_reason = nil unless ::Gitlab::ExternalAuthorization.access_allowed?(current_user, label) @@ -12,9 +14,7 @@ module ProjectUnauthorized rejection_reason ||= _('External authorization denied access to this project') end - if rejection_reason - access_denied!(rejection_reason) - end + access_denied!(rejection_reason) if rejection_reason end end end diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index 236f095ae31..ff9b0332c97 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -3,13 +3,13 @@ module RoutableActions extend ActiveSupport::Concern - def find_routable!(routable_klass, requested_full_path, extra_authorization_proc: nil, not_found_or_authorized_proc: nil) + def find_routable!(routable_klass, requested_full_path, extra_authorization_proc: nil) routable = routable_klass.find_by_full_path(requested_full_path, follow_redirects: request.get?) if routable_authorized?(routable, extra_authorization_proc) ensure_canonical_path(routable, requested_full_path) routable else - perform_not_found_actions(routable, [not_found_or_authorized_proc]) + perform_not_found_actions(routable, not_found_actions) route_not_found unless performed? @@ -17,11 +17,15 @@ module RoutableActions end end + def not_found_actions + [ProjectUnauthorized::ControllerActions.on_routable_not_found] + end + def perform_not_found_actions(routable, actions) - actions.compact.each do |action| + actions.each do |action| break if performed? - action.call(routable) + instance_exec(routable, &action) end end |