From 69b442330066d0cd24b59ffba97d0205df5ba07d Mon Sep 17 00:00:00 2001 From: Gaurav Soni Date: Thu, 24 Sep 2026 15:27:57 +0200 Subject: [PATCH] fix: [OCISDEV-1435] resolve vault permanent links opened outside the vault (#13001) --- ...gfix-vault-permanent-link-outside-vault.md | 15 +++++++ .../InviteCollaboratorForm.vue | 4 +- .../InviteCollaboratorForm.spec.ts | 15 ++++--- web/packages/web-client/src/constants.ts | 9 ++++ .../web-client/src/helpers/space/types.ts | 3 -- .../composables/piniaStores/capabilities.ts | 4 +- .../src/components/Topbar/Notifications.vue | 4 +- .../src/pages/resolvePrivateLink.vue | 9 +++- .../components/Topbar/Notifications.spec.ts | 13 ++++-- .../unit/pages/resolvePrivateLink.spec.ts | 45 +++++++++++++++---- 10 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 changelog/unreleased/bugfix-vault-permanent-link-outside-vault.md diff --git a/changelog/unreleased/bugfix-vault-permanent-link-outside-vault.md b/changelog/unreleased/bugfix-vault-permanent-link-outside-vault.md new file mode 100644 index 00000000000..24c61ddc5f3 --- /dev/null +++ b/changelog/unreleased/bugfix-vault-permanent-link-outside-vault.md @@ -0,0 +1,15 @@ +Bugfix: Open Safe permanent links from outside the Safe + +A permanent link to a file in the Safe, opened in a regular Drive tab, showed +"An error occurred while resolving the private link" instead of the file. The +Web frontend recognized Safe files by a storage provider id that the server +only sends to sessions already inside the Safe, so a Drive tab never redirected +the link into the Safe. + +The Safe storage provider id is fixed, so the frontend now uses it as a +constant, like the share jail and OCM ids. This also keeps Safe notifications +out of the Drive view and lets the invite form recognize Safe resources in +Drive mode. The `vaultStorageProvider` getter of the web-pkg capability store +is removed; use `VAULT_STORAGE_PROVIDER_ID` from web-client instead. + +https://github.com/owncloud/ocis/pull/13001 diff --git a/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue b/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue index ad950b34aa7..6ba266f1ced 100644 --- a/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue +++ b/web/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue @@ -170,7 +170,7 @@ import { } from '@ownclouders/web-pkg' import { computed, inject, ref, unref, watch, onMounted, nextTick, Ref, useTemplateRef } from 'vue' -import { Resource, SpaceResource } from '@ownclouders/web-client' +import { Resource, SpaceResource, VAULT_STORAGE_PROVIDER_ID } from '@ownclouders/web-client' import { DateTime } from 'luxon' import { OcDrop } from '@ownclouders/design-system/components' import { useTask } from 'vue-concurrency' @@ -295,7 +295,7 @@ const isVaultResource = computed(() => { if (!unref(capabilityRefs.vaultEnabled) || typeof storageId !== 'string') { return false } - return storageId.split('$')[0] === unref(capabilityRefs.vaultStorageProvider) + return storageId.split('$')[0] === VAULT_STORAGE_PROVIDER_ID }) const createSharesConcurrentRequests = computed(() => { diff --git a/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts b/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts index 46329655b6c..b2c46fb26d8 100644 --- a/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts +++ b/web/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.spec.ts @@ -7,7 +7,7 @@ import { shallowMount, VueWrapper } from '@ownclouders/web-test-helpers' -import { Resource, SpaceResource } from '@ownclouders/web-client' +import { Resource, SpaceResource, VAULT_STORAGE_PROVIDER_ID } from '@ownclouders/web-client' import { useSharesStore } from '@ownclouders/web-pkg' import { CollaboratorAutoCompleteItem, CollaboratorShare, ShareRole } from '@ownclouders/web-client' import { Group, User } from '@ownclouders/web-client/graph/generated' @@ -114,16 +114,17 @@ describe('InviteCollaboratorForm', () => { }) }) describe('fetching recipients for a vault resource', () => { - const vaultStorageProvider = '1a01c2c4-4309-4483-a845-842fd56d8622' + // vault resources are recognized by the fixed vault storage provider id, not by the + // `vault_storage_provider` capability, which a drive-mode session receives empty const vaultCapabilities = { files_sharing: { federation: { incoming: true, outgoing: true } }, - vault: { enabled: true, vault_storage_provider: vaultStorageProvider } + vault: { enabled: true, vault_storage_provider: '' } } it('only asks for users that may access the vault, and for no groups at all', async () => { const { wrapper, mocks } = getWrapper({ capabilities: vaultCapabilities, - resource: mock({ ...folderMock, storageId: vaultStorageProvider }) + resource: mock({ ...folderMock, storageId: VAULT_STORAGE_PROVIDER_ID }) }) await wrapper.vm.fetchRecipientsTask.last @@ -138,7 +139,7 @@ describe('InviteCollaboratorForm', () => { capabilities: vaultCapabilities, resource: mock({ ...spaceMock, - storageId: `${vaultStorageProvider}$some-space-id` + storageId: `${VAULT_STORAGE_PROVIDER_ID}$some-space-id` }) }) await wrapper.vm.fetchRecipientsTask.last @@ -165,9 +166,9 @@ describe('InviteCollaboratorForm', () => { const { wrapper, mocks } = getWrapper({ capabilities: { ...vaultCapabilities, - vault: { enabled: false, vault_storage_provider: vaultStorageProvider } + vault: { enabled: false } }, - resource: mock({ ...folderMock, storageId: vaultStorageProvider }) + resource: mock({ ...folderMock, storageId: VAULT_STORAGE_PROVIDER_ID }) }) await wrapper.vm.fetchRecipientsTask.last diff --git a/web/packages/web-client/src/constants.ts b/web/packages/web-client/src/constants.ts index ff26f666ae0..2f5bf79c164 100644 --- a/web/packages/web-client/src/constants.ts +++ b/web/packages/web-client/src/constants.ts @@ -21,3 +21,12 @@ export const PASSWORD_PROTECTED_FOLDER_RENAMED_MESSAGE = * Hiding the extension currently leads to hiding all actions except delete. */ export const HIDDEN_FILE_EXTENSIONS = [PASSWORD_PROTECTED_FOLDER_FILE_EXTENSION] + +/** + * Fixed storage provider ids of reva's special storages, mirroring `ShareStorageProviderID`, + * `OCMStorageProviderID` and `VaultStorageProviderID` in reva's `pkg/utils`. They are the + * same in every deployment. + */ +export const SHARE_JAIL_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668' +export const OCM_PROVIDER_ID = '89f37a33-858b-45fa-8890-a1f2b27d90e1' +export const VAULT_STORAGE_PROVIDER_ID = '1a01c2c4-4309-4483-a845-842fd56d8622' diff --git a/web/packages/web-client/src/helpers/space/types.ts b/web/packages/web-client/src/helpers/space/types.ts index 23380331157..107e46479a6 100644 --- a/web/packages/web-client/src/helpers/space/types.ts +++ b/web/packages/web-client/src/helpers/space/types.ts @@ -14,9 +14,6 @@ import { } from '@ownclouders/web-client/graph/generated' import { Ability, Resource } from '../resource' -export const SHARE_JAIL_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668' -export const OCM_PROVIDER_ID = '89f37a33-858b-45fa-8890-a1f2b27d90e1' - export type SpaceMember = { grantedTo: SharePointIdentitySet permissions: string[] diff --git a/web/packages/web-pkg/src/composables/piniaStores/capabilities.ts b/web/packages/web-pkg/src/composables/piniaStores/capabilities.ts index ee69d70054c..a677f165e5c 100644 --- a/web/packages/web-pkg/src/composables/piniaStores/capabilities.ts +++ b/web/packages/web-pkg/src/composables/piniaStores/capabilities.ts @@ -163,7 +163,6 @@ export const useCapabilityStore = defineStore('capabilities', () => { const authMfaSessionDuration = computed(() => unref(capabilities).auth.mfa.session_duration) const vaultEnabled = computed(() => unref(capabilities).vault?.enabled) - const vaultStorageProvider = computed(() => unref(capabilities).vault?.vault_storage_provider) return { isInitialized, @@ -216,8 +215,7 @@ export const useCapabilityStore = defineStore('capabilities', () => { authMfaEnabled, authMfaRequiredLevelname, authMfaSessionDuration, - vaultEnabled, - vaultStorageProvider + vaultEnabled } }) diff --git a/web/packages/web-runtime/src/components/Topbar/Notifications.vue b/web/packages/web-runtime/src/components/Topbar/Notifications.vue index fc41e57425d..c59c9b55d6e 100644 --- a/web/packages/web-runtime/src/components/Topbar/Notifications.vue +++ b/web/packages/web-runtime/src/components/Topbar/Notifications.vue @@ -93,7 +93,7 @@ import { Notification } from '../../helpers/notifications' import { useGettext } from 'vue3-gettext' import { useTask } from 'vue-concurrency' import { MESSAGE_TYPE } from '@ownclouders/web-client/sse' -import { call } from '@ownclouders/web-client' +import { call, VAULT_STORAGE_PROVIDER_ID } from '@ownclouders/web-client' const POLLING_INTERVAL = 30000 @@ -112,7 +112,7 @@ export default { const { isInVault } = useVault() const isVaultNotification = (notification: Notification) => - notification.object_id?.split('$')[0] === capabilityStore.vaultStorageProvider + notification.object_id?.split('$')[0] === VAULT_STORAGE_PROVIDER_ID const notifications = computed(() => { if (!capabilityStore.vaultEnabled) { diff --git a/web/packages/web-runtime/src/pages/resolvePrivateLink.vue b/web/packages/web-runtime/src/pages/resolvePrivateLink.vue index 9d9bc718b96..b41f4afd297 100644 --- a/web/packages/web-runtime/src/pages/resolvePrivateLink.vue +++ b/web/packages/web-runtime/src/pages/resolvePrivateLink.vue @@ -53,7 +53,12 @@ import { unref, defineComponent, computed, onMounted, ref, Ref } from 'vue' import { dirname } from 'path' import { createFileRouteOptions, useGetResourceContext } from '@ownclouders/web-pkg' import { useTask } from 'vue-concurrency' -import { isShareSpaceResource, Resource, SHARE_JAIL_ID } from '@ownclouders/web-client' +import { + isShareSpaceResource, + Resource, + SHARE_JAIL_ID, + VAULT_STORAGE_PROVIDER_ID +} from '@ownclouders/web-client' import { RouteLocationNamedRaw } from 'vue-router' import { useGettext } from 'vue3-gettext' @@ -92,7 +97,7 @@ export default defineComponent({ // fires on a router.push, so it is not the reason for the full reload. if ( capabilityStore.vaultEnabled && - id?.split('$')[0] === capabilityStore.vaultStorageProvider && + id?.split('$')[0] === VAULT_STORAGE_PROVIDER_ID && unref(scope) !== 'vault' ) { window.location.replace( diff --git a/web/packages/web-runtime/tests/unit/components/Topbar/Notifications.spec.ts b/web/packages/web-runtime/tests/unit/components/Topbar/Notifications.spec.ts index 0f330bce723..bcaebee6090 100644 --- a/web/packages/web-runtime/tests/unit/components/Topbar/Notifications.spec.ts +++ b/web/packages/web-runtime/tests/unit/components/Topbar/Notifications.spec.ts @@ -7,7 +7,7 @@ import { mockHttpResponse, shallowMount } from '@ownclouders/web-test-helpers' -import { SpaceResource } from '@ownclouders/web-client' +import { SpaceResource, VAULT_STORAGE_PROVIDER_ID } from '@ownclouders/web-client' import { RouterLink, RouteLocationNamedRaw, RouteLocationNormalizedLoaded } from 'vue-router' import Avatar from '../../../../src/components/Avatar.vue' @@ -268,7 +268,7 @@ describe('Notification component', () => { messageRich: undefined, computedMessage: undefined, computedLink: undefined, - object_id: 'vault-provider$resource-20', + object_id: `${VAULT_STORAGE_PROVIDER_ID}$resource-20`, datetime: '2024-01-01T00:00:00Z' }) const driveNotification = mock({ @@ -278,8 +278,13 @@ describe('Notification component', () => { object_id: 'other-provider$resource-22', datetime: '2024-01-01T00:00:01Z' }) + // a vault session fetches capabilities with `?vault=true` and gets the provider id, + // a drive-mode session fetches them without it and gets an empty value const vaultCapabilityState = { - capabilities: { vault: { enabled: true, vault_storage_provider: 'vault-provider' } } + capabilities: { vault: { enabled: true, vault_storage_provider: VAULT_STORAGE_PROVIDER_ID } } + } + const driveCapabilityState = { + capabilities: { vault: { enabled: true, vault_storage_provider: '' } } } it('shows only vault notifications when in vault mode', async () => { @@ -295,7 +300,7 @@ describe('Notification component', () => { vi.mocked(useVault).mockReturnValue({ isInVault: false }) const { wrapper } = getWrapper({ notifications: [vaultNotification, driveNotification], - capabilityState: vaultCapabilityState + capabilityState: driveCapabilityState }) await wrapper.vm.fetchNotificationsTask.last expect(wrapper.findAll(selectors.notificationItem).length).toBe(1) diff --git a/web/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts b/web/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts index 705a9d50688..f23233700cc 100644 --- a/web/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts +++ b/web/packages/web-runtime/tests/unit/pages/resolvePrivateLink.spec.ts @@ -2,7 +2,12 @@ import resolvePrivateLink from '../../../src/pages/resolvePrivateLink.vue' import { defaultPlugins, defaultComponentMocks, shallowMount } from '@ownclouders/web-test-helpers' import { mock } from 'vitest-mock-extended' import { queryItemAsString, useGetResourceContext, useRouteParam } from '@ownclouders/web-pkg' -import { Resource, SHARE_JAIL_ID, SpaceResource } from '@ownclouders/web-client' +import { + Resource, + SHARE_JAIL_ID, + SpaceResource, + VAULT_STORAGE_PROVIDER_ID +} from '@ownclouders/web-client' vi.mock('@ownclouders/web-pkg', async (importOriginal) => ({ ...(await importOriginal()), @@ -85,9 +90,11 @@ describe('resolvePrivateLink', () => { }) }) describe('vault permalinks', () => { - const vaultCapabilityState = { - capabilities: { vault: { enabled: true, vault_storage_provider: 'vault-provider' } } + // a drive-mode session fetches capabilities without `?vault=true` and gets no provider id + const driveCapabilityState = { + capabilities: { vault: { enabled: true, vault_storage_provider: '' } } } + const vaultFileId = `${VAULT_STORAGE_PROVIDER_ID}$space!item` const originalLocation = window.location afterEach(() => { @@ -104,15 +111,15 @@ describe('resolvePrivateLink', () => { value: { replace, href: '' } }) const { wrapper, mocks } = getWrapper({ - fileId: 'vault-provider$space!item', - capabilityState: vaultCapabilityState + fileId: vaultFileId, + capabilityState: driveCapabilityState }) await wrapper.vm.resolvePrivateLinkTask.last expect(replace).toHaveBeenCalledTimes(1) expect(mocks.$router.resolve).toHaveBeenCalledWith( expect.objectContaining({ name: 'resolvePrivateLink', - params: { scope: 'vault', fileId: 'vault-provider$space!item' } + params: { scope: 'vault', fileId: vaultFileId } }) ) expect(mocks.$router.push).not.toHaveBeenCalled() @@ -132,7 +139,27 @@ describe('resolvePrivateLink', () => { resource, fileId, path: '/', - capabilityState: vaultCapabilityState + capabilityState: driveCapabilityState + }) + await wrapper.vm.resolvePrivateLinkTask.last + expect(replace).not.toHaveBeenCalled() + expect(mocks.$router.push).toHaveBeenCalled() + }) + + it('does not redirect a vault permalink when vault mode is disabled', async () => { + const replace = vi.fn() + Object.defineProperty(window, 'location', { + configurable: true, + value: { replace, href: '' } + }) + const space = mock({ getDriveAliasAndItem: () => 'personal/home' }) + const resource = mock({ fileId: vaultFileId }) + const { wrapper, mocks } = getWrapper({ + space, + resource, + fileId: vaultFileId, + path: '/', + capabilityState: { capabilities: { vault: { enabled: false } } } }) await wrapper.vm.resolvePrivateLinkTask.last expect(replace).not.toHaveBeenCalled() @@ -145,7 +172,7 @@ describe('resolvePrivateLink', () => { configurable: true, value: { replace, href: '' } }) - const fileId = 'vault-provider$space!item' + const fileId = vaultFileId const space = mock({ getDriveAliasAndItem: () => 'personal/home' }) const resource = mock({ fileId }) const { wrapper, mocks } = getWrapper({ @@ -154,7 +181,7 @@ describe('resolvePrivateLink', () => { fileId, path: '/', scope: 'vault', - capabilityState: vaultCapabilityState + capabilityState: driveCapabilityState }) await wrapper.vm.resolvePrivateLinkTask.last expect(replace).not.toHaveBeenCalled()