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

base_data_fields.rb « integrations « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 11bdd3aae7b1bb5e6383305c249028dc72bc5e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module Integrations
  module BaseDataFields
    extend ActiveSupport::Concern

    LEGACY_FOREIGN_KEY_NAME = %w(
      Integrations::IssueTrackerData
      Integrations::JiraTrackerData
    ).freeze

    included do
      # TODO: Once we rename the tables we can't rely on `table_name` anymore.
      # https://gitlab.com/gitlab-org/gitlab/-/issues/331953
      belongs_to :integration, inverse_of: self.table_name.to_sym, foreign_key: foreign_key_name

      validates :integration, presence: true
    end

    class_methods do
      def encryption_options
        {
          key: Settings.attr_encrypted_db_key_base_32,
          encode: true,
          mode: :per_attribute_iv,
          algorithm: 'aes-256-gcm'
        }
      end

      private

      # Older data field models use the `service_id` foreign key for the
      # integration association.
      def foreign_key_name
        return :service_id if self.name.in?(LEGACY_FOREIGN_KEY_NAME)

        :integration_id
      end
    end

    def activated?
      !!integration&.activated?
    end

    def to_database_hash
      as_json(
        only: self.class.column_names
      ).except('id', 'service_id', 'integration_id', 'created_at', 'updated_at')
    end
  end
end