Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd8844b

Browse files
committed
fix: only return non-deleted groups
1 parent 539bea7 commit fd8844b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

coderd/workspaces.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,12 +2215,18 @@ func (api *API) workspaceACL(rw http.ResponseWriter, r *http.Request) {
22152215
}
22162216
groupIDs = append(groupIDs, id)
22172217
}
2218-
// For context see https://github.com/coder/coder/pull/19375
2219-
// nolint:gocritic
2220-
dbGroups, err := api.Database.GetGroups(dbauthz.AsSystemRestricted(ctx), database.GetGroupsParams{GroupIds: groupIDs})
2221-
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
2222-
httpapi.InternalServerError(rw, err)
2223-
return
2218+
2219+
// `GetGroups` returns all groups in the org if `GroupIds` is empty so we check
2220+
// the length before making the DB call.
2221+
dbGroups := make([]database.GetGroupsRow, 0)
2222+
if len(groupIDs) > 0 {
2223+
// For context see https://github.com/coder/coder/pull/19375
2224+
// nolint:gocritic
2225+
dbGroups, err = api.Database.GetGroups(dbauthz.AsSystemRestricted(ctx), database.GetGroupsParams{GroupIds: groupIDs})
2226+
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
2227+
httpapi.InternalServerError(rw, err)
2228+
return
2229+
}
22242230
}
22252231

22262232
groups := make([]codersdk.WorkspaceGroup, 0, len(dbGroups))

0 commit comments

Comments
 (0)