diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-10 14:35:52 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-10 14:35:52 +0100 |
commit | b44583e9c6a00c689be398fee54b24a6dab019a6 (patch) | |
tree | ebea46677f2d425cb7c6534a459273659853f527 /app | |
parent | be623ef3c1a867d23e9625fe372c17fcad3c47ce (diff) | |
download | gitlab-ce-b44583e9c6a00c689be398fee54b24a6dab019a6.tar.gz |
Extract GCP billing check as method
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/clusters/gcp_controller.rb | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/app/controllers/projects/clusters/gcp_controller.rb b/app/controllers/projects/clusters/gcp_controller.rb index 25608df0b9c..659bf8d8f82 100644 --- a/app/controllers/projects/clusters/gcp_controller.rb +++ b/app/controllers/projects/clusters/gcp_controller.rb @@ -3,6 +3,7 @@ class Projects::Clusters::GcpController < Projects::ApplicationController before_action :authorize_google_api, except: [:login] before_action :authorize_google_project_billing, only: [:new] before_action :authorize_create_cluster!, only: [:new, :create] + before_action :verify_billing, only: [:create] def login begin @@ -23,24 +24,34 @@ class Projects::Clusters::GcpController < Projects::ApplicationController end def create + @cluster = ::Clusters::CreateService + .new(project, current_user, create_params) + .execute(token_in_session) + + if @cluster.persisted? + redirect_to project_cluster_path(project, @cluster) + else + render :new + end + end + + private + + def verify_billing case google_project_billing_status when 'true' - @cluster = ::Clusters::CreateService - .new(project, current_user, create_params) - .execute(token_in_session) - - return redirect_to project_cluster_path(project, @cluster) if @cluster.persisted? + return when 'false' - flash[:error] = _('Please enable billing for one of your projects to be able to create a cluster.') + flash[:alert] = _('Please enable billing for one of your projects to be able to create a cluster.') else - flash[:error] = _('We could not verify that one of your projects on GCP has billing enabled. Please try again.') + flash[:alert] = _('We could not verify that one of your projects on GCP has billing enabled. Please try again.') end + @cluster = ::Clusters::Cluster.new(create_params) + render :new end - private - def create_params params.require(:cluster).permit( :enabled, |