Commit 22d211d0 authored by Jarka Košanová's avatar Jarka Košanová

Refactor data fields common functions to concern

- association, encryption
parent 4807a9b4
# frozen_string_literal: true
module Services
module DataFields
extend ActiveSupport::Concern
included do
belongs_to :service
delegate :activated?, to: :service, allow_nil: true
validates :service, 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
end
end
end
......@@ -44,6 +44,7 @@ module DataFields
included do
has_one :issue_tracker_data, autosave: true
has_one :jira_tracker_data, autosave: true
has_one :open_project_tracker_data, autosave: true
def data_fields
raise NotImplementedError
......
# frozen_string_literal: true
class IssueTrackerData < ApplicationRecord
belongs_to :service
delegate :activated?, to: :service, allow_nil: true
validates :service, presence: true
def self.encryption_options
{
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
include Services::DataFields
attr_encrypted :project_url, encryption_options
attr_encrypted :issues_url, encryption_options
......
# frozen_string_literal: true
class JiraTrackerData < ApplicationRecord
belongs_to :service
delegate :activated?, to: :service, allow_nil: true
validates :service, presence: true
def self.encryption_options
{
key: Settings.attr_encrypted_db_key_base_32,
encode: true,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
}
end
include Services::DataFields
attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options
......
# frozen_string_literal: true
class OpenProjectTrackerData < ApplicationRecord
# When the Open Project is fresh installed, the default closed status id is "13" based on current version: v8.
DEFAULT_CLOSED_STATUS_ID = "13"
include Services::DataFields
attr_encrypted :url, encryption_options
attr_encrypted :api_url, encryption_options
attr_encrypted :token, encryption_options
def closed_status_id
super || DEFAULT_CLOSED_STATUS_ID
end
end
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