2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class JiraConnectInstallation < ApplicationRecord
|
2023-06-09 08:11:10 +05:30
|
|
|
include Gitlab::Routing
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
attr_encrypted :shared_secret,
|
2022-08-27 11:52:29 +05:30
|
|
|
mode: :per_attribute_iv,
|
2020-11-24 15:15:51 +05:30
|
|
|
algorithm: 'aes-256-gcm',
|
2022-08-27 11:52:29 +05:30
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
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-10-27 15:23:28 +05:30
|
|
|
validates :instance_url, public_url: true, allow_blank: true
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
scope :for_project, -> (project) {
|
|
|
|
distinct
|
|
|
|
.joins(:subscriptions)
|
|
|
|
.where(jira_connect_subscriptions: {
|
|
|
|
id: JiraConnectSubscription.for_project(project)
|
|
|
|
})
|
|
|
|
}
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
scope :direct_installations, -> { joins(:subscriptions) }
|
|
|
|
scope :proxy_installations, -> { where.not(instance_url: nil) }
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
def client
|
|
|
|
Atlassian::JiraConnect::Client.new(base_url, shared_secret)
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
def oauth_authorization_url
|
2023-06-09 08:11:10 +05:30
|
|
|
return Gitlab.config.gitlab.url if instance_url.blank?
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
instance_url
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
def audience_url
|
|
|
|
return unless proxy?
|
|
|
|
|
2023-06-09 08:11:10 +05:30
|
|
|
Gitlab::Utils.append_path(instance_url, jira_connect_base_path)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def audience_installed_event_url
|
|
|
|
return unless proxy?
|
|
|
|
|
2023-06-09 08:11:10 +05:30
|
|
|
Gitlab::Utils.append_path(instance_url, jira_connect_events_installed_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def audience_uninstalled_event_url
|
|
|
|
return unless proxy?
|
|
|
|
|
|
|
|
Gitlab::Utils.append_path(instance_url, jira_connect_events_uninstalled_path)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def proxy?
|
|
|
|
instance_url.present?
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|