Skip to content

Commit 163631e

Browse files
authored
chore: use system context for fetching template information (coder#15205)
The authz check is Update() on the original template. This is not ideal, but it follows the existing behavior. We are implicitly granting this read access since template admins need to be able to see what users/groups exist to assign.
1 parent fed70bd commit 163631e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

enterprise/coderd/templates.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ func (api *API) templateAvailablePermissions(rw http.ResponseWriter, r *http.Req
6666
httpapi.InternalServerError(rw, err)
6767
return
6868
}
69-
memberCount, err := api.Database.GetGroupMembersCountByGroupID(ctx, group.Group.ID)
69+
70+
// nolint:gocritic
71+
memberCount, err := api.Database.GetGroupMembersCountByGroupID(dbauthz.AsSystemRestricted(ctx), group.Group.ID)
7072
if err != nil {
7173
httpapi.InternalServerError(rw, err)
7274
return

enterprise/coderd/templates_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,10 @@ func TestUpdateTemplateACL(t *testing.T) {
14941494
},
14951495
}
14961496

1497+
// Group adds complexity to the /available endpoint
1498+
// Intentionally omit user2
1499+
coderdtest.CreateGroup(t, client, user.OrganizationID, "some-group", user3)
1500+
14971501
ctx := testutil.Context(t, testutil.WaitLong)
14981502

14991503
err := client1.UpdateTemplateACL(ctx, template.ID, req)

0 commit comments

Comments
 (0)