summaryrefslogtreecommitdiff
path: root/app/controllers/clusters
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-19 14:42:30 +1300
committerThong Kuah <tkuah@gitlab.com>2018-11-01 19:36:58 +1300
commit88800abcd8741b07114c2850e00b74fbecfbf90e (patch)
tree06dcb6a6a8036164eb73df0da2cc13150357dda7 /app/controllers/clusters
parent5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 (diff)
downloadgitlab-ce-88800abcd8741b07114c2850e00b74fbecfbf90e.tar.gz
Abstract out project out of ClustersController
To the extent possible swap out `project` with `clusterable` - Abstract paths for showing cluster or clusters. This will allow us to swap in alternative paths for group level cluster - Push :project_id and :namespace_id params from the URL to the POST body. - Create a nice helper for to generate links for the destroy action For some reason, spec :project_id and :namespace_id param are not going through `to_param` for a JSON format. Manually call `to_param` to fix specs. - Move :layout to BaseController
Diffstat (limited to 'app/controllers/clusters')
-rw-r--r--app/controllers/clusters/applications_controller.rb2
-rw-r--r--app/controllers/clusters/base_controller.rb32
2 files changed, 32 insertions, 2 deletions
diff --git a/app/controllers/clusters/applications_controller.rb b/app/controllers/clusters/applications_controller.rb
index a5ac5fe3f8e..250f42f3096 100644
--- a/app/controllers/clusters/applications_controller.rb
+++ b/app/controllers/clusters/applications_controller.rb
@@ -19,7 +19,7 @@ class Clusters::ApplicationsController < Clusters::BaseController
private
def cluster
- @cluster ||= project.clusters.find(params[:id]) || render_404
+ @cluster ||= clusterable.clusters.find(params[:id]) || render_404
end
def create_cluster_application_params
diff --git a/app/controllers/clusters/base_controller.rb b/app/controllers/clusters/base_controller.rb
index 2804b236d17..2e9997dfc08 100644
--- a/app/controllers/clusters/base_controller.rb
+++ b/app/controllers/clusters/base_controller.rb
@@ -9,6 +9,10 @@ class Clusters::BaseController < ApplicationController
before_action :repository, if: :project_type?
before_action :authorize_read_cluster!
+ layout :determine_layout
+
+ helper_method :clusters_page_path, :cluster_page_path, :new_cluster_page_path
+
private
# We can extend to `#group_type?` in the future
@@ -32,8 +36,34 @@ class Clusters::BaseController < ApplicationController
access_denied! unless can?(current_user, :create_cluster, clusterable)
end
+ def determine_layout
+ if project_type?
+ 'project'
+ end
+ end
+
def clusterable
- project if project_type?
+ if project_type?
+ project
+ end
+ end
+
+ def cluster_page_path(cluster)
+ if project_type?
+ project_cluster_path(project, cluster)
+ end
+ end
+
+ def clusters_page_path
+ if project_type?
+ project_clusters_path(project)
+ end
+ end
+
+ def new_cluster_page_path
+ if project_type?
+ new_project_cluster_path(project)
+ end
end
def project_type?