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