diff options
Diffstat (limited to 'app/models/service.rb')
-rw-r--r-- | app/models/service.rb | 9 |
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 |