Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach share permission to roles #4216

Merged
merged 15 commits into from
Oct 26, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
:selected-role="role"
@roleSelected="selectRole"
/>
<label v-if="$_ocCollaborators_hasAdditionalPermissions" class="oc-label">
<translate>Additional permissions:</translate>
</label>
<additional-permissions
:available-permissions="role.additionalPermissions"
:collaborators-permissions="collaboratorsPermissions"
@permissionChecked="checkAdditionalPermissions"
/>
<template v-if="$_ocCollaborators_hasAdditionalPermissions">
<label v-if="selectedRole.name !== 'advancedRole'" class="oc-label">
<translate>Additional permissions:</translate>
</label>
<additional-permissions
:available-permissions="role.additionalPermissions"
:collaborators-permissions="collaboratorsPermissions"
@permissionChecked="checkAdditionalPermissions"
/>
</template>
<div v-if="expirationSupported">
<label for="files-collaborators-collaborator-expiration-input">
<translate>Expiration date:</translate>
Expand Down Expand Up @@ -106,10 +108,7 @@ export default {
},

$_ocCollaborators_hasAdditionalPermissions() {
if (this.selectedRole && this.selectedRole.name !== 'advancedRole') {
return Object.keys(this.selectedRole.additionalPermissions).length > 0
}
return false
return this.selectedRole && this.selectedRole.additionalPermissions
},

role() {
Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/components/Collaborators/EditCollaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default {
},
computed: {
...mapGetters('Files', ['highlightedFile']),
...mapGetters(['user']),
...mapGetters(['user', 'isOcis']),

collaboratorType() {
const collaboratorShareType = this.collaborator.shareType
Expand Down Expand Up @@ -177,7 +177,7 @@ export default {
client: this.$client,
share: this.collaborator,
// Map bitmask to role to get the correct role in case the advanced role was mapped to existing role
role: bitmaskToRole(bitmask, this.highlightedFile.type === 'folder'),
role: bitmaskToRole(bitmask, this.highlightedFile.type === 'folder', !this.isOcis),
permissions: bitmask,
expirationDate: this.expirationDate
})
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/components/FileSharingSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default {
'currentFileOutgoingSharesLoading',
'sharesTreeLoading'
]),
...mapGetters(['isOcis']),
...mapState('Files', [
'incomingShares',
'incomingSharesLoading',
Expand Down Expand Up @@ -174,7 +175,7 @@ export default {
let role = { name: '' }

if (permissions > 0) {
role = bitmaskToRole(permissions, isFolder)
role = bitmaskToRole(permissions, isFolder, !this.isOcis)
} else {
role.name = 'owner'
}
Expand Down
53 changes: 20 additions & 33 deletions apps/files/src/helpers/collaboratorRolesDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@ function returnOriginal(string) {
* Returns object with collaborator roles
* @param {boolean} isFolder Defines if the item is folder
* @param {function} $gettext Function to translate neccessary strings
* @param {boolean} allowSharePerm Asserts whether share permission is allowed
* @returns {object} Collaborator roles
*/
export default ({ isFolder = false, $gettext = returnOriginal }) => {
export default ({ isFolder = false, $gettext = returnOriginal, allowSharePerm = false }) => {
if (isFolder) {
return {
viewer: {
name: 'viewer',
label: $gettext('Viewer'),
description: $gettext('Download and preview'),
permissions: ['read'],
additionalPermissions: {
share: {
name: 'share',
description: $gettext('Allow re-Sharing')
}
}
description: allowSharePerm
? $gettext('Download, preview and share')
: $gettext('Download and preview'),
permissions: allowSharePerm ? ['read', 'share'] : ['read']
},
editor: {
name: 'editor',
label: $gettext('Editor'),
description: $gettext('Upload, edit, delete, download and preview'),
permissions: ['read', 'update', 'create', 'delete'],
additionalPermissions: {
share: {
name: 'share',
description: $gettext('Allow re-Sharing')
}
}
description: allowSharePerm
? $gettext('Upload, edit, delete, download, preview and share')
: $gettext('Upload, edit, delete, download and preview'),
permissions: allowSharePerm
? ['read', 'update', 'create', 'delete', 'share']
: ['read', 'update', 'create', 'delete']
}
}
}
Expand All @@ -44,26 +39,18 @@ export default ({ isFolder = false, $gettext = returnOriginal }) => {
viewer: {
name: 'viewer',
label: $gettext('Viewer'),
description: $gettext('Download and preview'),
permissions: ['read'],
additionalPermissions: {
share: {
name: 'share',
description: $gettext('Allow re-Sharing')
}
}
description: allowSharePerm
? $gettext('Download, preview and share')
: $gettext('Download and preview'),
permissions: allowSharePerm ? ['read', 'share'] : ['read']
},
editor: {
name: 'editor',
label: $gettext('Editor'),
description: $gettext('Edit, download and preview'),
permissions: ['read', 'update'],
additionalPermissions: {
share: {
name: 'share',
description: $gettext('Allow re-Sharing')
}
}
description: allowSharePerm
? $gettext('Edit, download, preview and share')
: $gettext('Edit, download and preview'),
permissions: allowSharePerm ? ['read', 'update', 'share'] : ['read', 'update']
}
}
}
9 changes: 6 additions & 3 deletions apps/files/src/helpers/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,28 @@ export function roleToBitmask(role, additionalPermissions = []) {

if (additionalPermissions) {
for (const additionalPermission of additionalPermissions) {
if (role.additionalPermissions[additionalPermission]) {
if (role.additionalPermissions && role.additionalPermissions[additionalPermission]) {
bitmask |= permissionsBitmask[additionalPermission]
}
}
}

console.log(bitmask)

return bitmask
}

/**
* Maps bitmask to role
* @param {number} bitmask Permissions which are to be mapped to role
* @param {boolean} isFolder Defines if the item is folder
* @param {boolean} allowSharePerm Asserts if the share permission is allowed
* @returns {object} Role mapped to the bitmask
*/
export function bitmaskToRole(bitmask, isFolder) {
export function bitmaskToRole(bitmask, isFolder, allowSharePerm) {
// TODO: inject the result of "roles()" in the function header and have the caller of bitmaskToRole call roles() with appropriate arguments including translation
// Not passing in translation as we don't need it
const currentRoles = roles({ isFolder: isFolder })
const currentRoles = roles({ isFolder: isFolder, allowSharePerm })
bitmask = parseInt(bitmask, 10)

for (const role in currentRoles) {
Expand Down
19 changes: 13 additions & 6 deletions apps/files/src/mixins/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import roles from '../helpers/collaboratorRolesDefinition'

export default {
computed: {
...mapGetters(['getToken']),
...mapGetters(['getToken', 'user', 'isOcis']),
...mapGetters('Files', ['highlightedFile']),

ownerRole() {
Expand All @@ -27,10 +27,6 @@ export default {
description: this.$gettext('Set detailed permissions'),
permissions: ['read'],
additionalPermissions: {
share: {
name: 'share',
description: this.$gettext('Allow re-Sharing')
},
update: {
name: 'update',
description: this.$gettext('Allow editing')
Expand All @@ -50,13 +46,24 @@ export default {
}
}

if (!this.isOcis) {
advancedRole.additionalPermissions.share = {
name: 'share',
description: this.$gettext('Allow sharing')
}
}

return advancedRole
},

roles() {
const isFolder = this.highlightedFile.type === 'folder'
const $gettext = this.$gettext
const collaboratorRoles = roles({ $gettext, isFolder: isFolder })
const collaboratorRoles = roles({
$gettext,
isFolder: isFolder,
allowSharePerm: !this.isOcis
})
collaboratorRoles.advancedRole = this.advancedRole

return collaboratorRoles
Expand Down
Loading