-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(links): Insert
/f/<fileId>
format for links to files
Get rid of the old `/path/?fileId=<id>` format. It never really worked anyway because the paths were relative to the users' home directory. Instead, insert links to files/folders as full URLs with the `/f/<fileId>` format. This makes link previews work both in Text and Collectives. Rewrite links in the old format to the new format. But don't touch absolute link (without origin) to the collectives app to not break collectives-specific link handling to other pages. Signed-off-by: Jonas <[email protected]>
- Loading branch information
Showing
6 changed files
with
53 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { domHref, parseHref } from '../../helpers/links' | ||
import { loadState } from '@nextcloud/initial-state' | ||
|
||
global.OCA = { | ||
Viewer: { | ||
|
@@ -13,9 +12,6 @@ global.OC = { | |
|
||
global._oc_webroot = '' | ||
|
||
jest.mock('@nextcloud/initial-state') | ||
loadState.mockImplementation((app, key) => 'files') | ||
|
||
describe('Preparing href attributes for the DOM', () => { | ||
|
||
test('leave empty hrefs alone', () => { | ||
|
@@ -36,24 +32,24 @@ describe('Preparing href attributes for the DOM', () => { | |
.toBe('mailTo:[email protected]') | ||
}) | ||
|
||
test('relative link with fileid', () => { | ||
test('relative link with fileid (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: 'otherfile?fileId=123'}})) | ||
.toBe('/apps/files/?dir=/Wiki&openfile=123#relPath=otherfile') | ||
.toBe('/f/123') | ||
}) | ||
|
||
test('relative path with ../', () => { | ||
test('relative path with ../ (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '../other/otherfile?fileId=123'}})) | ||
.toBe('/apps/files/?dir=/other&openfile=123#relPath=../other/otherfile') | ||
.toBe('/f/123') | ||
}) | ||
|
||
test('absolute path', () => { | ||
test('absolute path (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '/other/otherfile?fileId=123'}})) | ||
.toBe('/apps/files/?dir=/other&openfile=123#relPath=/other/otherfile') | ||
.toBe('/f/123') | ||
}) | ||
|
||
test('absolute path', () => { | ||
test('absolute path (old format from file picker)', () => { | ||
expect(domHref({attrs: {href: '/otherfile?fileId=123'}})) | ||
.toBe('/apps/files/?dir=/&openfile=123#relPath=/otherfile') | ||
.toBe('/f/123') | ||
}) | ||
|
||
}) | ||
|
@@ -74,9 +70,9 @@ describe('Extracting short urls from the DOM', () => { | |
expect(parseHref(domStub())).toBe(undefined) | ||
}) | ||
|
||
test('relative link with fileid', () => { | ||
test('relative link with fileid (old format from file picker)', () => { | ||
expect(parseHref(domStub('?dir=/other&openfile=123#relPath=../other/otherfile'))) | ||
.toBe('../other/otherfile?fileId=123') | ||
.toBe('/f/123') | ||
}) | ||
|
||
}) | ||
|
@@ -101,20 +97,29 @@ describe('Inserting hrefs into the dom and extracting them again', () => { | |
expect(insertAndExtract({})).toBe(undefined) | ||
}) | ||
|
||
test('default relative link format is unchanged', () => { | ||
test('old relative link format (from file picker) is rewritten', () => { | ||
expect(insertAndExtract({href: 'otherfile?fileId=123'})) | ||
.toBe('otherfile?fileId=123') | ||
.toBe('/f/123') | ||
}) | ||
|
||
}) | ||
test('old relative link format with ../ (from file picker) is rewritten', () => { | ||
expect(insertAndExtract({href: '../otherfile?fileId=123'})) | ||
.toBe('/f/123') | ||
}) | ||
|
||
describe('Preparing href attributes for the DOM in Collectives app', () => { | ||
beforeAll(() => { | ||
loadState.mockImplementation((app, key) => 'collectives') | ||
test('old absolute link format (from file picker) is rewritten', () => { | ||
expect(insertAndExtract({href: '/otherfile?fileId=123'})) | ||
.toBe('/f/123') | ||
}) | ||
|
||
test('relative link with fileid in Collectives', () => { | ||
expect(domHref({attrs: {href: 'otherfile?fileId=123'}})) | ||
.toBe('otherfile?fileId=123') | ||
test('default absolute link format is unchanged', () => { | ||
expect(insertAndExtract({href: '/f/123'})) | ||
.toBe('/f/123') | ||
}) | ||
|
||
test('absolute link to collectives page is unchanged', () => { | ||
expect(insertAndExtract({href: '/apps/collectives/page?fileId=123'})) | ||
.toBe('/apps/collectives/page?fileId=123') | ||
}) | ||
|
||
}) |