diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-10-15 16:37:51 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-01 18:38:36 +1300 |
commit | 5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 (patch) | |
tree | f0e4934cd4bbf59d670ff8911e64d94602907259 /app/controllers/clusters/base_controller.rb | |
parent | 5a953741820b78492333e1543062a5c222694d8c (diff) | |
download | gitlab-ce-5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5.tar.gz |
Convert clusters to use a top-level controller
In preparation so that we can create both cluster attached to project
and cluster attached to group.
- Move ClustersController to top level
- Move Clusters::ApplicationsController to top-level too
- Creates a Clusters::BaseController to share common functions
- Do not rely on @project ivar. Anything could set the ivar.
- Fix Vue page components due to new data-page value
Because of the controller change we have gone from
`projects:clusters:new` to `clusters:new`, so we need to update the file
location of the page components. There is somewhere a function that will
convert data-page to a file location.
On that note, projects/clusters/gcp/new/, translate to
Projects::Clusters::Gcp#new doesn't exist so replace that with
clusters/create_gcp/ and clusters/create_user/
Diffstat (limited to 'app/controllers/clusters/base_controller.rb')
-rw-r--r-- | app/controllers/clusters/base_controller.rb | 42 |
1 files changed, 42 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..2804b236d17 --- /dev/null +++ b/app/controllers/clusters/base_controller.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +class Clusters::BaseController < ApplicationController + include RoutableActions + + skip_before_action :authenticate_user! + before_action :require_project_id + before_action :project, if: :project_type? + before_action :repository, if: :project_type? + before_action :authorize_read_cluster! + + private + + # We can extend to `#group_type?` in the future + def require_project_id + not_found unless project_type? + end + + def project + @project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id])) + end + + def repository + @repository ||= project.repository + 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 + project if project_type? + end + + def project_type? + params[:project_id].present? + end +end |