diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-11-06 15:43:24 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-11-06 15:43:24 +0000 |
commit | 1208d55206128266690f46f0165df0fc10c24941 (patch) | |
tree | 93fbdde5a5db6cdd8f79f2806707dab093985aa2 /app/controllers/clusters/base_controller.rb | |
parent | d171ff60168cd55b6d7b9ee920269f44a26e577e (diff) | |
parent | d0c58a97c8a053c0beec7c13c1c6ec5042120ef1 (diff) | |
download | gitlab-ce-refactor-snippets-finder.tar.gz |
Merge branch 'master' into 'refactor-snippets-finder'refactor-snippets-finder
# Conflicts:
# spec/models/project_spec.rb
Diffstat (limited to 'app/controllers/clusters/base_controller.rb')
-rw-r--r-- | app/controllers/clusters/base_controller.rb | 37 |
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 |