Commit d46e1f00 authored by Tom Quirk's avatar Tom Quirk

Get current GitLab user path from backend

In the Jira Connect App, instead of building the
GitLab user link on the frontend, we use the
backend path helper to build it and pass
it to the frontend via the data attribute.
parent dcb61727
......@@ -12,6 +12,9 @@ export default {
usersPath: {
default: '',
},
gitlabUserPath: {
default: '',
},
},
props: {
userSignedIn: {
......@@ -32,9 +35,6 @@ export default {
gitlabUserHandle() {
return `@${gon.current_username}`;
},
gitlabUserLink() {
return `${gon.gitlab_url}/${gon.current_username}`;
},
},
async created() {
this.signInURL = await getGitlabSignInURL(this.usersPath);
......@@ -49,7 +49,7 @@ export default {
<div class="jira-connect-user gl-font-base">
<gl-sprintf v-if="userSignedIn" :message="$options.i18n.signedInAsUserText">
<template #user_link>
<gl-link data-testid="gitlab-user-link" :href="gitlabUserLink" target="_blank">
<gl-link data-testid="gitlab-user-link" :href="gitlabUserPath" target="_blank">
{{ gitlabUserHandle }}
</gl-link>
</template>
......
......@@ -21,7 +21,7 @@ export function initJiraConnect() {
Vue.use(Translate);
Vue.use(GlFeatureFlagsPlugin);
const { groupsPath, subscriptions, subscriptionsPath, usersPath } = el.dataset;
const { groupsPath, subscriptions, subscriptionsPath, usersPath, gitlabUserPath } = el.dataset;
sizeToParent();
return new Vue({
......@@ -32,6 +32,7 @@ export function initJiraConnect() {
subscriptions: JSON.parse(subscriptions),
subscriptionsPath,
usersPath,
gitlabUserPath,
},
render(createElement) {
return createElement(JiraConnectApp);
......
......@@ -8,7 +8,8 @@ module JiraConnectHelper
groups_path: api_v4_groups_path(params: { min_access_level: Gitlab::Access::MAINTAINER, skip_groups: skip_groups }),
subscriptions: subscriptions.map { |s| serialize_subscription(s) }.to_json,
subscriptions_path: jira_connect_subscriptions_path,
users_path: current_user ? nil : jira_connect_users_path
users_path: current_user ? nil : jira_connect_users_path, # users_path is used to determine if user is signed in
gitlab_user_path: current_user ? user_path(current_user) : nil
}
end
......
......@@ -68,17 +68,20 @@ describe('SubscriptionsList', () => {
});
describe('gitlab user link', () => {
beforeEach(() => {
window.gon = { current_username: 'root', gitlab_url: 'https://gitlab.com' };
window.gon = { current_username: 'root' };
createComponent({
userSignedIn: true,
hasSubscriptions: true,
});
beforeEach(() => {
createComponent(
{
userSignedIn: true,
hasSubscriptions: true,
},
{ provide: { gitlabUserPath: '/root' } },
);
});
it('renders with correct href', () => {
expect(findGitlabUserLink().attributes('href')).toBe('https://gitlab.com/root');
expect(findGitlabUserLink().attributes('href')).toBe('/root');
});
it('contains GitLab user handle', () => {
......
......@@ -19,7 +19,9 @@ RSpec.describe JiraConnectHelper do
is_expected.to include(
:groups_path,
:subscriptions_path,
:users_path
:users_path,
:subscriptions,
:gitlab_user_path
)
end
......@@ -32,6 +34,10 @@ RSpec.describe JiraConnectHelper do
expect(subject[:groups_path]).to include("#{skip_groups_param}=#{subscription.namespace.id}")
end
it 'assigns gitlab_user_path to nil' do
expect(subject[:gitlab_user_path]).to be_nil
end
end
context 'user is logged in' do
......@@ -42,6 +48,10 @@ RSpec.describe JiraConnectHelper do
it 'assigns users_path to nil' do
expect(subject[:users_path]).to be_nil
end
it 'assigns gitlab_user_path correctly' do
expect(subject[:gitlab_user_path]).to eq(user_path(user))
end
end
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