Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/web-runtime/src/router/setupVaultUnlockGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
getVaultClaim,
queryItemAsString,
resolveVaultEngine,
routeToContextQuery,
useExtensionRegistry,
useSpacesLoading,
useSpacesStore,
VaultClaim
} from '@opencloud-eu/web-pkg'
import { SpaceResource } from '@opencloud-eu/web-client'
import { isPublicSpaceResource, SpaceResource } from '@opencloud-eu/web-client'

/** Space-relative, absolute path a `driveAliasAndItem` points at within `space`. */
function spaceRelativePath(driveAliasAndItem: string, space: SpaceResource): string {
Expand Down Expand Up @@ -134,6 +135,7 @@ export const setupVaultUnlockGuard = (router: Router, clientService: ClientServi
...claim.unlockRoute,
query: {
...(claim.unlockRoute.query || {}),
...(isPublicSpaceResource(space) && routeToContextQuery(to)),
redirectUrl: to.fullPath,
...(cancelUrl && { cancelUrl })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
vi.mock('@opencloud-eu/web-pkg', async () => {
const { getSpaceForDriveAliasAndItem } =
await import('../../../../web-pkg/src/helpers/spaces/driveAlias')
const { queryItemAsString } =
const { queryItemAsString, routeToContextQuery } =
await import('../../../../web-pkg/src/composables/appDefaults/useAppNavigation')
return {
getSpaceForDriveAliasAndItem,
queryItemAsString,
routeToContextQuery,
getVaultClaim: vi.fn(),
resolveVaultEngine: vi.fn(),
useExtensionRegistry: vi.fn(() => ({})),
Expand Down Expand Up @@ -149,6 +150,32 @@ describe('setupVaultUnlockGuard', () => {
})
})

it('keeps the public link context, so anonymous visitors are not sent to the login', async () => {
const publicSpace = { id: 'token', driveAlias: 'public/token', driveType: 'public' }
const guard = installGuard({
spaces: [publicSpace],
claim: { vaultRoot: '/my.vault', unlockRoute },
engine: null
})

const result = await guard(
{
name: 'files-public-link',
params: { driveAliasAndItem: 'public/token/my.vault' },
query: {},
fullPath: '/files/link/public/token/my.vault'
},
coldStart
)

expect(result).toMatchObject({
query: {
contextRouteName: 'files-public-link',
contextRouteParams: { driveAliasAndItem: 'public/token/my.vault' }
}
})
})

it('carries where the user came from, so cancelling can return there', async () => {
// e.g. opening a vault from the search results: cancelling the unlock has to
// land back on the results, not next to the vault.
Expand Down
Loading