Skip to content

Commit d48e08e

Browse files
committed
fix(enterprise/coderd): skip org membership check for prebuilds user on group patch
1 parent 49fcffc commit d48e08e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

enterprise/coderd/groups.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/coder/coder/v2/coderd/database/db2sdk"
1515
"github.com/coder/coder/v2/coderd/httpapi"
1616
"github.com/coder/coder/v2/coderd/httpmw"
17+
"github.com/coder/coder/v2/coderd/prebuilds"
1718
"github.com/coder/coder/v2/codersdk"
1819
)
1920

@@ -171,6 +172,12 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
171172
})
172173
return
173174
}
175+
// Skip membership checks for the prebuilds user. There is a valid use case
176+
// for adding the prebuilds user to a single group: in order to set a quota
177+
// allowance specifically for prebuilds.
178+
if id == prebuilds.SystemUserID.String() {
179+
continue
180+
}
174181
_, err := database.ExpectOne(api.Database.OrganizationMembers(ctx, database.OrganizationMembersParams{
175182
OrganizationID: group.OrganizationID,
176183
UserID: uuid.MustParse(id),

enterprise/coderd/groups_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,32 @@ func TestPatchGroup(t *testing.T) {
463463
require.Equal(t, http.StatusBadRequest, cerr.StatusCode())
464464
})
465465

466+
// For quotas to work with prebuilds, it's currently required to add the
467+
// prebuilds user into a group with a quota allowance.
468+
// See: docs/admin/templates/extending-templates/prebuilt-workspaces.md
469+
t.Run("PrebuildsUser", func(t *testing.T) {
470+
t.Parallel()
471+
472+
client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
473+
Features: license.Features{
474+
codersdk.FeatureTemplateRBAC: 1,
475+
},
476+
}})
477+
userAdminClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
478+
ctx := testutil.Context(t, testutil.WaitLong)
479+
group, err := userAdminClient.CreateGroup(ctx, user.OrganizationID, codersdk.CreateGroupRequest{
480+
Name: "prebuilds",
481+
QuotaAllowance: 123,
482+
})
483+
require.NoError(t, err)
484+
485+
group, err = userAdminClient.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
486+
Name: "prebuilds",
487+
AddUsers: []string{prebuilds.SystemUserID.String()},
488+
})
489+
require.NoError(t, err)
490+
})
491+
466492
t.Run("Everyone", func(t *testing.T) {
467493
t.Parallel()
468494
t.Run("NoUpdateName", func(t *testing.T) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy