Commit 98d2d23d authored by Matija Čupić's avatar Matija Čupić

Extract EE specific Cluster code into an EE concern

parent f850b1bd
module Clusters module Clusters
class Cluster < ActiveRecord::Base class Cluster < ActiveRecord::Base
prepend EE::Clusters::Cluster
include Presentable include Presentable
prepend HasEnvironmentScope
self.table_name = 'clusters' self.table_name = 'clusters'
...@@ -32,7 +33,6 @@ module Clusters ...@@ -32,7 +33,6 @@ module Clusters
accepts_nested_attributes_for :platform_kubernetes, update_only: true accepts_nested_attributes_for :platform_kubernetes, update_only: true
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
...@@ -105,15 +105,6 @@ module Clusters ...@@ -105,15 +105,6 @@ module Clusters
private private
def unique_environment_scope
if project && project.clusters.where(environment_scope: environment_scope).where.not(id: self.id).exists?
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")
......
module EE
module Clusters
module Cluster
extend ActiveSupport::Concern
prepended do
prepend HasEnvironmentScope
validate :unique_environment_scope
end
def unique_environment_scope
if project && project.clusters.where(environment_scope: environment_scope).where.not(id: self.id).exists?
errors.add(:base, "cannot add duplicated environment scope")
return false
end
true
end
end
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