From 250a8aee258b432bc51b8f177159f4abbc31a8b9 Mon Sep 17 00:00:00 2001
From: Dennis Tang <dtang@gitlab.com>
Date: Wed, 23 May 2018 17:30:00 +0200
Subject: [PATCH] revisions

---
 .../projects/clusters_controller.rb           | 53 +++++++------------
 config/routes/project.rb                      |  2 +-
 2 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/app/controllers/projects/clusters_controller.rb b/app/controllers/projects/clusters_controller.rb
index 4c31732113c..305bef4d080 100644
--- a/app/controllers/projects/clusters_controller.rb
+++ b/app/controllers/projects/clusters_controller.rb
@@ -1,6 +1,9 @@
 class Projects::ClustersController < Projects::ApplicationController
-  before_action :cluster, except: [:index, :new, :create_cluster]
+  before_action :cluster, except: [:index, :new, :create]
   before_action :authorize_read_cluster!
+  before_action :generate_gcp_authorize_url, only: [:new]
+  before_action :new_cluster, only: [:new]
+  before_action :existing_cluster, only: [:new]
   before_action :authorize_create_cluster!, only: [:new]
   before_action :authorize_update_cluster!, only: [:update]
   before_action :authorize_admin_cluster!, only: [:destroy]
@@ -14,9 +17,6 @@ class Projects::ClustersController < Projects::ApplicationController
   end
 
   def new
-    generate_gcp_authorize_url
-    tap_new_cluster
-    tap_existing_cluster
   end
 
   def status
@@ -67,22 +67,7 @@ class Projects::ClustersController < Projects::ApplicationController
     end
   end
 
-  def tap_new_cluster
-    if GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
-      .validate_token(expires_at_in_session)
-      @new_cluster = ::Clusters::Cluster.new.tap do |cluster|
-        cluster.build_provider_gcp
-      end
-    end
-  end
-
-  def tap_existing_cluster
-    @existing_cluster = ::Clusters::Cluster.new.tap do |cluster|
-      cluster.build_platform_kubernetes
-    end
-  end
-
-  def create_cluster
+  def create
     case params[:type]
     when 'new'
       cluster_params = create_new_cluster_params
@@ -120,19 +105,6 @@ class Projects::ClustersController < Projects::ApplicationController
                                  .present(current_user: current_user)
   end
 
-  def create_params
-    params.require(:cluster).permit(
-      :enabled,
-      :name,
-      :provider_type,
-      provider_gcp_attributes: [
-        :gcp_project_id,
-        :zone,
-        :num_nodes,
-        :machine_type
-      ])
-  end
-
   def update_params
     if cluster.managed?
       params.require(:cluster).permit(
@@ -199,6 +171,21 @@ class Projects::ClustersController < Projects::ApplicationController
     # no-op
   end
 
+  def new_cluster
+    if GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
+      .validate_token(expires_at_in_session)
+      @new_cluster = ::Clusters::Cluster.new.tap do |cluster|
+        cluster.build_provider_gcp
+      end
+    end
+  end
+
+  def existing_cluster
+    @existing_cluster = ::Clusters::Cluster.new.tap do |cluster|
+      cluster.build_platform_kubernetes
+    end
+  end
+
   def token_in_session
     @token_in_session ||=
       session[GoogleApi::CloudPlatform::Client.session_key_for_token]
diff --git a/config/routes/project.rb b/config/routes/project.rb
index 4584c8d74a8..6609f093b20 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -206,7 +206,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
 
       resources :clusters, except: [:edit, :create] do
         collection do
-          post '/new', to: 'clusters#create_cluster'
+          post '/new', to: 'clusters#create'
         end
 
         member do
-- 
2.30.9