Commit 842906d4 authored by Denys Mishunov's avatar Denys Mishunov Committed by Phil Hughes

Take relative_url_root into account

When building hardcoded URLs, we have to make sure we do not
leave out the relative_url_root as this breaks URLs on
 instances, served from a subfolder
parent 9e480ebb
...@@ -88,7 +88,9 @@ export default { ...@@ -88,7 +88,9 @@ export default {
}, },
cancelButtonHref() { cancelButtonHref() {
if (this.newSnippet) { if (this.newSnippet) {
return this.projectPath ? `/${this.projectPath}/-/snippets` : `/-/snippets`; return this.projectPath
? `${gon.relative_url_root}${this.projectPath}/-/snippets`
: `${gon.relative_url_root}-/snippets`;
} }
return this.snippet.webUrl; return this.snippet.webUrl;
}, },
......
...@@ -97,7 +97,7 @@ export default { ...@@ -97,7 +97,7 @@ export default {
text: __('New snippet'), text: __('New snippet'),
href: this.snippet.project href: this.snippet.project
? `${this.snippet.project.webUrl}/-/snippets/new` ? `${this.snippet.project.webUrl}/-/snippets/new`
: '/-/snippets/new', : `${gon.relative_url_root}-/snippets/new`,
variant: 'success', variant: 'success',
category: 'secondary', category: 'secondary',
cssClass: 'ml-2', cssClass: 'ml-2',
...@@ -137,7 +137,7 @@ export default { ...@@ -137,7 +137,7 @@ export default {
redirectToSnippets() { redirectToSnippets() {
window.location.pathname = this.snippet.project window.location.pathname = this.snippet.project
? `${this.snippet.project.fullPath}/-/snippets` ? `${this.snippet.project.fullPath}/-/snippets`
: 'dashboard/snippets'; : `${gon.relative_url_root}dashboard/snippets`;
}, },
closeDeleteModal() { closeDeleteModal() {
this.$refs.deleteModal.hide(); this.$refs.deleteModal.hide();
......
---
title: Take relative_url_path into account when building URLs in snippets
merge_request: 39960
author:
type: fixed
...@@ -47,6 +47,8 @@ const createTestSnippet = () => ({ ...@@ -47,6 +47,8 @@ const createTestSnippet = () => ({
describe('Snippet Edit app', () => { describe('Snippet Edit app', () => {
let wrapper; let wrapper;
const relativeUrlRoot = '/foo/';
const originalRelativeUrlRoot = gon.relative_url_root;
const mutationTypes = { const mutationTypes = {
RESOLVE: jest.fn().mockResolvedValue({ RESOLVE: jest.fn().mockResolvedValue({
...@@ -104,12 +106,14 @@ describe('Snippet Edit app', () => { ...@@ -104,12 +106,14 @@ describe('Snippet Edit app', () => {
} }
beforeEach(() => { beforeEach(() => {
gon.relative_url_root = relativeUrlRoot;
jest.spyOn(urlUtils, 'redirectTo').mockImplementation(); jest.spyOn(urlUtils, 'redirectTo').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
gon.relative_url_root = originalRelativeUrlRoot;
}); });
const findBlobActions = () => wrapper.find(SnippetBlobActionsEdit); const findBlobActions = () => wrapper.find(SnippetBlobActionsEdit);
...@@ -196,8 +200,8 @@ describe('Snippet Edit app', () => { ...@@ -196,8 +200,8 @@ describe('Snippet Edit app', () => {
it.each` it.each`
projectPath | snippetArg | expectation projectPath | snippetArg | expectation
${''} | ${[]} | ${'/-/snippets'} ${''} | ${[]} | ${`${relativeUrlRoot}-/snippets`}
${'project/path'} | ${[]} | ${'/project/path/-/snippets'} ${'project/path'} | ${[]} | ${`${relativeUrlRoot}project/path/-/snippets`}
${''} | ${[createTestSnippet()]} | ${TEST_WEB_URL} ${''} | ${[createTestSnippet()]} | ${TEST_WEB_URL}
${'project/path'} | ${[createTestSnippet()]} | ${TEST_WEB_URL} ${'project/path'} | ${[createTestSnippet()]} | ${TEST_WEB_URL}
`( `(
......
...@@ -14,6 +14,7 @@ describe('Snippet header component', () => { ...@@ -14,6 +14,7 @@ describe('Snippet header component', () => {
let errorMsg; let errorMsg;
let err; let err;
const originalRelativeUrlRoot = gon.relative_url_root;
function createComponent({ function createComponent({
loading = false, loading = false,
...@@ -50,6 +51,7 @@ describe('Snippet header component', () => { ...@@ -50,6 +51,7 @@ describe('Snippet header component', () => {
} }
beforeEach(() => { beforeEach(() => {
gon.relative_url_root = '/foo/';
snippet = { snippet = {
id: 'gid://gitlab/PersonalSnippet/50', id: 'gid://gitlab/PersonalSnippet/50',
title: 'The property of Thor', title: 'The property of Thor',
...@@ -86,6 +88,7 @@ describe('Snippet header component', () => { ...@@ -86,6 +88,7 @@ describe('Snippet header component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
gon.relative_url_root = originalRelativeUrlRoot;
}); });
it('renders itself', () => { it('renders itself', () => {
...@@ -213,7 +216,7 @@ describe('Snippet header component', () => { ...@@ -213,7 +216,7 @@ describe('Snippet header component', () => {
it('redirects to dashboard/snippets for personal snippet', () => { it('redirects to dashboard/snippets for personal snippet', () => {
return createDeleteSnippet().then(() => { return createDeleteSnippet().then(() => {
expect(wrapper.vm.closeDeleteModal).toHaveBeenCalled(); expect(wrapper.vm.closeDeleteModal).toHaveBeenCalled();
expect(window.location.pathname).toBe('dashboard/snippets'); expect(window.location.pathname).toBe(`${gon.relative_url_root}dashboard/snippets`);
}); });
}); });
......
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