Skip to content

Commit

Permalink
Re-use space role names for the space role object
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 7, 2022
1 parent a7c1bcf commit 2b3041d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
30 changes: 12 additions & 18 deletions packages/web-app-files/src/helpers/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SharePermissions,
ShareStatus,
ShareTypes,
SpacePeopleShareRoles,
spaceRoleEditor,
spaceRoleManager,
spaceRoleViewer
Expand Down Expand Up @@ -112,10 +113,11 @@ export function buildResource(resource) {

export function buildSpace(space) {
let spaceImageData, spaceReadmeData
let spaceViewers = []
let spaceEditors = []
let spaceManagers = []
let disabled = false
const spaceRoles = SpacePeopleShareRoles.list().reduce((obj, role) => {
obj[role.name] = []
return obj
}, {})

if (space.special) {
spaceImageData = space.special.find((el) => el.specialFolder.name === 'image')
Expand All @@ -124,16 +126,12 @@ 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))
}

if (permission.roles.includes(spaceRoleEditor.name)) {
spaceEditors = spaceEditors.concat(permission.grantedTo.map((el) => el.user.id))
}

if (permission.roles.includes(spaceRoleManager.name)) {
spaceManagers = spaceManagers.concat(permission.grantedTo.map((el) => el.user.id))
for (const role of SpacePeopleShareRoles.list()) {
if (permission.roles.includes(role.name)) {
spaceRoles[role.name] = spaceRoles[role.name].concat(
permission.grantedTo.map((el) => el.user.id)
)
}
}
}

Expand Down Expand Up @@ -169,11 +167,7 @@ export function buildSpace(space) {
ownerId: '',
disabled,
spaceQuota: space.quota,
spaceRoles: {
viewers: spaceViewers,
editors: spaceEditors,
managers: spaceManagers
},
spaceRoles,
spaceImageData,
spaceReadmeData,
canUpload: function () {
Expand Down
26 changes: 3 additions & 23 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/tests/unit/store/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('vuex store actions', () => {

await actions.deleteShare(stateMock, {
client: clientMock,
graphClient: graphClientMock,
share: dataSet.share,
resource: {}
})
Expand Down

0 comments on commit 2b3041d

Please sign in to comment.