mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-25 22:08:46 +00:00
feat(group): manage users in user groups (#10940)
# Which Problems Are Solved 1. Adding users to user groups and removing users from user groups. 2. Searching for users in user groups by group IDs or user IDs # How the Problems Are Solved By adding: 1. The API definitions to manage users in users groups 3. The command-layer implementation of adding users/removing users to/from user groups. 4. The projection table group_users1 5. Query-side implementation to search for users in user groups # Additional Changes 1. Remove debug statements from unit tests. 2. Fix removal of groups when orgs are removed 3. Add unit tests for groups projection # Additional Context * Related to #9702 * Follow-up for PRs * https://github.com/zitadel/zitadel/pull/10455 * https://github.com/zitadel/zitadel/pull/10758 * https://github.com/zitadel/zitadel/pull/10853
This commit is contained in:
@@ -200,11 +200,11 @@ func (h *UsersHandler) Update(ctx context.Context, id string, operations patch.O
|
||||
}
|
||||
|
||||
func (h *UsersHandler) Delete(ctx context.Context, id string) error {
|
||||
memberships, grants, err := h.queryUserDependencies(ctx, id)
|
||||
memberships, grants, groupIDs, err := h.queryUserDependencies(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = h.command.RemoveUserV2(ctx, id, authz.GetCtxData(ctx).OrgID, memberships, grants...)
|
||||
_, err = h.command.RemoveUserV2(ctx, id, authz.GetCtxData(ctx).OrgID, memberships, grants, groupIDs)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -254,22 +254,22 @@ func (h *UsersHandler) List(ctx context.Context, request *ListRequest) (*ListRes
|
||||
return NewListResponse(users.SearchResponse.Count, q.SearchRequest, scimUsers), nil
|
||||
}
|
||||
|
||||
func (h *UsersHandler) queryUserDependencies(ctx context.Context, userID string) ([]*command.CascadingMembership, []string, error) {
|
||||
func (h *UsersHandler) queryUserDependencies(ctx context.Context, userID string) ([]*command.CascadingMembership, []string, []string, error) {
|
||||
userGrantUserQuery, err := query.NewUserGrantUserIDSearchQuery(userID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
grants, err := h.query.UserGrants(ctx, &query.UserGrantsQueries{
|
||||
Queries: []query.SearchQuery{userGrantUserQuery},
|
||||
}, true, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
membershipsUserQuery, err := query.NewMembershipUserIDQuery(userID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
memberships, err := h.query.Memberships(ctx, &query.MembershipSearchQuery{
|
||||
@@ -277,7 +277,35 @@ func (h *UsersHandler) queryUserDependencies(ctx context.Context, userID string)
|
||||
}, false)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return cascadingMemberships(memberships.Memberships), userGrantsToIDs(grants.UserGrants), nil
|
||||
groupIDs, err := h.getGroupsByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return cascadingMemberships(memberships.Memberships), userGrantsToIDs(grants.UserGrants), groupIDs, nil
|
||||
}
|
||||
|
||||
func (h *UsersHandler) getGroupsByUserID(ctx context.Context, userID string) ([]string, error) {
|
||||
groupUserQuery, err := query.NewGroupUsersUserIDsSearchQuery([]string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupUsers, err := h.query.SearchGroupUsers(ctx,
|
||||
&query.GroupUsersSearchQuery{
|
||||
Queries: []query.SearchQuery{
|
||||
groupUserQuery,
|
||||
},
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupUsers.GroupUsers) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
groupIDs := make([]string, 0, len(groupUsers.GroupUsers))
|
||||
for _, groupUser := range groupUsers.GroupUsers {
|
||||
groupIDs = append(groupIDs, groupUser.GroupID)
|
||||
}
|
||||
return groupIDs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user