From accc87ea85e7240b26b43caf2a27deb97f8a06d2 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Tue, 12 Dec 2023 18:06:23 +0100 Subject: [PATCH] fix: resolving links without drive alias --- .../bugfix-resolve-link-without-drive-alias | 6 +++++ .../src/views/spaces/DriveResolver.vue | 12 ++++++++++ .../unit/views/spaces/DriveResolver.spec.ts | 22 ++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/bugfix-resolve-link-without-drive-alias diff --git a/changelog/unreleased/bugfix-resolve-link-without-drive-alias b/changelog/unreleased/bugfix-resolve-link-without-drive-alias new file mode 100644 index 00000000000..6afee44f332 --- /dev/null +++ b/changelog/unreleased/bugfix-resolve-link-without-drive-alias @@ -0,0 +1,6 @@ +Bugfix: Resolving links without drive alias + +Resolving links without a drive alias has been fixed in case a fileId is given via query param. + +https://github.com/owncloud/web/pull/10154 +https://github.com/owncloud/web/issues/9269 diff --git a/packages/web-app-files/src/views/spaces/DriveResolver.vue b/packages/web-app-files/src/views/spaces/DriveResolver.vue index b2a9f13f0ad..7b7304afab7 100644 --- a/packages/web-app-files/src/views/spaces/DriveResolver.vue +++ b/packages/web-app-files/src/views/spaces/DriveResolver.vue @@ -129,6 +129,18 @@ export default defineComponent({ } onMounted(async () => { + if (!unref(driveAliasAndItem) && unref(fileId)) { + return router.push({ + name: 'resolvePrivateLink', + params: { fileId: unref(fileId) }, + query: { + ...(configurationManager.options.openLinksWithDefaultApp && { + openWithDefaultApp: 'true' + }) + } + }) + } + const space = unref(resolvedDrive.space) if (space && isPublicSpaceResource(space)) { const isRunningOnEos = store.getters.configuration?.options?.runningOnEos diff --git a/packages/web-app-files/tests/unit/views/spaces/DriveResolver.spec.ts b/packages/web-app-files/tests/unit/views/spaces/DriveResolver.spec.ts index 3a2eb30aedf..602cfbd9a85 100644 --- a/packages/web-app-files/tests/unit/views/spaces/DriveResolver.spec.ts +++ b/packages/web-app-files/tests/unit/views/spaces/DriveResolver.spec.ts @@ -1,5 +1,5 @@ import DriveResolver from '../../../../src/views/spaces/DriveResolver.vue' -import { useDriveResolver } from '@ownclouders/web-pkg' +import { queryItemAsString, useDriveResolver, useRouteParam } from '@ownclouders/web-pkg' import { computed, ref } from 'vue' import { mock, mockDeep } from 'jest-mock-extended' import { ClientService } from '@ownclouders/web-pkg' @@ -21,7 +21,9 @@ import { jest.mock('@ownclouders/web-pkg', () => ({ ...jest.requireActual('@ownclouders/web-pkg'), useGetMatchingSpace: jest.fn(), - useDriveResolver: jest.fn() + useDriveResolver: jest.fn(), + useRouteParam: jest.fn(), + queryItemAsString: jest.fn() })) describe('DriveResolver view', () => { @@ -102,6 +104,16 @@ describe('DriveResolver view', () => { }) ) }) + it('redirects to private link if no drive alias but a fileId is given', async () => { + const { wrapper, mocks } = getMountedWrapper({ driveAliasAndItem: '' }) + await wrapper.vm.$nextTick() + + expect(mocks.$router.push).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'resolvePrivateLink' + }) + ) + }) }) function getMountedWrapper({ @@ -109,8 +121,12 @@ function getMountedWrapper({ space = undefined, internalSpace = undefined, currentRouteName = 'files-spaces-generic', - isUserContextReady = false + isUserContextReady = false, + driveAliasAndItem = 'personal/einstein/file', + fileId = '1' } = {}) { + jest.mocked(useRouteParam).mockReturnValue(ref(driveAliasAndItem)) + jest.mocked(queryItemAsString).mockReturnValue(fileId) jest.mocked(useDriveResolver).mockImplementation(() => ({ space, item: ref('/'),