debian-mirror-gitlab/app/helpers/jira_connect_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.1 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
module JiraConnectHelper
2022-10-11 01:57:18 +05:30
def jira_connect_app_data(subscriptions, installation)
2021-03-11 19:13:27 +05:30
skip_groups = subscriptions.map(&:namespace_id)
2021-03-08 18:12:59 +05:30
{
2021-03-11 19:13:27 +05:30
groups_path: api_v4_groups_path(params: { min_access_level: Gitlab::Access::MAINTAINER, skip_groups: skip_groups }),
2021-04-29 21:17:54 +05:30
subscriptions: subscriptions.map { |s| serialize_subscription(s) }.to_json,
2022-07-16 23:28:13 +05:30
add_subscriptions_path: jira_connect_subscriptions_path,
subscriptions_path: jira_connect_subscriptions_path(format: :json),
2022-01-26 12:08:38 +05:30
users_path: current_user ? nil : jira_connect_users_path, # users_path is used to determine if user is signed in
2022-05-07 20:08:51 +05:30
gitlab_user_path: current_user ? user_path(current_user) : nil,
2023-04-23 21:23:45 +05:30
oauth_metadata: Feature.enabled?(:jira_connect_oauth, current_user) ? jira_connect_oauth_data(installation).to_json : nil,
2023-05-27 22:25:52 +05:30
public_key_storage_enabled: Gitlab::CurrentSettings.jira_connect_public_key_storage_enabled?
2021-03-08 18:12:59 +05:30
}
end
2021-04-29 21:17:54 +05:30
private
2022-10-11 01:57:18 +05:30
def jira_connect_oauth_data(installation)
oauth_instance_url = installation.oauth_authorization_url
oauth_authorize_path = oauth_authorization_path(
2022-07-23 23:45:48 +05:30
client_id: Gitlab::CurrentSettings.jira_connect_application_key,
2022-05-07 20:08:51 +05:30
response_type: 'code',
scope: 'api',
redirect_uri: jira_connect_oauth_callbacks_url,
state: oauth_state
)
{
2022-10-11 01:57:18 +05:30
oauth_authorize_url: Gitlab::Utils.append_path(oauth_instance_url, oauth_authorize_path),
oauth_token_path: oauth_token_path,
2022-05-07 20:08:51 +05:30
state: oauth_state,
oauth_token_payload: {
grant_type: :authorization_code,
2022-07-23 23:45:48 +05:30
client_id: Gitlab::CurrentSettings.jira_connect_application_key,
2022-05-07 20:08:51 +05:30
redirect_uri: jira_connect_oauth_callbacks_url
}
}
end
def oauth_state
@oauth_state ||= SecureRandom.hex(32)
end
2021-04-29 21:17:54 +05:30
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-03-08 18:12:59 +05:30
end