summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-10-01 20:30:32 +0900
committerShinya Maeda <shinya@gitlab.com>2017-10-01 20:30:32 +0900
commit5663b4808df787b1bcbf32ba54eccbb4c7537e25 (patch)
treedb851b0b94ee77d493dc787f67fe63136dab4fef /app/models
parent2d1a77b8a3567cae61f73196918fe365d4fe9415 (diff)
downloadgitlab-ce-5663b4808df787b1bcbf32ba54eccbb4c7537e25.tar.gz
authorize in controller. validation in model.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/cluster.rb35
1 files changed, 33 insertions, 2 deletions
diff --git a/app/models/ci/cluster.rb b/app/models/ci/cluster.rb
index 594739075e4..93f582f565a 100644
--- a/app/models/ci/cluster.rb
+++ b/app/models/ci/cluster.rb
@@ -32,8 +32,26 @@ module Ci
errored: 4
}
- def error!(reason)
- update!(status: statuses[:errored], status_reason: reason, gcp_token: nil)
+ validates :gcp_project_id, presence: true
+ validates :cluster_zone, presence: true
+ validates :cluster_name, presence: true
+ validates :cluster_size, presence: true,
+ numericality: { only_integer: true, greater_than: 0 }
+ validate :restrict_modification, on: :update
+
+ def errored!(reason)
+ self.status = :errored
+ self.status_reason = reason
+ self.gcp_token = nil
+
+ save!(validate: false)
+ end
+
+ def creating!(gcp_operation_id)
+ self.status = :creating
+ self.gcp_operation_id = gcp_operation_id
+
+ save!(validate: false)
end
def on_creation?
@@ -43,5 +61,18 @@ module Ci
def api_url
'https://' + endpoint
end
+
+ def restrict_modification
+ if on_creation?
+ errors.add(:base, "cannot modify during creation")
+ return false
+ end
+
+ true
+ end
+
+ def destroy
+ super if restrict_modification
+ end
end
end