Skip to content

Commit

Permalink
Make Contributor role optional
Browse files Browse the repository at this point in the history
  • Loading branch information
diocas committed Feb 8, 2023
1 parent 6f8ea9d commit 041b2af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import {
useCapabilityShareJailEnabled,
useCapabilityFilesSharingResharing,
useCapabilityFilesSharingPublicCanEdit,
useCapabilityFilesSharingPublicCanContribute,
useCapabilityFilesSharingPublicAlias
} from 'web-pkg/src/composables'
import { shareViaLinkHelp, shareViaIndirectLinkHelp } from '../../../helpers/contextualHelpers'
Expand Down Expand Up @@ -153,6 +154,7 @@ export default defineComponent({
hasShareJail: useCapabilityShareJailEnabled(),
hasResharing: useCapabilityFilesSharingResharing(),
hasPublicLinkEditing: useCapabilityFilesSharingPublicCanEdit(),
hasPublicLinkContribute: useCapabilityFilesSharingPublicCanContribute(),
hasPublicLinkAliasSupport: useCapabilityFilesSharingPublicAlias(),
indirectLinkListCollapsed,
linkListCollapsed
Expand Down Expand Up @@ -561,6 +563,7 @@ export default defineComponent({
this.incomingParentShare.permissions,
this.resource.isFolder,
this.hasPublicLinkEditing,
this.hasPublicLinkContribute,
this.hasPublicLinkAliasSupport,
!!link.password
)
Expand All @@ -569,6 +572,7 @@ export default defineComponent({
return LinkShareRoles.list(
this.resource.isFolder,
this.hasPublicLinkEditing,
this.hasPublicLinkContribute,
this.hasPublicLinkAliasSupport,
!!link.password
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { mockDeep } from 'jest-mock-extended'
import { Resource } from 'web-client'

const availableRoleOptions = LinkShareRoles.list(false, true, true)
const availableRoleOptions = LinkShareRoles.list(false, true, true, true)

const exampleLink = {
name: 'Example link',
Expand Down
18 changes: 14 additions & 4 deletions packages/web-client/src/helpers/share/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,33 @@ export abstract class LinkShareRoles {
static readonly all = [
linkRoleViewerFile,
linkRoleViewerFolder,
linkRoleContributorFolder,
linkRoleEditorFolder,
linkRoleUploaderFolder
]

static list(
isFolder: boolean,
canEditFile = false,
canContribute = false,
hasAliasLinks = false,
hasPassword = false
): ShareRole[] {
return [
...(hasAliasLinks && !hasPassword ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...this.all,
...(canEditFile ? [linkRoleEditorFile] : [])
...(canEditFile ? [linkRoleEditorFile] : []),
...(canContribute ? [linkRoleContributorFolder] : [])
].filter((r) => r.folder === isFolder)
}

static getByBitmask(bitmask: number, isFolder: boolean): ShareRole {
return [...this.all, linkRoleEditorFile, linkRoleInternalFile, linkRoleInternalFolder] // Always return all roles
return [
...this.all,
linkRoleEditorFile,
linkRoleContributorFolder,
linkRoleInternalFile,
linkRoleInternalFolder
] // Always return all roles
.find((r) => r.folder === isFolder && r.bitmask(false) === bitmask)
}

Expand All @@ -387,20 +394,23 @@ export abstract class LinkShareRoles {
* @param bitmask
* @param isFolder
* @param canEditFile
* @param canContribute
* @param hasAliasLinks
* @param hasPassword
*/
static filterByBitmask(
bitmask: number,
isFolder: boolean,
canEditFile = false,
canContribute = false,
hasAliasLinks = false,
hasPassword = false
): ShareRole[] {
return [
...(hasAliasLinks && !hasPassword ? [linkRoleInternalFile, linkRoleInternalFolder] : []),
...this.all,
...(canEditFile ? [linkRoleEditorFile] : [])
...(canEditFile ? [linkRoleEditorFile] : []),
...(canContribute ? [linkRoleContributorFolder] : [])
].filter((r) => {
return r.folder === isFolder && bitmask === (bitmask | r.bitmask(false))
})
Expand Down
4 changes: 4 additions & 0 deletions packages/web-pkg/src/composables/capability/useCapability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const useCapabilityFilesSharingPublicCanEdit = createCapabilityComposable
'files_sharing.public.can_edit',
false
)
export const useCapabilityFilesSharingPublicCanContribute = createCapabilityComposable(
'files_sharing.public.can_contribute',
true
)
export const useCapabilityFilesSharingPublicAlias = createCapabilityComposable(
'files_sharing.public.alias',
false
Expand Down

0 comments on commit 041b2af

Please sign in to comment.