summaryrefslogtreecommitdiff
path: root/app/controllers/clusters/base_controller.rb
diff options
context:
space:
mode:
authorConstance Okoghenun <constanceokoghenun@gmail.com>2018-11-05 10:33:05 +0100
committerConstance Okoghenun <constanceokoghenun@gmail.com>2018-11-05 10:33:05 +0100
commit3bac1a322c82dd9b6e9b23edd66fa45afaa9859f (patch)
treed3e7d47a3e0c8047cb2972aefbc12fe1e3080ef8 /app/controllers/clusters/base_controller.rb
parentfe7b6f57120946a5d5fe4a4d54a245dc76b06dc8 (diff)
parent9e2eb85e365e2a33e52e3f1f48cc23ad4201a52b (diff)
downloadgitlab-ce-issue_51323.tar.gz
Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into issue_51323issue_51323
Diffstat (limited to 'app/controllers/clusters/base_controller.rb')
-rw-r--r--app/controllers/clusters/base_controller.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/controllers/clusters/base_controller.rb b/app/controllers/clusters/base_controller.rb
new file mode 100644
index 00000000000..ef42f7c4074
--- /dev/null
+++ b/app/controllers/clusters/base_controller.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class Clusters::BaseController < ApplicationController
+ include RoutableActions
+
+ skip_before_action :authenticate_user!
+ before_action :authorize_read_cluster!
+
+ helper_method :clusterable
+
+ private
+
+ def cluster
+ @cluster ||= clusterable.clusters.find(params[:id])
+ .present(current_user: current_user)
+ end
+
+ def authorize_update_cluster!
+ access_denied! unless can?(current_user, :update_cluster, cluster)
+ end
+
+ def authorize_admin_cluster!
+ access_denied! unless can?(current_user, :admin_cluster, cluster)
+ end
+
+ def authorize_read_cluster!
+ access_denied! unless can?(current_user, :read_cluster, clusterable)
+ end
+
+ def authorize_create_cluster!
+ access_denied! unless can?(current_user, :create_cluster, clusterable)
+ end
+
+ def clusterable
+ raise NotImplementedError
+ end
+end