Commit 7af2161c authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix controllers and links

parent 1385d700
......@@ -2,8 +2,6 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
before_action :authorize_read_cluster!
before_action :authorize_google_api, except: [:login]
before_action :authorize_create_cluster!, only: [:new, :create]
before_action :authorize_update_cluster!, only: [:update]
before_action :authorize_admin_cluster!, only: [:destroy]
def login
begin
......@@ -52,6 +50,14 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
)
end
def update_params
params.require(:cluster).permit(
:enabled,
platform_kubernetes_attributes: [
:namespace
])
end
def authorize_google_api
unless GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
.validate_token(expires_at_in_session)
......
class Projects::ClustersController < Projects::ApplicationController
before_action :cluster, except: [:login, :index, :new]
before_action :cluster, except: [:index, :new]
before_action :authorize_read_cluster!
before_action :authorize_create_cluster!, only: [:new]
before_action :authorize_update_cluster!, only: [:update]
......@@ -13,6 +13,9 @@ class Projects::ClustersController < Projects::ApplicationController
end
end
def new
end
def status
respond_to do |format|
format.json do
......@@ -60,6 +63,7 @@ class Projects::ClustersController < Projects::ApplicationController
def update_params
params.require(:cluster).permit(
:enabled,
:name,
platform_kubernetes_attributes: [
:namespace,
:api_url,
......
......@@ -17,7 +17,7 @@ module Clusters
# we force autosave to happen when we save `Cluster` model
has_one :provider_gcp, class_name: 'Clusters::Providers::Gcp', autosave: true
has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes'
has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', autosave: true
has_one :application_helm, class_name: 'Clusters::Applications::Helm'
has_one :application_ingress, class_name: 'Clusters::Applications::Ingress'
......@@ -28,8 +28,6 @@ module Clusters
validates :name, cluster_name: true
validate :restrict_modification, on: :update
validates_associated :provider_gcp, :platform_kubernetes
delegate :status, to: :provider, allow_nil: true
delegate :status_reason, to: :provider, allow_nil: true
delegate :on_creation?, to: :provider, allow_nil: true
......@@ -95,6 +93,11 @@ module Clusters
return false
end
if managed? && name_changed?
errors.add(:base, "cannot modify cluster name")
return false
end
true
end
end
......
......@@ -7,6 +7,6 @@
= icon('chevron-down')
%ul.dropdown-menu.clusters-dropdown-menu.dropdown-menu-full-width
%li
= link_to(s_('ClusterIntegration|Create cluster on Google Container Engine'), new_namespace_project_gcp_path(@project.namespace, @project))
= link_to(s_('ClusterIntegration|Create cluster on Google Container Engine'), gcp_new_namespace_project_clusters_path(@project.namespace, @project))
%li
= link_to(s_('ClusterIntegration|Add an existing cluster'), new_namespace_project_user_path(@project.namespace, @project))
= link_to(s_('ClusterIntegration|Add an existing cluster'), user_new_namespace_project_clusters_path(@project.namespace, @project))
......@@ -3,7 +3,7 @@
- link_to_help_page = link_to(s_('ClusterIntegration|help page'), help_page_path('user/project/clusters/index'), target: '_blank', rel: 'noopener noreferrer')
= s_('ClusterIntegration|Read our %{link_to_help_page} on cluster integration.').html_safe % { link_to_help_page: link_to_help_page}
= form_for @cluster, html: { class: 'prepend-top-20' }, url: namespace_project_gcp_path(@project.namespace, @project), as: :cluster do |field|
= form_for @cluster, html: { class: 'prepend-top-20' }, url: gcp_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field|
= form_errors(@cluster)
.form-group
= field.label :name, s_('ClusterIntegration|Cluster name')
......
......@@ -69,7 +69,7 @@
- if @cluster.managed?
= render 'projects/clusters/gcp/show'
- else
= render 'projects/clusters/kubernetes/show'
= render 'projects/clusters/user/show'
%section.settings.no-animate#js-cluster-advanced-settings{ class: ('expanded' if expanded) }
.settings-header
......
= form_for @cluster, url: namespace_project_user_path(@project.namespace, @project), as: :cluster do |field|
= form_for @cluster, url: user_namespace_project_clusters_path(@project.namespace, @project), as: :cluster do |field|
= form_errors(@cluster)
.form-group
= field.label :name, s_('ClusterIntegration|Cluster name')
......
.form-group
%label.append-bottom-10{ for: 'cluster-name' }
= s_('ClusterIntegration|Cluster name')
%input.form-control.cluster-name{ value: @cluster.name }
= form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field|
= form_errors(@cluster)
.form-group
= field.label :name, s_('ClusterIntegration|Cluster name')
= field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Cluster name')
= field.fields_for :platform_kubernetes, @cluster.platform_kubernetes do |platform_kubernetes_field|
.form-group
= platform_kubernetes_field.label :api_url, s_('ClusterIntegration|API URL')
......
......@@ -186,10 +186,12 @@ constraints(ProjectUrlConstrainer.new) do
resources :clusters, except: [:edit, :create] do
collection do
scope :providers do
resource :user, only: [:new, :create], controller: 'clusters/user'
resource :gcp, only: [:new, :create], controller: 'clusters/gcp' do
get :login
end
get '/user/new', to: 'clusters/user#new'
post '/user', to: 'clusters/user#create'
get '/gcp/new', to: 'clusters/gcp#new'
get '/gcp/login', to: 'clusters/gcp#login'
post '/gcp', to: 'clusters/gcp#create'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment