fix: [ocisdev-1199] resolve vault permalinks into vault scope (#12881)

* fix: [ocisdev-1199] resolve vault permalinks into vault scope

* chore: bugfix

* fix: review, share-jail early return
This commit is contained in:
Michal Klos authored and GitHub committed 2026-09-07 09:51:10 +02:00
1 parent 1150423490
commit 361b719fa9
4 files changed
+126 -10

No files matched your search

@@ -0,0 +1,6 @@
Bugfix: Resolve Safe/Vault permalinks
A permanent link to a file inside the Safe failed for the recipient. Such links now
open the shared file.
https://github.com/owncloud/ocis/pull/12881
@@ -46,7 +46,8 @@ import {
useRouteQuery,
createLocationSpaces,
createLocationShares,
useClientService
useClientService,
useCapabilityStore
} from '@ownclouders/web-pkg'
import { unref, defineComponent, computed, onMounted, ref, Ref } from 'vue'
import { dirname } from 'path'
@@ -61,8 +62,10 @@ export default defineComponent({
setup() {
const router = useRouter()
const id = useRouteParam('fileId')
const scope = useRouteParam('scope')
const { $gettext } = useGettext()
const clientService = useClientService()
const capabilityStore = useCapabilityStore()
const resource: Ref<Resource> = ref()
const sharedParentResource: Ref<Resource> = ref()
@@ -83,13 +86,34 @@ export default defineComponent({
})
const resolvePrivateLinkTask = useTask(function* (signal, id) {
// vault file but non-vault /f/ URL: hard-reload into /vault so the vault client
// base URLs are picked up (they are derived from the URL at boot). The MFA
// step-up is enforced by the authService guard on the vault scope, which also
// fires on a router.push, so it is not the reason for the full reload.
if (
capabilityStore.vaultEnabled &&
id?.split('$')[0] === capabilityStore.vaultStorageProvider &&
unref(scope) !== 'vault'
) {
window.location.replace(
router.resolve({
name: 'resolvePrivateLink',
params: { scope: 'vault', fileId: id },
query: router.currentRoute.value.query
}).href
)
return
}
if (
[
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}!${SHARE_JAIL_ID}`,
`${SHARE_JAIL_ID}$${SHARE_JAIL_ID}`
].includes(id)
) {
return router.push(createLocationShares('files-shares-with-me'))
return router.push(
createLocationShares('files-shares-with-me', { params: { scope: unref(scope) } })
)
}
let result: Awaited<ReturnType<typeof getResourceContext>>
@@ -140,7 +164,7 @@ export default defineComponent({
const { params, query } = createFileRouteOptions(space, { fileId, path })
const openWithDefault = unref(openWithDefaultApp) !== 'false' && !unref(details)
targetLocation.params = params
targetLocation.params = { ...params, scope: unref(scope) }
targetLocation.query = {
...query,
scrollTo: unref(resource).fileId,
@@ -156,9 +180,10 @@ export default defineComponent({
return !resolvePrivateLinkTask.last || resolvePrivateLinkTask.isRunning
})
const sharedWithMeRoute = computed(() => {
return { name: 'files-shares-with-me' }
})
const sharedWithMeRoute = computed(() => ({
name: 'files-shares-with-me',
params: { scope: unref(scope) }
}))
const openSharedWithMeLabel = computed(() => {
return $gettext('Open "Shared with me"')
+1 -1
View File
@@ -54,7 +54,7 @@ const routes = [
meta: { title: $gettext('Oidc redirect'), authContext: 'anonymous' }
},
{
path: '/f/:fileId',
path: '/:scope(vault)?/f/:fileId',
name: 'resolvePrivateLink',
component: ResolvePrivateLinkPage,
meta: { title: $gettext('Private link'), authContext: 'user' }
@@ -1,7 +1,7 @@
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 } from '@ownclouders/web-pkg'
import { queryItemAsString, useGetResourceContext, useRouteParam } from '@ownclouders/web-pkg'
import { Resource, SHARE_JAIL_ID, SpaceResource } from '@ownclouders/web-client'
vi.mock('@ownclouders/web-pkg', async (importOriginal) => ({
@@ -84,6 +84,83 @@ describe('resolvePrivateLink', () => {
)
})
})
describe('vault permalinks', () => {
const vaultCapabilityState = {
capabilities: { vault: { enabled: true, vault_storage_provider: 'vault-provider' } }
}
const originalLocation = window.location
afterEach(() => {
Object.defineProperty(window, 'location', {
configurable: true,
value: originalLocation
})
})
it('hard-redirects a vault permalink into vault scope instead of resolving it', async () => {
const replace = vi.fn()
Object.defineProperty(window, 'location', {
configurable: true,
value: { replace, href: '' }
})
const { wrapper, mocks } = getWrapper({
fileId: 'vault-provider$space!item',
capabilityState: vaultCapabilityState
})
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' }
})
)
expect(mocks.$router.push).not.toHaveBeenCalled()
})
it('resolves normally when the permalink is not a vault resource', async () => {
const replace = vi.fn()
Object.defineProperty(window, 'location', {
configurable: true,
value: { replace, href: '' }
})
const fileId = 'other-provider$space!item'
const space = mock<SpaceResource>({ getDriveAliasAndItem: () => 'personal/home' })
const resource = mock<Resource>({ fileId })
const { wrapper, mocks } = getWrapper({
space,
resource,
fileId,
path: '/',
capabilityState: vaultCapabilityState
})
await wrapper.vm.resolvePrivateLinkTask.last
expect(replace).not.toHaveBeenCalled()
expect(mocks.$router.push).toHaveBeenCalled()
})
it('does not reload when already in vault scope', async () => {
const replace = vi.fn()
Object.defineProperty(window, 'location', {
configurable: true,
value: { replace, href: '' }
})
const fileId = 'vault-provider$space!item'
const space = mock<SpaceResource>({ getDriveAliasAndItem: () => 'personal/home' })
const resource = mock<Resource>({ fileId })
const { wrapper, mocks } = getWrapper({
space,
resource,
fileId,
path: '/',
scope: 'vault',
capabilityState: vaultCapabilityState
})
await wrapper.vm.resolvePrivateLinkTask.last
expect(replace).not.toHaveBeenCalled()
expect(mocks.$router.push).toHaveBeenCalled()
})
})
it('passes the details query param if given via query', async () => {
const details = 'sharing'
const { wrapper, mocks } = getWrapper({ details, path: '/' })
@@ -138,7 +215,9 @@ function getWrapper({
fileId = '',
details = '',
hiddenShare = false,
openWithDefaultAppQuery = 'true'
openWithDefaultAppQuery = 'true',
scope = '',
capabilityState = {}
}: {
space?: SpaceResource
resource?: Resource
@@ -147,7 +226,13 @@ function getWrapper({
details?: string
hiddenShare?: boolean
openWithDefaultAppQuery?: string
scope?: string
capabilityState?: Record<string, unknown>
} = {}) {
vi.mocked(useRouteParam).mockImplementation(
(str) => (str === 'scope' && scope ? scope : str) as any
)
vi.mocked(queryItemAsString).mockImplementation((str) => {
if (str === 'fileId') {
return fileId
@@ -174,7 +259,7 @@ function getWrapper({
mocks,
wrapper: shallowMount(resolvePrivateLink, {
global: {
plugins: [...defaultPlugins()],
plugins: [...defaultPlugins({ piniaOptions: { capabilityState } })],
mocks,
provide: mocks
}