diff options
author | James Fargher <proglottis@gmail.com> | 2019-05-02 13:07:38 +1200 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2019-05-07 08:37:04 +1200 |
commit | beb66cfcba26d0796644ccce2dfac8c65a808144 (patch) | |
tree | 6bb32fccb64f91776e946d84c5717d1ae52a9d7e /app/controllers | |
parent | 8db382b05545fdef0a60bcff65f8c23e8b1ed282 (diff) | |
download | gitlab-ce-beb66cfcba26d0796644ccce2dfac8c65a808144.tar.gz |
Check instance cluster feature at policy level
Try to simplify feature flag checks by using policies
Diffstat (limited to 'app/controllers')
4 files changed, 25 insertions, 19 deletions
diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index ef182b981f1..b742b7e19cf 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -4,10 +4,7 @@ # # Automatically sets the layout and ensures an administrator is logged in class Admin::ApplicationController < ApplicationController - before_action :authenticate_admin! - layout 'admin' + include EnforcesAdminAuthentication - def authenticate_admin! - render_404 unless current_user.admin? - end + layout 'admin' end diff --git a/app/controllers/admin/clusters/applications_controller.rb b/app/controllers/admin/clusters/applications_controller.rb index 3351d3ff825..7400cc16175 100644 --- a/app/controllers/admin/clusters/applications_controller.rb +++ b/app/controllers/admin/clusters/applications_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Clusters::ApplicationsController < Clusters::ApplicationsController + include EnforcesAdminAuthentication + private def clusterable diff --git a/app/controllers/admin/clusters_controller.rb b/app/controllers/admin/clusters_controller.rb index f2b54125d48..f54933de10f 100644 --- a/app/controllers/admin/clusters_controller.rb +++ b/app/controllers/admin/clusters_controller.rb @@ -1,25 +1,13 @@ # frozen_string_literal: true class Admin::ClustersController < Clusters::ClustersController - prepend_before_action :check_instance_clusters_feature_flag! + include EnforcesAdminAuthentication layout 'admin' private def clusterable - @clusterable ||= InstanceClusterablePresenter.fabricate(cluster_instance, current_user: current_user) - end - - def cluster_instance - @cluster_instance ||= Clusters::Instance.new - end - - def check_instance_clusters_feature_flag! - render_404 unless instance_clusters_enabled? - end - - def instance_clusters_enabled? - cluster_instance.instance_clusters_enabled? + @clusterable ||= InstanceClusterablePresenter.fabricate(Clusters::Instance.new, current_user: current_user) end end diff --git a/app/controllers/concerns/enforces_admin_authentication.rb b/app/controllers/concerns/enforces_admin_authentication.rb new file mode 100644 index 00000000000..3ef92730df6 --- /dev/null +++ b/app/controllers/concerns/enforces_admin_authentication.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == EnforcesAdminAuthentication +# +# Controller concern to enforce that users are authenticated as admins +# +# Upon inclusion, adds `authenticate_admin!` as a before_action +# +module EnforcesAdminAuthentication + extend ActiveSupport::Concern + + included do + before_action :authenticate_admin! + end + + def authenticate_admin! + render_404 unless current_user.admin? + end +end |