Commit f8af7854 authored by Arturo Herrero's avatar Arturo Herrero

Validate service belongs to project or group

parent 81fa9f67
......@@ -57,6 +57,7 @@ class Service < ApplicationRecord
validates :template, uniqueness: { scope: :type }, if: -> { template? }
validates :instance, uniqueness: { scope: :type }, if: -> { instance? }
validate :validate_is_instance_or_template
validate :validate_belongs_to_project_or_group
scope :external_issue_trackers, -> { where(category: 'issue_tracker').active }
scope :external_wikis, -> { where(type: 'ExternalWikiService').active }
......@@ -379,6 +380,10 @@ class Service < ApplicationRecord
errors.add(:template, 'The service should be a service template or instance-level integration') if template? && instance?
end
def validate_belongs_to_project_or_group
errors.add(:project_id, 'The service should belongs to a project or group') if project_id && group_id
end
def cache_project_has_external_issue_tracker
if project && !project.destroyed?
project.cache_has_external_issue_tracker
......
......@@ -25,6 +25,7 @@ RSpec.describe Service do
nil | nil | false | true | true
nil | nil | false | false | false
nil | nil | true | true | false
1 | 1 | false | false | false
1 | nil | true | false | false
1 | nil | false | true | false
nil | 1 | true | false | false
......
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