Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/integration.rb')
-rw-r--r--app/models/integration.rb41
1 files changed, 19 insertions, 22 deletions
diff --git a/app/models/integration.rb b/app/models/integration.rb
index d4c76f743a3..b4408301c6d 100644
--- a/app/models/integration.rb
+++ b/app/models/integration.rb
@@ -47,6 +47,9 @@ class Integration < ApplicationRecord
Integrations::BaseThirdPartyWiki
].freeze
+ BASE_ATTRIBUTES = %w[id instance project_id group_id created_at updated_at
+ encrypted_properties encrypted_properties_iv properties].freeze
+
SECTION_TYPE_CONFIGURATION = 'configuration'
SECTION_TYPE_CONNECTION = 'connection'
SECTION_TYPE_TRIGGER = 'trigger'
@@ -111,18 +114,18 @@ class Integration < ApplicationRecord
validate :validate_belongs_to_project_or_group
scope :external_issue_trackers, -> { where(category: 'issue_tracker').active }
- # TODO: Will be modified in 15.0
- # Details: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74501#note_744393645
- scope :third_party_wikis, -> { where(type: %w[Integrations::Confluence Integrations::Shimo]).active }
+ scope :third_party_wikis, -> { where(category: 'third_party_wiki').active }
scope :by_name, ->(name) { by_type(integration_name_to_type(name)) }
scope :external_wikis, -> { by_name(:external_wiki).active }
scope :active, -> { where(active: true) }
scope :by_type, ->(type) { where(type: type) } # INTERNAL USE ONLY: use by_name instead
- scope :by_active_flag, -> (flag) { where(active: flag) }
- scope :inherit_from_id, -> (id) { where(inherit_from_id: id) }
+ scope :by_active_flag, ->(flag) { where(active: flag) }
+ scope :inherit_from_id, ->(id) { where(inherit_from_id: id) }
scope :with_default_settings, -> { where.not(inherit_from_id: nil) }
scope :with_custom_settings, -> { where(inherit_from_id: nil) }
- scope :for_group, -> (group) { where(group_id: group, type: available_integration_types(include_project_specific: false)) }
+ scope :for_group, ->(group) {
+ where(group_id: group, type: available_integration_types(include_project_specific: false))
+ }
scope :for_instance, -> { where(instance: true, type: available_integration_types(include_project_specific: false)) }
scope :push_hooks, -> { where(push_events: true, active: true) }
@@ -216,13 +219,6 @@ class Integration < ApplicationRecord
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
def self.boolean_accessor(*args)
args.each do |arg|
- # TODO: Allow legacy usage of `.boolean_accessor`, once all integrations
- # are converted to the field DSL we can remove this and only call
- # `.boolean_accessor` through `.field`.
- #
- # See https://gitlab.com/groups/gitlab-org/-/epics/7652
- prop_accessor(arg) unless method_defined?(arg)
-
class_eval <<~RUBY, __FILE__, __LINE__ + 1
# Make the original getter available as a private method.
alias_method :#{arg}_before_type_cast, :#{arg}
@@ -239,13 +235,14 @@ class Integration < ApplicationRecord
RUBY
end
end
+ private_class_method :boolean_accessor
def self.to_param
raise NotImplementedError
end
def self.event_names
- self.supported_events.map { |event| IntegrationsHelper.integration_event_field_name(event) }
+ supported_events.map { |event| IntegrationsHelper.integration_event_field_name(event) }
end
def self.supported_events
@@ -406,7 +403,7 @@ class Integration < ApplicationRecord
from_union([active.where(instance: true), active.where(group_id: group_ids, inherit_from_id: nil)])
.order(order)
.group_by(&:type)
- .count { |type, parents| build_from_integration(parents.first, association => owner.id).save }
+ .count { |_type, parents| build_from_integration(parents.first, association => owner.id).save }
end
def self.inherited_descendants_from_self_or_ancestors_from(integration)
@@ -415,9 +412,10 @@ class Integration < ApplicationRecord
.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))
- ])
+ 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?
@@ -490,10 +488,9 @@ class Integration < ApplicationRecord
def to_database_hash
column = self.class.attribute_aliases.fetch('type', 'type')
- as_json(
- except: %w[id instance project_id group_id created_at updated_at]
- ).merge(column => type)
- .merge(reencrypt_properties)
+ attributes_for_database.except(*BASE_ATTRIBUTES)
+ .merge(column => type)
+ .merge(reencrypt_properties)
end
def reencrypt_properties