summaryrefslogtreecommitdiff
path: root/app/models/service.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 12:09:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-11 12:09:26 +0000
commitc9687bdf58e9d4a9c3942f587bd4841f42e3b5de (patch)
treea60a2e20f152483be6a92bacdf10564bbc96c664 /app/models/service.rb
parent3f3e4bcc50a3280d03299c2c263eafd9c8e3bd7b (diff)
downloadgitlab-ce-c9687bdf58e9d4a9c3942f587bd4841f42e3b5de.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/service.rb')
-rw-r--r--app/models/service.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/service.rb b/app/models/service.rb
index 91597c51fca..8f1772e67f9 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -32,9 +32,12 @@ class Service < ApplicationRecord
belongs_to :project, inverse_of: :services
has_one :service_hook
- validates :project_id, presence: true, unless: -> { template? }
+ validates :project_id, presence: true, unless: -> { template? || instance? }
+ validates :project_id, absence: true, if: -> { instance? }
validates :type, presence: true
validates :template, uniqueness: { scope: :type }, if: -> { template? }
+ validates :instance, uniqueness: { scope: :type }, if: -> { instance? }
+ validate :validate_is_instance_or_template
scope :visible, -> { where.not(type: 'GitlabIssueTrackerService') }
scope :issue_trackers, -> { where(category: 'issue_tracker') }
@@ -326,6 +329,10 @@ class Service < ApplicationRecord
private
+ def validate_is_instance_or_template
+ errors.add(:template, 'The service should be a service template or instance-level integration') if template? && instance?
+ end
+
def cache_project_has_external_issue_tracker
if project && !project.destroyed?
project.cache_has_external_issue_tracker