From 5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 15 Oct 2018 16:37:51 +1300 Subject: 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/ --- .../projects/clusters/applications_controller.rb | 29 ---------------------- 1 file changed, 29 deletions(-) delete mode 100644 app/controllers/projects/clusters/applications_controller.rb (limited to 'app/controllers/projects/clusters/applications_controller.rb') diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/projects/clusters/applications_controller.rb deleted file mode 100644 index bcea96bce94..00000000000 --- a/app/controllers/projects/clusters/applications_controller.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -class Projects::Clusters::ApplicationsController < Projects::ApplicationController - before_action :cluster - before_action :authorize_read_cluster! - before_action :authorize_create_cluster!, only: [:create] - - def create - Clusters::Applications::CreateService - .new(@cluster, current_user, create_cluster_application_params) - .execute(request) - - head :no_content - rescue Clusters::Applications::CreateService::InvalidApplicationError - render_404 - rescue StandardError - head :bad_request - end - - private - - def cluster - @cluster ||= project.clusters.find(params[:id]) || render_404 - end - - def create_cluster_application_params - params.permit(:application, :hostname) - end -end -- cgit v1.2.1 From 1a1fdf8efe1923ba781e978e858c009264020e72 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Thu, 1 Nov 2018 13:39:01 +1300 Subject: Resolve controller sharing concern Use ClustersController as base while having Projects::ClustersController to inform what `clusterable` is. Thanks @ayufan for the great suggestion ! - View changes to work with new approach - Fix javascript for new approach - Fix feature specs for new approach - Fix QA --- .../projects/clusters/applications_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/controllers/projects/clusters/applications_controller.rb (limited to 'app/controllers/projects/clusters/applications_controller.rb') diff --git a/app/controllers/projects/clusters/applications_controller.rb b/app/controllers/projects/clusters/applications_controller.rb new file mode 100644 index 00000000000..c7b6218d007 --- /dev/null +++ b/app/controllers/projects/clusters/applications_controller.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class Projects::Clusters::ApplicationsController < Clusters::ApplicationsController + include ProjectUnauthorized + + prepend_before_action :project + + private + + def clusterable + @clusterable ||= ClusterablePresenter.fabricate(project, current_user: current_user) + end + + def project + @project ||= find_routable!(Project, File.join(params[:namespace_id], params[:project_id]), not_found_or_authorized_proc: project_unauthorized_proc) + end +end -- cgit v1.2.1