diff --git a/packages/web-app-files/src/helpers/resources.js b/packages/web-app-files/src/helpers/resources.js index 3fcc1e58604..c8b219a1086 100644 --- a/packages/web-app-files/src/helpers/resources.js +++ b/packages/web-app-files/src/helpers/resources.js @@ -9,6 +9,7 @@ import { SharePermissions, ShareStatus, ShareTypes, + SpacePeopleShareRoles, spaceRoleEditor, spaceRoleManager, spaceRoleViewer @@ -112,11 +113,13 @@ export function buildResource(resource) { export function buildSpace(space) { let spaceImageData, spaceReadmeData - let spaceViewers = [] - let spaceEditors = [] - let spaceManagers = [] let disabled = false + const spaceRoles = {} + for (const role of SpacePeopleShareRoles.list()) { + spaceRoles[role.name] = [] + } + if (space.special) { spaceImageData = space.special.find((el) => el.specialFolder.name === 'image') spaceReadmeData = space.special.find((el) => el.specialFolder.name === 'readme') @@ -125,15 +128,21 @@ export function buildSpace(space) { if (space.root) { for (const permission of space.root.permissions) { if (permission.roles.includes(spaceRoleViewer.name)) { - spaceViewers = spaceViewers.concat(permission.grantedTo.map((el) => el.user.id)) + spaceRoles[spaceRoleViewer.name] = spaceRoles[spaceRoleViewer.name].concat( + permission.grantedTo.map((el) => el.user.id) + ) } if (permission.roles.includes(spaceRoleEditor.name)) { - spaceEditors = spaceEditors.concat(permission.grantedTo.map((el) => el.user.id)) + spaceRoles[spaceRoleEditor.name] = spaceRoles[spaceRoleEditor.name].concat( + permission.grantedTo.map((el) => el.user.id) + ) } if (permission.roles.includes(spaceRoleManager.name)) { - spaceManagers = spaceManagers.concat(permission.grantedTo.map((el) => el.user.id)) + spaceRoles[spaceRoleManager.name] = spaceRoles[spaceRoleViewer.name].concat( + permission.grantedTo.map((el) => el.user.id) + ) } } @@ -169,11 +178,7 @@ export function buildSpace(space) { ownerId: '', disabled, spaceQuota: space.quota, - spaceRoles: { - viewers: spaceViewers, - editors: spaceEditors, - managers: spaceManagers - }, + spaceRoles, spaceImageData, spaceReadmeData, canUpload: function () { diff --git a/packages/web-app-files/src/store/actions.js b/packages/web-app-files/src/store/actions.js index ba184718a90..8887d5d1809 100644 --- a/packages/web-app-files/src/store/actions.js +++ b/packages/web-app-files/src/store/actions.js @@ -13,13 +13,7 @@ import { $gettext, $gettextInterpolate } from '../gettext' import { loadPreview } from '../helpers/resource' import { avatarUrl } from '../helpers/user' import { has } from 'lodash-es' -import { - ShareTypes, - SpacePeopleShareRoles, - spaceRoleEditor, - spaceRoleManager, - spaceRoleViewer -} from '../helpers/share' +import { ShareTypes, SpacePeopleShareRoles } from '../helpers/share' export default { updateFileProgress({ commit }, progress) { @@ -164,23 +158,9 @@ export default { if (space) { const promises = [] const spaceShares = [] - const userRoles = [ - { - role: spaceRoleViewer.name, - userIds: space.spaceRoles.viewers - }, - { - role: spaceRoleEditor.name, - userIds: space.spaceRoles.editors - }, - { - role: spaceRoleManager.name, - userIds: space.spaceRoles.managers - } - ] - for (const { role, userIds } of userRoles) { - for (const userId of userIds) { + for (const role of Object.keys(space.spaceRoles)) { + for (const userId of space.spaceRoles[role]) { promises.push( client.users.getUser(userId).then((resolved) => { spaceShares.push( diff --git a/packages/web-app-files/tests/unit/store/actions.spec.js b/packages/web-app-files/tests/unit/store/actions.spec.js index d892ab7a45b..ad005137b1d 100644 --- a/packages/web-app-files/tests/unit/store/actions.spec.js +++ b/packages/web-app-files/tests/unit/store/actions.spec.js @@ -141,6 +141,7 @@ describe('vuex store actions', () => { await actions.deleteShare(stateMock, { client: clientMock, + graphClient: graphClientMock, share: dataSet.share, resource: {} })