mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add group_ids filter to /groups endpoint (#14688)
Allow filtering groups by IDs.
This commit is contained in:
@@ -2714,6 +2714,12 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
|
||||
orgDetailsCache := make(map[uuid.UUID]struct{ name, displayName string })
|
||||
filtered := make([]database.GetGroupsRow, 0)
|
||||
for _, group := range q.groups {
|
||||
if len(arg.GroupIds) > 0 {
|
||||
if !slices.Contains(arg.GroupIds, group.ID) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if arg.OrganizationID != uuid.Nil && group.OrganizationID != arg.OrganizationID {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1683,12 +1683,17 @@ WHERE
|
||||
groups.name = ANY($3)
|
||||
ELSE true
|
||||
END
|
||||
AND CASE WHEN array_length($4 :: uuid[], 1) > 0 THEN
|
||||
groups.id = ANY($4)
|
||||
ELSE true
|
||||
END
|
||||
`
|
||||
|
||||
type GetGroupsParams struct {
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
HasMemberID uuid.UUID `db:"has_member_id" json:"has_member_id"`
|
||||
GroupNames []string `db:"group_names" json:"group_names"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
HasMemberID uuid.UUID `db:"has_member_id" json:"has_member_id"`
|
||||
GroupNames []string `db:"group_names" json:"group_names"`
|
||||
GroupIds []uuid.UUID `db:"group_ids" json:"group_ids"`
|
||||
}
|
||||
|
||||
type GetGroupsRow struct {
|
||||
@@ -1698,7 +1703,12 @@ type GetGroupsRow struct {
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetGroups(ctx context.Context, arg GetGroupsParams) ([]GetGroupsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getGroups, arg.OrganizationID, arg.HasMemberID, pq.Array(arg.GroupNames))
|
||||
rows, err := q.db.QueryContext(ctx, getGroups,
|
||||
arg.OrganizationID,
|
||||
arg.HasMemberID,
|
||||
pq.Array(arg.GroupNames),
|
||||
pq.Array(arg.GroupIds),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ WHERE
|
||||
groups.name = ANY(@group_names)
|
||||
ELSE true
|
||||
END
|
||||
AND CASE WHEN array_length(@group_ids :: uuid[], 1) > 0 THEN
|
||||
groups.id = ANY(@group_ids)
|
||||
ELSE true
|
||||
END
|
||||
;
|
||||
|
||||
-- name: InsertGroup :one
|
||||
|
||||
Reference in New Issue
Block a user