From 3f6e10fe05ccb2872f96f3226fe71b5551fcfb27 Mon Sep 17 00:00:00 2001 From: Paul Neubauer Date: Thu, 9 Mar 2023 12:33:55 +0100 Subject: [PATCH] Use capabilities in getByName --- .../SideBar/Shares/Links/CreateQuickLink.vue | 24 +++++++++++++++---- .../web-app-files/src/helpers/share/link.ts | 20 +++++++++++++--- packages/web-client/src/helpers/share/role.ts | 10 ++++++-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue index 3dec6ca2912..e9530c21358 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue @@ -28,13 +28,15 @@ import { computed, defineComponent, inject } from 'vue' import { useAbility, + useCapabilityFilesSharingPublicAlias, + useCapabilityFilesSharingPublicCanContribute, + useCapabilityFilesSharingPublicCanEdit, useCapabilityFilesSharingQuickLinkDefaultRole, useCapabilityFilesSharingResharing } from 'web-pkg' import { Resource } from 'web-client/src' import { useGettext } from 'vue3-gettext' import { LinkShareRoles } from 'web-client/src/helpers/share' -import { Capabilities } from 'web-client/src/ocs' export default defineComponent({ name: 'CreateQuickLink', @@ -54,10 +56,19 @@ export default defineComponent({ const resource = inject('resource') const createQuickLink = () => { const allowResharing = useCapabilityFilesSharingResharing().value + const canEdit = useCapabilityFilesSharingPublicCanEdit().value + const canContribute = useCapabilityFilesSharingPublicCanContribute().value + const alias = useCapabilityFilesSharingPublicAlias().value const emitData = { link: { name: $gettext('Quicklink'), - permissions: LinkShareRoles.getByName('none', resource.isFolder).bitmask(allowResharing), + permissions: LinkShareRoles.getByName( + 'none', + resource.isFolder, + canEdit, + canContribute, + alias + ).bitmask(allowResharing), expiration: props.expirationDate.enforced ? props.expirationDate.default : null, quicklink: true, password: false @@ -68,8 +79,13 @@ export default defineComponent({ } const capabilitiesRoleName = useCapabilityFilesSharingQuickLinkDefaultRole().value emitData.link.permissions = ( - LinkShareRoles.getByName(capabilitiesRoleName, resource.isFolder) || - LinkShareRoles.getByName('viewer', resource.isFolder) + LinkShareRoles.getByName( + capabilitiesRoleName, + resource.isFolder, + canEdit, + canContribute, + alias + ) || LinkShareRoles.getByName('viewer', resource.isFolder, canEdit, canContribute, alias) ).bitmask(allowResharing) emit('createPublicLink', emitData) } diff --git a/packages/web-app-files/src/helpers/share/link.ts b/packages/web-app-files/src/helpers/share/link.ts index 29940eae400..af0bb40de74 100644 --- a/packages/web-app-files/src/helpers/share/link.ts +++ b/packages/web-app-files/src/helpers/share/link.ts @@ -21,13 +21,27 @@ export const createQuicklink = async (args: CreateQuicklink): Promise => const allowResharing = store.state.user.capabilities.files_sharing?.resharing const capabilitiesRoleName = store.state.user.capabilities.files_sharing?.quick_link?.default_role || 'viewer' + const canEdit = store.state.user.capabilities.files_sharing?.public?.can_edit || false + const canContribute = store.state.user.capabilities.files_sharing?.public?.can_contribute || false + const alias = store.state.user.capabilities.files_sharing?.public?.alias let permissions if (!canCreatePublicLink) { - permissions = LinkShareRoles.getByName('none', resource.isFolder).bitmask(allowResharing) + permissions = LinkShareRoles.getByName( + 'none', + resource.isFolder, + canEdit, + canContribute, + alias + ).bitmask(allowResharing) } else { permissions = ( - LinkShareRoles.getByName(capabilitiesRoleName, resource.isFolder) || - LinkShareRoles.getByName('viewer', resource.isFolder) + LinkShareRoles.getByName( + capabilitiesRoleName, + resource.isFolder, + canEdit, + canContribute, + alias + ) || LinkShareRoles.getByName('viewer', resource.isFolder, canEdit, canContribute, alias) ).bitmask(allowResharing) } const params: { [key: string]: unknown } = { diff --git a/packages/web-client/src/helpers/share/role.ts b/packages/web-client/src/helpers/share/role.ts index 8363e1614f2..480ad7215b6 100644 --- a/packages/web-client/src/helpers/share/role.ts +++ b/packages/web-client/src/helpers/share/role.ts @@ -410,8 +410,14 @@ export abstract class LinkShareRoles { }) } - static getByName(name: string, isFolder: boolean): ShareRole { - return LinkShareRoles.list(isFolder, true, true, true).find( + static getByName( + name: string, + isFolder: boolean, + canEditFile: boolean, + canContribute: boolean, + hasAliasLinks: boolean + ): ShareRole { + return LinkShareRoles.list(isFolder, canEditFile, canContribute, hasAliasLinks).find( (role) => role.name.toLowerCase() === name.toLowerCase() ) }