Commit 7eddfef4 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-invalid-active-service-template' into 'master'

Deactivate new KubernetesService created from active template to prevent project creation from failing

Closes gitlab-ee#6753

See merge request gitlab-org/gitlab-ce!20400
parents 633ac497 cf79a87e
...@@ -240,7 +240,7 @@ class KubernetesService < DeploymentService ...@@ -240,7 +240,7 @@ class KubernetesService < DeploymentService
end end
def deprecation_validation def deprecation_validation
return if active_changed?(from: true, to: false) return if active_changed?(from: true, to: false) || (new_record? && !active?)
if deprecated? if deprecated?
errors[:base] << deprecation_message errors[:base] << deprecation_message
......
...@@ -281,9 +281,9 @@ class Service < ActiveRecord::Base ...@@ -281,9 +281,9 @@ class Service < ActiveRecord::Base
def self.build_from_template(project_id, template) def self.build_from_template(project_id, template)
service = template.dup service = template.dup
service.active = false unless service.valid?
service.template = false service.template = false
service.project_id = project_id service.project_id = project_id
service.active = false if service.active? && !service.valid?
service service
end end
......
---
title: Deactivate new KubernetesService created from active template to prevent project creation from failing
merge_request:
author:
type: fixed
...@@ -78,7 +78,7 @@ describe Service do ...@@ -78,7 +78,7 @@ describe Service do
context 'when template is invalid' do context 'when template is invalid' do
it 'sets service template to inactive when template is invalid' do it 'sets service template to inactive when template is invalid' do
project = create(:project) project = create(:project)
template = JiraService.new(template: true, active: true) template = KubernetesService.new(template: true, active: true)
template.save(validate: false) template.save(validate: false)
service = described_class.build_from_template(project.id, template) service = described_class.build_from_template(project.id, template)
......
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