Skip to content

Commit

Permalink
fix: display shared file versions
Browse files Browse the repository at this point in the history
Instead of checking permissions of the space, check permissions directly on the resource object if it is an incoming share because the space is manually built there without permissions.
  • Loading branch information
LukasHirt committed Feb 24, 2025
1 parent c23c6d5 commit a085508
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-display-shared-file-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Display shared file versions

We've fixed an issue where versions were not displayed in the sidebar for a shared file even when shared with necessary permissions. If a resource is an incoming share, we are now checking permission directly on the resource object instead of space.

https://github.com/owncloud/web/pull/12194
https://github.com/owncloud/web/issues/12168
1 change: 1 addition & 0 deletions packages/web-client/src/helpers/share/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export function buildIncomingShareResource({
canCreate: () => sharePermissions.includes(GraphSharePermission.createChildren),
canBeDeleted: () => sharePermissions.includes(GraphSharePermission.deleteStandard),
canEditTags: () => sharePermissions.includes(GraphSharePermission.createChildren),
canListVersions: () => sharePermissions.includes(GraphSharePermission.readVersions),
isMounted: () => false,
isReceivedShare: () => true,
canShare: () => false,
Expand Down
1 change: 1 addition & 0 deletions packages/web-client/src/helpers/share/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IncomingShareResource extends ShareResource {
syncEnabled: boolean
shareRoles: UnifiedRoleDefinition[]
sharePermissions: GraphSharePermission[]
canListVersions?(): boolean
}

export interface ShareRole extends UnifiedRoleDefinition {
Expand Down
16 changes: 15 additions & 1 deletion packages/web-pkg/src/composables/resources/useCanListVersions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useUserStore } from '../piniaStores'
import { isSpaceResource, isTrashResource, Resource, SpaceResource } from '@ownclouders/web-client'
import {
IncomingShareResource,
isSpaceResource,
isTrashResource,
Resource,
SpaceResource
} from '@ownclouders/web-client'

export const useCanListVersions = () => {
const userStore = useUserStore()
Expand All @@ -14,6 +20,14 @@ export const useCanListVersions = () => {
if (isTrashResource(resource)) {
return false
}

if (
resource.isReceivedShare() &&
typeof (resource as IncomingShareResource).canListVersions === 'function'
) {
return (resource as IncomingShareResource).canListVersions()
}

return space?.canListVersions({ user: userStore.user })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ const resourcesWithAllFields = [
shareTypes: [],
canRename: vi.fn(),
getDomSelector: () => extractDomSelector('documents'),
canDownload: () => true
canDownload: () => true,
canListVersions: () => true
},
{
id: 'another-one==',
driveId: 'another-one==',
name: 'Another one',
path: '/Another one',
indicators,
isFolder: true,
type: 'folder',
size: '237895',
Expand All @@ -213,14 +213,14 @@ const resourcesWithAllFields = [
tags: [],
canRename: vi.fn(),
getDomSelector: () => extractDomSelector('another-one=='),
canDownload: () => true
canDownload: () => true,
canListVersions: () => true
},
{
id: 'in-delete-queue==',
driveId: 'another-one==',
name: 'In delete queue',
path: '/In delete queue',
indicators,
isFolder: true,
type: 'folder',
size: '237895',
Expand All @@ -238,7 +238,8 @@ const resourcesWithAllFields = [
tags: [],
canRename: vi.fn(),
getDomSelector: () => extractDomSelector('in-delete-queue=='),
canDownload: () => true
canDownload: () => true,
canListVersions: () => true
}
] as IncomingShareResource[]

Expand Down Expand Up @@ -270,6 +271,7 @@ const processingResourcesWithAllFields = [
canRename: vi.fn(),
getDomSelector: () => extractDomSelector('forest'),
canDownload: () => true,
canListVersions: () => true,
processing: true
},
{
Expand All @@ -296,6 +298,7 @@ const processingResourcesWithAllFields = [
canRename: vi.fn(),
getDomSelector: () => extractDomSelector('notes'),
canDownload: () => true,
canListVersions: () => true,
processing: true
}
] as IncomingShareResource[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { getComposableWrapper } from '@ownclouders/web-test-helpers'
import { mock } from 'vitest-mock-extended'
import { Resource, SpaceResource, TrashResource } from '@ownclouders/web-client'
import {
IncomingShareResource,
Resource,
SpaceResource,
TrashResource
} from '@ownclouders/web-client'
import { useCanListVersions } from '../../../../src/composables/resources'

describe('useCanListVersions', () => {
Expand Down Expand Up @@ -55,6 +60,21 @@ describe('useCanListVersions', () => {
}
})
})

it('should use resource permissions instead of space permissions for received shares', () => {
getWrapper({
setup: ({ canListVersions }) => {
const space = mock<SpaceResource>({ canListVersions: () => false })
const resource = mock<IncomingShareResource>({
type: 'file',
isReceivedShare: () => true,
canListVersions: () => true
})
const canList = canListVersions({ space, resource })
expect(canList).toBeTruthy()
}
})
})
})
})

Expand Down

0 comments on commit a085508

Please sign in to comment.