From f345f2c7164359d8a2639a818e03ad95d0245115 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 13 Feb 2023 10:12:16 +0100 Subject: [PATCH 1/4] Fix groups not updated in ui after editing user --- packages/web-app-admin-settings/src/views/Users.vue | 10 ++++++++-- packages/web-client/src/graph.ts | 8 +++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index 3faff4bf91e..2b88be928bb 100644 --- a/packages/web-app-admin-settings/src/views/Users.vue +++ b/packages/web-app-admin-settings/src/views/Users.vue @@ -400,13 +400,19 @@ export default defineComponent({ return !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)) } + + await 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) - } } } } From cf29e56ce508b5cd6d41e0f57bedb0d2ac820a4d Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 13 Feb 2023 10:16:57 +0100 Subject: [PATCH 2/4] update changelog item --- .../enhancement-admin-settings-users-role-graph-api-usage | 1 + 1 file changed, 1 insertion(+) 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 From 470ab9686978c622fffb7de5646eb4fa2a7b2bb5 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 13 Feb 2023 10:25:53 +0100 Subject: [PATCH 3/4] return promises instead of awaiting those --- .../src/views/Users.vue | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index 2b88be928bb..5ddc6c34bbb 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,7 +385,14 @@ export default defineComponent({ }) } }, - async updateUserGroupAssignments(user, editUser) { + 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) => { return !user.memberOf.some((g) => g.id === editUserGroup.id) }) @@ -412,7 +413,7 @@ export default defineComponent({ requests.push(this.graphClient.groups.deleteMember(groupToDelete.id, user.id)) } - await Promise.all(requests) + return Promise.all(requests) } } }) From 96d5cb2f2f00ca0dc8ffc8bf9f445aaf85af56f3 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 13 Feb 2023 10:28:13 +0100 Subject: [PATCH 4/4] Simplify code --- .../web-app-admin-settings/src/views/Users.vue | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index 5ddc6c34bbb..d8e66df813d 100644 --- a/packages/web-app-admin-settings/src/views/Users.vue +++ b/packages/web-app-admin-settings/src/views/Users.vue @@ -393,14 +393,12 @@ export default defineComponent({ }) }, 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) - }) - + 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) { @@ -408,7 +406,6 @@ export default defineComponent({ this.graphClient.groups.addMember(groupToAdd.id, user.id, this.configuration.server) ) } - for (const groupToDelete of groupsToDelete) { requests.push(this.graphClient.groups.deleteMember(groupToDelete.id, user.id)) }