-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hide version panel with insufficient permissions
Users that have insufficient permissions to view file versions don't see the version sidebar panel anymore. This currently affects regular share receivers, space viewers and space editors without the `versions/read` permission.
- Loading branch information
Jannik Stehle
committed
Aug 30, 2024
1 parent
536d821
commit 19a3469
Showing
11 changed files
with
138 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Enhancement: Hide versions panel with insufficient permissions | ||
|
||
Users that have insufficient permissions to view file versions don't see the versions sidebar panel anymore. This currently affects regular share receivers, space viewers and space editors without the permission to view versions. | ||
|
||
https://github.com/owncloud/web/pull/11484 | ||
https://github.com/owncloud/web/issues/11359 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useCanBeOpenedWithSecureView' | ||
export * from './useCanListVersions' | ||
export * from './useGetResourceContext' | ||
export * from './useResourceContents' |
26 changes: 26 additions & 0 deletions
26
packages/web-pkg/src/composables/resources/useCanListVersions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useUserStore } from '../piniaStores' | ||
import { isSpaceResource, isTrashResource, Resource, SpaceResource } from '@ownclouders/web-client' | ||
|
||
export const useCanListVersions = () => { | ||
const userStore = useUserStore() | ||
|
||
const canListVersions = ({ space, resource }: { space: SpaceResource; resource: Resource }) => { | ||
if (resource.type === 'folder') { | ||
return false | ||
} | ||
if (isSpaceResource(resource)) { | ||
return false | ||
} | ||
if (isTrashResource(resource)) { | ||
return false | ||
} | ||
if (!space.canListVersions({ user: userStore.user })) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
return { | ||
canListVersions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/web-pkg/tests/unit/composables/resources/useCanListVersions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { getComposableWrapper } from 'web-test-helpers' | ||
import { mock } from 'vitest-mock-extended' | ||
import { Resource, SpaceResource, TrashResource } from '@ownclouders/web-client' | ||
import { useCanListVersions } from '../../../../src/composables/resources' | ||
|
||
describe('useCanListVersions', () => { | ||
describe('canListVersions', () => { | ||
it('returns true for files when user has sufficient permissions in space', () => { | ||
getWrapper({ | ||
setup: ({ canListVersions }) => { | ||
const space = mock<SpaceResource>({ canListVersions: () => true }) | ||
const resource = mock<Resource>({ type: 'file' }) | ||
const canList = canListVersions({ space, resource }) | ||
expect(canList).toBeTruthy() | ||
} | ||
}) | ||
}) | ||
it('returns false for folders', () => { | ||
getWrapper({ | ||
setup: ({ canListVersions }) => { | ||
const space = mock<SpaceResource>({ canListVersions: () => true }) | ||
const resource = mock<Resource>({ type: 'folder' }) | ||
const canList = canListVersions({ space, resource }) | ||
expect(canList).toBeFalsy() | ||
} | ||
}) | ||
}) | ||
it('returns false for space resources', () => { | ||
getWrapper({ | ||
setup: ({ canListVersions }) => { | ||
const space = mock<SpaceResource>({ canListVersions: () => true }) | ||
const resource = mock<SpaceResource>({ type: 'space' }) | ||
const canList = canListVersions({ space, resource }) | ||
expect(canList).toBeFalsy() | ||
} | ||
}) | ||
}) | ||
it('returns false for trash resources', () => { | ||
getWrapper({ | ||
setup: ({ canListVersions }) => { | ||
const space = mock<SpaceResource>({ canListVersions: () => true }) | ||
const resource = mock<TrashResource>({ type: 'file', ddate: '' }) | ||
const canList = canListVersions({ space, resource }) | ||
expect(canList).toBeFalsy() | ||
} | ||
}) | ||
}) | ||
it('returns false when user does not have sufficient permissions in space', () => { | ||
getWrapper({ | ||
setup: ({ canListVersions }) => { | ||
const space = mock<SpaceResource>({ canListVersions: () => false }) | ||
const resource = mock<Resource>({ type: 'file' }) | ||
const canList = canListVersions({ space, resource }) | ||
expect(canList).toBeFalsy() | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ | ||
setup | ||
}: { | ||
setup: (instance: ReturnType<typeof useCanListVersions>) => void | ||
}) { | ||
return { | ||
wrapper: getComposableWrapper(() => { | ||
const instance = useCanListVersions() | ||
setup(instance) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters