From 1b2d667e466a065f81394f96cf366422c2a06e38 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 13 Feb 2023 11:00:53 +0100 Subject: [PATCH] Fix groups not updated in ui after editing user (#8418) * Fix groups not updated in ui after editing user * update changelog item * return promises instead of awaiting those * Simplify code --- ...-admin-settings-users-role-graph-api-usage | 1 + .../src/views/Users.vue | 38 ++++++++++--------- packages/web-client/src/graph.ts | 8 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/changelog/unreleased/enhancement-admin-settings-users-role-graph-api-usage b/changelog/unreleased/enhancement-admin-settings-users-role-graph-api-usage index 160905509e6..ce958a7c950 100644 --- a/changelog/unreleased/enhancement-admin-settings-users-role-graph-api-usage +++ b/changelog/unreleased/enhancement-admin-settings-users-role-graph-api-usage @@ -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 diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index 3faff4bf91e..d8e66df813d 100644 --- a/packages/web-app-admin-settings/src/views/Users.vue +++ b/packages/web-app-admin-settings/src/views/Users.vue @@ -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, @@ -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) } } }) diff --git a/packages/web-client/src/graph.ts b/packages/web-client/src/graph.ts index 7e187a1ac46..d176d3b3db3 100644 --- a/packages/web-client/src/graph.ts +++ b/packages/web-client/src/graph.ts @@ -161,12 +161,10 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => { new Set([]), new Set(['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) - } } } }