Commit 54badfc5 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch 'ld-use-new-level-methods-in-integrations' into 'master'

Use new `level?` methods for `Service`

See merge request gitlab-org/gitlab!60074
parents ea5011af d99a3857
...@@ -153,9 +153,9 @@ module ServicesHelper ...@@ -153,9 +153,9 @@ module ServicesHelper
private private
def integration_level(integration) def integration_level(integration)
if integration.instance if integration.instance_level?
'instance' 'instance'
elsif integration.group_id elsif integration.group_level?
'group' 'group'
else else
'project' 'project'
......
...@@ -51,14 +51,14 @@ class Service < ApplicationRecord ...@@ -51,14 +51,14 @@ class Service < ApplicationRecord
belongs_to :group, inverse_of: :services belongs_to :group, inverse_of: :services
has_one :service_hook has_one :service_hook
validates :project_id, presence: true, unless: -> { template? || instance? || group_id } validates :project_id, presence: true, unless: -> { template? || instance_level? || group_level? }
validates :group_id, presence: true, unless: -> { template? || instance? || project_id } validates :group_id, presence: true, unless: -> { template? || instance_level? || project_level? }
validates :project_id, :group_id, absence: true, if: -> { template? || instance? } validates :project_id, :group_id, absence: true, if: -> { template? || instance_level? }
validates :type, presence: true validates :type, presence: true
validates :type, uniqueness: { scope: :template }, if: :template? validates :type, uniqueness: { scope: :template }, if: :template?
validates :type, uniqueness: { scope: :instance }, if: :instance? validates :type, uniqueness: { scope: :instance }, if: :instance_level?
validates :type, uniqueness: { scope: :project_id }, if: :project_id? validates :type, uniqueness: { scope: :project_id }, if: :project_level?
validates :type, uniqueness: { scope: :group_id }, if: :group_id? validates :type, uniqueness: { scope: :group_id }, if: :group_level?
validate :validate_is_instance_or_template validate :validate_is_instance_or_template
validate :validate_belongs_to_project_or_group validate :validate_belongs_to_project_or_group
...@@ -240,7 +240,7 @@ class Service < ApplicationRecord ...@@ -240,7 +240,7 @@ class Service < ApplicationRecord
service.instance = false service.instance = false
service.project_id = project_id service.project_id = project_id
service.group_id = group_id service.group_id = group_id
service.inherit_from_id = integration.id if integration.instance? || integration.group service.inherit_from_id = integration.id if integration.instance_level? || integration.group_level?
service service
end end
...@@ -409,7 +409,7 @@ class Service < ApplicationRecord ...@@ -409,7 +409,7 @@ class Service < ApplicationRecord
# Disable test for instance-level and group-level services. # Disable test for instance-level and group-level services.
# https://gitlab.com/gitlab-org/gitlab/-/issues/213138 # https://gitlab.com/gitlab-org/gitlab/-/issues/213138
def can_test? def can_test?
!instance? && !group_id !(instance_level? || group_level?)
end end
def project_level? def project_level?
...@@ -460,11 +460,11 @@ class Service < ApplicationRecord ...@@ -460,11 +460,11 @@ class Service < ApplicationRecord
private private
def validate_is_instance_or_template def validate_is_instance_or_template
errors.add(:template, 'The service should be a service template or instance-level integration') if template? && instance? errors.add(:template, 'The service should be a service template or instance-level integration') if template? && instance_level?
end end
def validate_belongs_to_project_or_group def validate_belongs_to_project_or_group
errors.add(:project_id, 'The service cannot belong to both a project and a group') if project_id && group_id errors.add(:project_id, 'The service cannot belong to both a project and a group') if project_level? && group_level?
end end
def validate_recipients? def validate_recipients?
......
...@@ -5,7 +5,7 @@ module Admin ...@@ -5,7 +5,7 @@ module Admin
include PropagateService include PropagateService
def propagate def propagate
if integration.instance? if integration.instance_level?
update_inherited_integrations update_inherited_integrations
create_integration_for_groups_without_integration create_integration_for_groups_without_integration
create_integration_for_projects_without_integration create_integration_for_projects_without_integration
......
...@@ -11,7 +11,7 @@ class PropagateIntegrationGroupWorker ...@@ -11,7 +11,7 @@ class PropagateIntegrationGroupWorker
integration = Service.find_by_id(integration_id) integration = Service.find_by_id(integration_id)
return unless integration return unless integration
batch = if integration.instance? batch = if integration.instance_level?
Group.where(id: min_id..max_id).without_integration(integration) Group.where(id: min_id..max_id).without_integration(integration)
else else
integration.group.descendants.where(id: min_id..max_id).without_integration(integration) integration.group.descendants.where(id: min_id..max_id).without_integration(integration)
......
...@@ -12,7 +12,7 @@ class PropagateIntegrationProjectWorker ...@@ -12,7 +12,7 @@ class PropagateIntegrationProjectWorker
return unless integration return unless integration
batch = Project.where(id: min_id..max_id).without_integration(integration) batch = Project.where(id: min_id..max_id).without_integration(integration)
batch = batch.in_namespace(integration.group.self_and_descendants) if integration.group_id batch = batch.in_namespace(integration.group.self_and_descendants) if integration.group_level?
return if batch.empty? return if batch.empty?
......
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