Skip to content

Commit

Permalink
Adjusted tests
Browse files Browse the repository at this point in the history
Add permissions only if they exist for the role
  • Loading branch information
LukasHirt committed Nov 19, 2019
1 parent e20b6d3 commit 1fc797a
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 189 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<oc-grid gutter="small">
<label v-for="permission in permissions" :key="permission.name">
<label v-for="permission in permissions" :key="permission.name" class="files-collaborators-permission-label">
<oc-checkbox
class="uk-margin-xsmall-right"
:id="`files-collaborators-permission-${permission.name}`"
class="uk-margin-xsmall-right files-collaborators-permission-checkbox"
v-model="permission.value"
@change="permissionChecked"
/>
Expand Down
34 changes: 29 additions & 5 deletions apps/files/src/components/Collaborators/Collaborator.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<oc-accordion-item class="files-collaborators-collaborator uk-margin-small-bottom" :class="{ 'oc-disabled uk-disabled' : collaboratorsEditInProgress && !editing }">
<oc-accordion-item
class="files-collaborators-collaborator uk-margin-small-bottom"
:class="{ 'oc-disabled uk-disabled' : collaboratorsEditInProgress && !editing }"
:key="collaborator.id"
>
<template slot="title">
<div v-if="user.id !== collaborator.info.uid_owner" class="uk-text-meta uk-flex uk-flex-middle uk-margin-small-bottom"><oc-icon name="repeat" class="uk-margin-small-right" /> {{ collaborator.info.displayname_owner }}</div>
<div class="files-collaborators-collaborator-information uk-flex uk-flex-wrap uk-flex-middle">
Expand All @@ -26,7 +30,7 @@
<template slot="content">
<collaborators-edit-options
:existingRole="collaborator.role"
:collaboratorsPermissions="collaborator.customPermissions"
:collaboratorsPermissions="collaboratorsPermissions"
@optionChange="collaboratorOptionChanged"
class="uk-margin-bottom"
/>
Expand All @@ -47,7 +51,8 @@
<script>
import { mapGetters, mapActions } from 'vuex'
import Mixins from '../../mixins/collaborators'
import { roleToBitmask } from '../../helpers/collaborators'
import { roleToBitmask, bitmaskToRole } from '../../helpers/collaborators'
import filterObject from 'filter-obj'
const CollaboratorsEditOptions = () => import('./CollaboratorsEditOptions.vue')
Expand Down Expand Up @@ -88,6 +93,12 @@ export default {
}
return this.roles[this.collaborator.role.name]
},
collaboratorsPermissions () {
const permissions = this.collaborator.customPermissions
return filterObject(permissions, (key, value) => value)
}
},
mounted () {
Expand All @@ -106,11 +117,24 @@ export default {
},
saveChanges (collaborator) {
if (!this.selectedRole) this.selectedRole = this.roles[collaborator.role.name]
let permissions = this.additionalPermissions
if (!permissions) {
permissions = []
for (const permission in this.collaboratorsPermissions) {
permissions.push(permission)
}
}
const bitmask = roleToBitmask(this.selectedRole, permissions, this.highlightedFile.type === 'folder')
this.changeShare({
client: this.$client,
share: collaborator,
role: this.selectedRole,
permissions: roleToBitmask(this.selectedRole, this.additionalPermissions, this.highlightedFile.type === 'folder')
// TODO: After changing to tabs view, this can be dropped
// 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'),
permissions: bitmask
})
.then(() => {
this.editing = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
if (
(
this.existingRole && this.existingRole.name === 'advancedRole'
this.existingRole && this.existingRole.name === 'advancedRole' && !this.selectedRole
) || (
this.selectedRole && this.selectedRole.name === 'advancedRole'
)
Expand Down
6 changes: 4 additions & 2 deletions apps/files/src/helpers/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function roleToBitmask (role, additionalPermissions = []) {

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

Expand Down Expand Up @@ -64,7 +66,7 @@ export function bitmaskToRole (bitmask, isFolder) {
rolePermissionsBitmask |= permissionsBitmask[additionalPermissions[additionalPermission].name]
}

// TODO: Use bitmask
// TODO: Use bitmask to cover cases of more then one additional permission
if (
rolePermissionsBitmask === bitmask ||
roleBasicPermissionsBitmask === bitmask
Expand Down
10 changes: 5 additions & 5 deletions apps/files/src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment'
import { bitmaskToRole } from '../helpers/collaborators'
import { bitmaskToRole, permissionsBitmask } from '../helpers/collaborators'

function _buildFile (file) {
let ext = ''
Expand Down Expand Up @@ -223,10 +223,10 @@ function _buildShare (s, file) {
share.displayName = s.share_with_displayname
// TODO: Refactor to work with roles / prepare for roles API
share.customPermissions = {
update: s.permissions === '3' || s.permissions === '15' || s.permissions === '19' || s.permissions === '31',
create: s.permissions === '5' || s.permissions === '15' || s.permissions === '21' || s.permissions === '31',
delete: s.permissions === '9' || s.permissions === '15' || s.permissions === '25' || s.permissions === '31',
share: s.permissions === '17' || s.permissions === '19' || s.permissions === '21' || s.permissions === '25' || s.permissions === '31'
update: s.permissions & permissionsBitmask.update,
create: s.permissions & permissionsBitmask.create,
delete: s.permissions & permissionsBitmask.delete,
share: s.permissions & permissionsBitmask.share
}
// share.email = '[email protected]' // hm, where do we get the mail from? share_with_additional_info:Object?
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Feature: deleting files and folders
Then file "lorem.txt" should not be listed on the webUI

Scenario: delete a file on a public share
Given user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions
Given user "user1" has shared folder "simple-folder" with link with "read, update, create, delete" permissions
When the public uses the webUI to access the last public link created by user "user1"
And the user deletes the following elements using the webUI
| name |
Expand All @@ -176,7 +176,7 @@ Feature: deleting files and folders
| | "double" quotes |
| | question? |
| | &and#hash |
And user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions
And user "user1" has shared folder "simple-folder" with link with "read, update, create, delete" permissions
When the public uses the webUI to access the last public link created by user "user1"
And the user deletes the following file using the webUI
| name-parts |
Expand All @@ -200,7 +200,7 @@ Feature: deleting files and folders

@skip @yetToImplement
Scenario: Delete multiple files at once on a public share
Given user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions
Given user "user1" has shared folder "simple-folder" with link with "read, update, create, delete" permissions
When the public uses the webUI to access the last public link created by user "user1"
And the user batch deletes these files using the webUI
| name |
Expand Down
34 changes: 17 additions & 17 deletions tests/acceptance/features/webUIResharing/reshareUsers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ Feature: Resharing shared files with different permissions
| item_type | folder |
| permissions | <permissions> |
Examples:
| role | displayed-role | collaborators-permissions | displayed-permissions | permissions |
| Viewer | Viewer | share | share | read, share |
| Editor | Editor | share | share | all |
| Custom Role | Custom role | share, create | share, create | read, share, create |
| Custom Role | Editor | change, share | share | read, change, share |
| Custom Role | Editor | delete, share, create, change | share | read, share, delete, change, create |
| role | displayed-role | collaborators-permissions | displayed-permissions | permissions |
| Viewer | Viewer | share | share | read, share |
| Editor | Editor | share | share | all |
| Advanced permissions | Advanced permissions | share, create | share, create | read, share, create |
| Advanced permissions | Editor | update, share | share | read, update, share |
| Advanced permissions | Editor | delete, share, create, update | share | read, share, delete, update, create |

Scenario Outline: share a received folder with another user with same permissions(including share permissions) and check if the user is displayed in collaborators list for original owner
Given user "user2" has shared folder "simple-folder" with user "user1" with "<permissions>" permissions
Expand All @@ -77,12 +77,12 @@ Feature: Resharing shared files with different permissions
| item_type | folder |
| permissions | <permissions> |
Examples:
| role | displayed-role | collaborators-permissions | displayed-permissions | permissions |
| Viewer | Viewer | share | share | read, share |
| Editor | Editor | share | share | all |
| Custom Role | Custom role | share, create | share, create | read, share, create |
| Custom Role | Editor | change, share | share | read, change, share |
| Custom Role | Editor | delete, share, create, change | share | read, share, delete, change, create |
| role | displayed-role | collaborators-permissions | displayed-permissions | permissions |
| Viewer | Viewer | share | share | read, share |
| Editor | Editor | share | share | all |
| Advanced permissions | Advanced permissions | share, create | share, create | read, share, create |
| Advanced permissions | Editor | update, share | share | read, update, share |
| Advanced permissions | Editor | delete, share, create, update | share | read, share, delete, update, create |

Scenario: share a folder with another user with share permissions and reshare without share permissions to different user, and check if user is displayed for original sharer
Given user "user2" has shared folder "simple-folder" with user "user1" with "read, share" permissions
Expand Down Expand Up @@ -144,7 +144,7 @@ Feature: Resharing shared files with different permissions
Scenario: User is allowed to reshare a file/folder with the equivalent received permissions, and collaborators should not be listed for the receiver
Given user "user2" has shared folder "simple-folder" with user "user1" with "read, share, delete" permissions
And user "user1" has logged in using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Custom role" with permissions "share, delete" using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Advanced permissions" with permissions "share, delete" using the webUI
And the user re-logs in as "user3" using the webUI
Then the collaborators list for folder "simple-folder (2)" should be empty
And user "user3" should have received a share with these details:
Expand All @@ -158,11 +158,11 @@ Feature: Resharing shared files with different permissions
Scenario: User is allowed to reshare a file/folder with the lesser permissions, and check if it is listed for original owner
Given user "user2" has shared folder "simple-folder" with user "user1" with "read, share, delete" permissions
And user "user1" has logged in using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Custom role" with permissions "delete" using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Advanced permissions" with permissions "delete" using the webUI
And the user re-logs in as "user2" using the webUI
Then user "User One" should be listed as "Custom role" in the collaborators list for folder "simple-folder" on the webUI
Then user "User One" should be listed as "Advanced permissions" in the collaborators list for folder "simple-folder" on the webUI
And custom permissions "share, delete" should be set for user "User One" for folder "simple-folder" on the webUI
And user "User Three" should be listed as "Custom role" in the collaborators list for folder "simple-folder" on the webUI
And user "User Three" should be listed as "Advanced permissions" in the collaborators list for folder "simple-folder" on the webUI
And custom permissions "delete" should be set for user "User Three" for folder "simple-folder" on the webUI
And user "user3" should have received a share with these details:
| field | value |
Expand All @@ -175,7 +175,7 @@ Feature: Resharing shared files with different permissions
Scenario: User is not allowed to reshare a file/folder with the higher permissions
Given user "user2" has shared folder "simple-folder" with user "user1" with "read, share, delete" permissions
And user "user1" has logged in using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Custom role" with permissions "share, delete, change" using the webUI
When the user shares folder "simple-folder (2)" with user "User Three" as "Advanced permissions" with permissions "share, delete, update" using the webUI
Then the error message "Error while sharing." should be displayed on the webUI
And as "user3" folder "simple-folder (2)" should not exist

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Feature: Sharing files and folders with internal groups
# And folder "simple-folder (2)" should be marked as shared by "User Two" on the webUI
# And file "testimage (2).jpg" should be marked as shared by "User Two" on the webUI
Examples:
| set-role | expected-role | permissions-folder | permissions-file |
| Viewer | Viewer | read | read |
| Editor | Editor | read,change,create, delete | read,change |
| Custom Role | Viewer | read | read |
| set-role | expected-role | permissions-folder | permissions-file |
| Viewer | Viewer | read | read |
| Editor | Editor | read,update,create, delete | read,update |
| Advanced permissions | Viewer | read | read |

@skip @yetToImplement
Scenario: share a file with an internal group a member overwrites and unshares the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Feature: Sharing files and folders with internal users
# And folder "simple-folder (2)" should be marked as shared by "User Two" on the webUI
# And file "testimage (2).jpg" should be marked as shared by "User Two" on the webUI
Examples:
| set-role | expected-role | permissions-folder | permissions-file |
| Viewer | Viewer | read | read |
| Editor | Editor | read,change,create,delete | read,change |
| Custom Role | Viewer | read | read |
| set-role | expected-role | permissions-folder | permissions-file |
| Viewer | Viewer | read | read |
| Editor | Editor | read,update,create,delete | read,update |
| Advanced permissions | Viewer | read | read |

Scenario Outline: change the collaborators of a file & folder
Given user "user2" has logged in using the webUI
Expand All @@ -66,11 +66,11 @@ Feature: Sharing files and folders with internal users
| item_type | folder |
| permissions | <expected-permissions> |
Examples:
| initial-permissions | set-role | expected-role | expected-permissions |
| read,change,create | Viewer | Viewer | read |
| read | Editor | Editor | read,change,create,delete |
| read | Custom role | Viewer | read |
| all | Custom role | Editor | all |
| initial-permissions | set-role | expected-role | expected-permissions |
| read,update,create | Viewer | Viewer | read |
| read | Editor | Editor | read,update,create,delete |
| read | Advanced permissions | Viewer | read |
| all | Advanced permissions | Editor | all |

Scenario: share a file with another internal user who overwrites and unshares the file
Given user "user2" has logged in using the webUI
Expand Down
Loading

0 comments on commit 1fc797a

Please sign in to comment.