Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix groups not updated in ui after editing user #8418

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
}