diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/models/service.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/models/service.rb')
-rw-r--r-- | app/models/service.rb | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/app/models/service.rb b/app/models/service.rb index 764f417362f..2b6971954e3 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -8,6 +8,7 @@ class Service < ApplicationRecord include ProjectServicesLoggable include DataFields include FromUnion + include EachBatch SERVICE_NAMES = %w[ alerts asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker discord @@ -16,6 +17,7 @@ class Service < ApplicationRecord pivotaltracker prometheus pushover redmine slack slack_slash_commands teamcity unify_circuit webex_teams youtrack ].freeze + # Fake services to help with local development. DEV_SERVICE_NAMES = %w[ mock_ci mock_deployment mock_monitoring ].freeze @@ -64,9 +66,9 @@ class Service < ApplicationRecord scope :by_type, -> (type) { where(type: type) } scope :by_active_flag, -> (flag) { where(active: flag) } scope :inherit_from_id, -> (id) { where(inherit_from_id: id) } - scope :for_group, -> (group) { where(group_id: group, type: available_services_types) } - scope :for_template, -> { where(template: true, type: available_services_types) } - scope :for_instance, -> { where(instance: true, type: available_services_types) } + scope :for_group, -> (group) { where(group_id: group, type: available_services_types(include_project_specific: false)) } + scope :for_template, -> { where(template: true, type: available_services_types(include_project_specific: false)) } + scope :for_instance, -> { where(instance: true, type: available_services_types(include_project_specific: false)) } scope :push_hooks, -> { where(push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } @@ -167,13 +169,13 @@ class Service < ApplicationRecord end private_class_method :create_nonexistent_templates - def self.find_or_initialize_integration(name, instance: false, group_id: nil) - if name.in?(available_services_names) + def self.find_or_initialize_non_project_specific_integration(name, instance: false, group_id: nil) + if name.in?(available_services_names(include_project_specific: false)) "#{name}_service".camelize.constantize.find_or_initialize_by(instance: instance, group_id: group_id) end end - def self.find_or_initialize_all(scope) + def self.find_or_initialize_all_non_project_specific(scope) scope + build_nonexistent_services_for(scope) end @@ -187,13 +189,14 @@ class Service < ApplicationRecord def self.list_nonexistent_services_for(scope) # Using #map instead of #pluck to save one query count. This is because # ActiveRecord loaded the object here, so we don't need to query again later. - available_services_types - scope.map(&:type) + available_services_types(include_project_specific: false) - scope.map(&:type) end private_class_method :list_nonexistent_services_for - def self.available_services_names + def self.available_services_names(include_project_specific: true, include_dev: true) service_names = services_names - service_names += dev_services_names + service_names += project_specific_services_names if include_project_specific + service_names += dev_services_names if include_dev service_names.sort_by(&:downcase) end @@ -212,12 +215,10 @@ class Service < ApplicationRecord [] end - def self.available_services_types - available_services_names.map { |service_name| "#{service_name}_service".camelize } - end - - def self.services_types - services_names.map { |service_name| "#{service_name}_service".camelize } + def self.available_services_types(include_project_specific: true, include_dev: true) + available_services_names(include_project_specific: include_project_specific, include_dev: include_dev).map do |service_name| + "#{service_name}_service".camelize + end end def self.build_from_integration(integration, project_id: nil, group_id: nil) @@ -273,6 +274,17 @@ class Service < ApplicationRecord end end + def self.inherited_descendants_from_self_or_ancestors_from(integration) + inherit_from_ids = + where(type: integration.type, group: integration.group.self_and_ancestors) + .or(where(type: integration.type, instance: true)).select(:id) + + from_union([ + where(type: integration.type, inherit_from_id: inherit_from_ids, group: integration.group.descendants), + where(type: integration.type, inherit_from_id: inherit_from_ids, project: Project.in_namespace(integration.group.self_and_descendants)) + ]) + end + def activated? active end @@ -294,7 +306,7 @@ class Service < ApplicationRecord end def initialize_properties - self.properties = {} if properties.nil? + self.properties = {} if has_attribute?(:properties) && properties.nil? end def title @@ -410,8 +422,12 @@ class Service < ApplicationRecord ProjectServiceWorker.perform_async(id, data) end - def issue_tracker? - self.category == :issue_tracker + def external_issue_tracker? + category == :issue_tracker && active? + end + + def external_wiki? + type == 'ExternalWikiService' && active? end # override if needed |