Skip to content

Commit e11299c

Browse files
committed
chore: fixup quotas to only include groups you are a member of
Before all everyone groups were included in the allowance.
1 parent 4fc0479 commit e11299c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

coderd/database/queries.sql.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/quotas.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
-- name: GetQuotaAllowanceForUser :one
22
SELECT
3-
coalesce(SUM(quota_allowance), 0)::BIGINT
3+
coalesce(SUM(groups.quota_allowance), 0)::BIGINT
44
FROM
5-
groups g
6-
LEFT JOIN group_members gm ON
7-
g.id = gm.group_id
8-
WHERE
9-
user_id = $1
10-
OR
11-
g.id = g.organization_id;
5+
(
6+
-- Select all groups this user is a member of. This will also include
7+
-- the "Everyone" group for organizations the user is a member of.
8+
SELECT * FROM group_members_expanded WHERE @user_id = user_id
9+
) AS members
10+
INNER JOIN groups ON
11+
members.group_id = groups.id
12+
;
1213

1314
-- name: GetQuotaConsumedForUser :one
1415
WITH latest_builds AS (

0 commit comments

Comments
 (0)