2021-01-05 07:10:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module JiraConnectHelper
|
2022-09-12 08:12:09 -04:00
|
|
|
def jira_connect_app_data(subscriptions)
|
2021-01-25 13:09:03 -05:00
|
|
|
skip_groups = subscriptions.map(&:namespace_id)
|
|
|
|
|
2021-01-18 10:10:42 -05:00
|
|
|
{
|
2021-01-25 13:09:03 -05:00
|
|
|
groups_path: api_v4_groups_path(params: { min_access_level: Gitlab::Access::MAINTAINER, skip_groups: skip_groups }),
|
2021-04-14 11:09:04 -04:00
|
|
|
subscriptions: subscriptions.map { |s| serialize_subscription(s) }.to_json,
|
2022-05-04 14:08:35 -04:00
|
|
|
add_subscriptions_path: jira_connect_subscriptions_path,
|
|
|
|
subscriptions_path: jira_connect_subscriptions_path(format: :json),
|
2021-12-02 04:10:59 -05:00
|
|
|
users_path: current_user ? nil : jira_connect_users_path, # users_path is used to determine if user is signed in
|
2022-03-10 22:08:14 -05:00
|
|
|
gitlab_user_path: current_user ? user_path(current_user) : nil,
|
2022-09-12 08:12:09 -04:00
|
|
|
oauth_metadata: Feature.enabled?(:jira_connect_oauth, current_user) ? jira_connect_oauth_data.to_json : nil
|
2021-01-18 10:10:42 -05:00
|
|
|
}
|
|
|
|
end
|
2021-04-14 11:09:04 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-09-12 08:12:09 -04:00
|
|
|
def jira_connect_oauth_data
|
|
|
|
oauth_authorize_url = oauth_authorization_url(
|
2022-05-30 14:08:57 -04:00
|
|
|
client_id: Gitlab::CurrentSettings.jira_connect_application_key,
|
2022-03-10 22:08:14 -05:00
|
|
|
response_type: 'code',
|
|
|
|
scope: 'api',
|
|
|
|
redirect_uri: jira_connect_oauth_callbacks_url,
|
|
|
|
state: oauth_state
|
|
|
|
)
|
|
|
|
|
|
|
|
{
|
2022-09-12 08:12:09 -04:00
|
|
|
oauth_authorize_url: oauth_authorize_url,
|
|
|
|
oauth_token_url: oauth_token_url,
|
2022-03-10 22:08:14 -05:00
|
|
|
state: oauth_state,
|
|
|
|
oauth_token_payload: {
|
|
|
|
grant_type: :authorization_code,
|
2022-05-30 14:08:57 -04:00
|
|
|
client_id: Gitlab::CurrentSettings.jira_connect_application_key,
|
2022-03-10 22:08:14 -05:00
|
|
|
redirect_uri: jira_connect_oauth_callbacks_url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def oauth_state
|
|
|
|
@oauth_state ||= SecureRandom.hex(32)
|
|
|
|
end
|
|
|
|
|
2021-04-14 11:09:04 -04:00
|
|
|
def serialize_subscription(subscription)
|
|
|
|
{
|
|
|
|
group: {
|
|
|
|
name: subscription.namespace.name,
|
|
|
|
avatar_url: subscription.namespace.avatar_url,
|
|
|
|
full_name: subscription.namespace.full_name,
|
|
|
|
description: subscription.namespace.description
|
|
|
|
},
|
|
|
|
created_at: subscription.created_at,
|
|
|
|
unlink_path: jira_connect_subscription_path(subscription)
|
|
|
|
}
|
|
|
|
end
|
2021-01-05 07:10:36 -05:00
|
|
|
end
|