mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
chore: fixup quotas to only include groups you are a member of (#14271)
* chore: fixup quotas to only include groups you are a member of Before all everyone groups were included in the allowance. * chore: add unit test to execercise the bug * add unit test to add rows into the everyone group
This commit is contained in:
@ -233,6 +233,51 @@ func TestWorkspaceQuota(t *testing.T) {
|
||||
verifyQuota(ctx, t, client, 4, 4)
|
||||
require.Equal(t, codersdk.WorkspaceStatusRunning, build.Status)
|
||||
})
|
||||
|
||||
// Ensures allowance from everyone groups only counts if you are an org member.
|
||||
// This was a bug where the group "Everyone" was being counted for all users,
|
||||
// regardless of membership.
|
||||
t.Run("AllowanceEveryone", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dv := coderdtest.DeploymentValues(t)
|
||||
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
|
||||
owner, first := coderdenttest.New(t, &coderdenttest.Options{
|
||||
Options: &coderdtest.Options{
|
||||
DeploymentValues: dv,
|
||||
},
|
||||
LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
Features: license.Features{
|
||||
codersdk.FeatureTemplateRBAC: 1,
|
||||
codersdk.FeatureMultipleOrganizations: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
member, _ := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID)
|
||||
|
||||
// Create a second organization
|
||||
second := coderdenttest.CreateOrganization(t, owner, coderdenttest.CreateOrganizationOptions{})
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
// update everyone quotas
|
||||
//nolint:gocritic // using owner for simplicity
|
||||
_, err := owner.PatchGroup(ctx, first.OrganizationID, codersdk.PatchGroupRequest{
|
||||
QuotaAllowance: ptr.Ref(30),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = owner.PatchGroup(ctx, second.ID, codersdk.PatchGroupRequest{
|
||||
QuotaAllowance: ptr.Ref(15),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
verifyQuota(ctx, t, member, 0, 30)
|
||||
// This currently reports the total site wide quotas. We might want to
|
||||
// org scope this api call in the future.
|
||||
verifyQuota(ctx, t, owner, 0, 45)
|
||||
})
|
||||
}
|
||||
|
||||
func planWithCost(cost int32) []*proto.Response {
|
||||
|
Reference in New Issue
Block a user