2020-09-01 08:11:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class JiraConnectInstallation < ApplicationRecord
|
|
|
|
attr_encrypted :shared_secret,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
|
|
|
|
|
|
|
has_many :subscriptions, class_name: 'JiraConnectSubscription'
|
|
|
|
|
|
|
|
validates :client_key, presence: true, uniqueness: true
|
|
|
|
validates :shared_secret, presence: true
|
|
|
|
validates :base_url, presence: true, public_url: true
|
2021-07-29 11:09:48 -04:00
|
|
|
validates :instance_url, public_url: true, allow_blank: true
|
2020-09-01 08:11:01 -04:00
|
|
|
|
|
|
|
scope :for_project, -> (project) {
|
|
|
|
distinct
|
|
|
|
.joins(:subscriptions)
|
|
|
|
.where(jira_connect_subscriptions: {
|
|
|
|
id: JiraConnectSubscription.for_project(project)
|
|
|
|
})
|
|
|
|
}
|
2021-08-31 17:10:43 -04:00
|
|
|
|
|
|
|
def client
|
|
|
|
Atlassian::JiraConnect::Client.new(base_url, shared_secret)
|
|
|
|
end
|
2020-09-01 08:11:01 -04:00
|
|
|
end
|