Commit 9a4cab44 authored by Shinya Maeda's avatar Shinya Maeda

Fix unique validation in app/models/clusters/cluster.rb

parent 0ab64ac7
...@@ -26,8 +26,8 @@ module Clusters ...@@ -26,8 +26,8 @@ module Clusters
accepts_nested_attributes_for :provider_gcp, update_only: true accepts_nested_attributes_for :provider_gcp, update_only: true
accepts_nested_attributes_for :platform_kubernetes, update_only: true accepts_nested_attributes_for :platform_kubernetes, update_only: true
validates :environment_scope, uniqueness: { scope: :project_id }
validates :name, cluster_name: true validates :name, cluster_name: true
validate :unique_environment_scope
validate :restrict_modification, on: :update validate :restrict_modification, on: :update
delegate :status, to: :provider, allow_nil: true delegate :status, to: :provider, allow_nil: true
...@@ -93,6 +93,15 @@ module Clusters ...@@ -93,6 +93,15 @@ module Clusters
private private
def unique_environment_scope
if project.clusters.where(environment_scope: environment_scope).any?
errors.add(:base, "cannot add duplicated environment scope")
return false
end
true
end
def restrict_modification def restrict_modification
if provider&.on_creation? if provider&.on_creation?
errors.add(:base, "cannot modify during creation") errors.add(:base, "cannot modify during creation")
......
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