Skip to content

Commit

Permalink
Use capabilities in getByName
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Mar 9, 2023
1 parent 3355908 commit 3f6e10f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -54,10 +56,19 @@ export default defineComponent({
const resource = inject<Resource>('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
Expand All @@ -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)
}
Expand Down
20 changes: 17 additions & 3 deletions packages/web-app-files/src/helpers/share/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@ export const createQuicklink = async (args: CreateQuicklink): Promise<Share> =>
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 } = {
Expand Down
10 changes: 8 additions & 2 deletions packages/web-client/src/helpers/share/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down

0 comments on commit 3f6e10f

Please sign in to comment.