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:
		| @ -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, | ||||
|                     } | ||||
|                 }); | ||||
|             }} | ||||
|         > | ||||
|  | ||||
| @ -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, | ||||
|                     } | ||||
|                 }); | ||||
|             }} | ||||
|         > | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer