Skip to content

Commit

Permalink
Fix groups not updated in ui after editing user (#8418)
Browse files Browse the repository at this point in the history
* Fix groups not updated in ui after editing user

* update changelog item

* return promises instead of awaiting those

* Simplify code
  • Loading branch information
Jan authored Feb 13, 2023
1 parent 6aa9af4 commit 1b2d667
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Especially for the list view this leads to improved performance.

https://github.com/owncloud/web/pull/8261
https://github.com/owncloud/web/pull/8330
https://github.com/owncloud/web/pull/8418
38 changes: 21 additions & 17 deletions packages/web-app-admin-settings/src/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,7 @@ export default defineComponent({
})
}
},
async updateUserAppRoleAssignments(user, editUser) {
await this.graphClient.users.createUserAppRoleAssignment(user.id, {
appRoleId: editUser.appRoleAssignments[0].appRoleId,
resourceId: editUser.appRoleAssignments[0].resourceId,
principalId: editUser.id
})
},
async updateUserDrive(editUser) {
const updateDriveResponse = await this.graphClient.drives.updateDrive(
editUser.drive.id,
Expand All @@ -391,22 +385,32 @@ export default defineComponent({
})
}
},
async updateUserGroupAssignments(user, editUser) {
const groupsToAdd = editUser.memberOf.filter((editUserGroup) => {
return !user.memberOf.some((g) => g.id === editUserGroup.id)
})
const groupsToDelete = user.memberOf.filter((editUserGroup) => {
return !editUser.memberOf.some((g) => g.id === editUserGroup.id)
updateUserAppRoleAssignments(user, editUser) {
return this.graphClient.users.createUserAppRoleAssignment(user.id, {
appRoleId: editUser.appRoleAssignments[0].appRoleId,
resourceId: editUser.appRoleAssignments[0].resourceId,
principalId: editUser.id
})
},
updateUserGroupAssignments(user, editUser) {
const groupsToAdd = editUser.memberOf.filter(
(editUserGroup) => !user.memberOf.some((g) => g.id === editUserGroup.id)
)
const groupsToDelete = user.memberOf.filter(
(editUserGroup) => !editUser.memberOf.some((g) => g.id === editUserGroup.id)
)
const requests = []
for (const groupToAdd of groupsToAdd) {
await this.graphClient.groups.addMember(groupToAdd.id, user.id, this.configuration.server)
requests.push(
this.graphClient.groups.addMember(groupToAdd.id, user.id, this.configuration.server)
)
}
for (const groupToDelete of groupsToDelete) {
await this.graphClient.groups.deleteMember(groupToDelete.id, user.id)
requests.push(this.graphClient.groups.deleteMember(groupToDelete.id, user.id))
}
return Promise.all(requests)
}
}
})
Expand Down
8 changes: 3 additions & 5 deletions packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,10 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
new Set<any>([]),
new Set<any>(['members'])
),
addMember: (groupId: string, userId: string, server: string) => {
groupApiFactory.addMember(groupId, { '@odata.id': `${server}graph/v1.0/users/${userId}` })
},
deleteMember: (groupId: string, userId: string) => {
addMember: (groupId: string, userId: string, server: string) =>
groupApiFactory.addMember(groupId, { '@odata.id': `${server}graph/v1.0/users/${userId}` }),
deleteMember: (groupId: string, userId: string) =>
groupApiFactory.deleteMember(groupId, userId)
}
}
}
}

0 comments on commit 1b2d667

Please sign in to comment.