core: add endpoints to add/remove users from group atomically

closes #4252

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2022-12-28 10:50:30 +01:00
parent 78f7eb4345
commit b16d1134ea
6 changed files with 233 additions and 19 deletions

View File

@ -52,17 +52,15 @@ export class RelatedGroupList extends Table<Group> {
return html`<ak-forms-delete-bulk
objectLabel=${t`Group(s)`}
actionLabel=${t`Remove from Group(s)`}
actionSubtext=${t`Are you sure you want to remove users ${this.targetUser?.username} from the following groups?`}
actionSubtext=${t`Are you sure you want to remove user ${this.targetUser?.username} from the following groups?`}
.objects=${this.selectedElements}
.delete=${(item: Group) => {
const newGroups = this.targetUser?.groups.filter((group) => {
return group != item.pk;
});
return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({
id: this.targetUser?.pk || 0,
patchedUserRequest: {
groups: newGroups,
},
if (!this.targetUser) return;
return new CoreApi(DEFAULT_CONFIG).coreGroupsRemoveUserCreate({
groupUuid: item.pk,
userAccountRequest: {
pk: this.targetUser?.pk || 0,
}
});
}}
>

View File

@ -88,16 +88,11 @@ export class RelatedUserList extends Table<User> {
];
}}
.delete=${(item: User) => {
const newUsers = this.targetGroup?.usersObj
.filter((user) => {
return user.pk != item.pk;
})
.map((user) => user.pk);
return new CoreApi(DEFAULT_CONFIG).coreGroupsPartialUpdate({
return new CoreApi(DEFAULT_CONFIG).coreGroupsRemoveUserCreate({
groupUuid: this.targetGroup?.pk || "",
patchedGroupRequest: {
users: newUsers,
},
userAccountRequest: {
pk: item.pk,
}
});
}}
>