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:
Steven Masley
2024-08-15 13:27:50 -05:00
committed by GitHub
parent f619500833
commit 83ccdaa755
5 changed files with 159 additions and 21 deletions

View File

@ -1,14 +1,15 @@
-- name: GetQuotaAllowanceForUser :one
SELECT
coalesce(SUM(quota_allowance), 0)::BIGINT
coalesce(SUM(groups.quota_allowance), 0)::BIGINT
FROM
groups g
LEFT JOIN group_members gm ON
g.id = gm.group_id
WHERE
user_id = $1
OR
g.id = g.organization_id;
(
-- Select all groups this user is a member of. This will also include
-- the "Everyone" group for organizations the user is a member of.
SELECT * FROM group_members_expanded WHERE @user_id = user_id
) AS members
INNER JOIN groups ON
members.group_id = groups.id
;
-- name: GetQuotaConsumedForUser :one
WITH latest_builds AS (