From 71e9548b2752edb2e1e4b502264a50ed462d74ef Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 16 Oct 2023 12:06:34 +0200 Subject: [PATCH 1/6] feat: add permission checks for creating shares and favorites --- .../src/components/FilesList/QuickActions.vue | 2 +- .../Shares/Collaborators/RoleDropdown.vue | 5 +- .../components/SideBar/Shares/FileLinks.vue | 5 +- .../components/SideBar/Shares/FileShares.vue | 5 +- packages/web-app-files/src/index.ts | 2 +- .../src/helpers/resource/functions.ts | 8 +-- .../web-client/src/helpers/resource/types.ts | 4 +- .../{resource.spec.ts => functions.spec.ts} | 49 +++++++++++++++++++ .../web-pkg/src/components/AppBar/AppBar.vue | 6 ++- .../files/useFileActionsCreateQuicklink.ts | 2 +- .../actions/files/useFileActionsFavorite.ts | 5 +- .../actions/files/useFileActionsShowShares.ts | 4 +- packages/web-pkg/src/quickActions.ts | 4 +- .../src/services/auth/abilities.ts | 6 +++ 14 files changed, 91 insertions(+), 16 deletions(-) rename packages/web-client/tests/unit/helpers/resource/{resource.spec.ts => functions.spec.ts} (58%) diff --git a/packages/web-app-files/src/components/FilesList/QuickActions.vue b/packages/web-app-files/src/components/FilesList/QuickActions.vue index 375bb623215..09a9d66718b 100644 --- a/packages/web-app-files/src/components/FilesList/QuickActions.vue +++ b/packages/web-app-files/src/components/FilesList/QuickActions.vue @@ -49,7 +49,7 @@ export default defineComponent({ const language = useGettext() const filteredActions = computed(() => - pickBy(props.actions, (action) => action.displayed(props.item, store) === true) + pickBy(props.actions, (action) => action.displayed(props.item, store, ability) === true) ) return { diff --git a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/RoleDropdown.vue b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/RoleDropdown.vue index 5ead5e145f9..2e6bae8a174 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/RoleDropdown.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/RoleDropdown.vue @@ -122,6 +122,7 @@ import { import * as uuid from 'uuid' import { defineComponent, inject, PropType, ComponentPublicInstance } from 'vue' import { + useAbility, useCapabilityFilesSharingAllowCustomPermissions, useCapabilityFilesSharingResharingDefault, useStore @@ -166,7 +167,9 @@ export default defineComponent({ emits: ['optionChange'], setup() { const store = useStore() + const ability = useAbility() return { + ability, resource: inject('resource'), incomingParentShare: inject('incomingParentShare'), hasRoleCustomPermissions: useCapabilityFilesSharingAllowCustomPermissions(store), @@ -202,7 +205,7 @@ export default defineComponent({ return PeopleShareRoles.custom(this.resource.isFolder) }, resourceIsSharable() { - return this.allowSharePermission && this.resource.canShare() + return this.allowSharePermission && this.resource.canShare({ ability: this.ability }) }, availableRoles() { if (this.resourceIsSpace) { diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue index 2832009aa51..621a8156a26 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue @@ -158,7 +158,8 @@ export default defineComponent({ }, setup() { const store = useStore() - const { can } = useAbility() + const ability = useAbility() + const { can } = ability const passwordPolicyService = usePasswordPolicyService() const hasResharing = useCapabilityFilesSharingResharing() @@ -206,7 +207,7 @@ export default defineComponent({ return false } - return unref(resource).canShare({ user: store.getters.user }) + return unref(resource).canShare({ user: store.getters.user, ability }) }) const canEditLink = ({ permissions }: Share) => { diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue index 37913851d4a..521cc41df18 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue @@ -89,6 +89,7 @@