mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
chore: add /groups endpoint to filter by organization
and/or member
(#14260)
* chore: merge get groups sql queries into 1 * Add endpoint for fetching groups with filters * remove 2 ways to customizing a fake authorizer
This commit is contained in:
@ -1,6 +1,3 @@
|
||||
-- name: GetGroups :many
|
||||
SELECT * FROM groups;
|
||||
|
||||
-- name: GetGroupByID :one
|
||||
SELECT
|
||||
*
|
||||
@ -23,30 +20,35 @@ AND
|
||||
LIMIT
|
||||
1;
|
||||
|
||||
-- name: GetGroupsByOrganizationID :many
|
||||
-- name: GetGroups :many
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
organization_id = $1;
|
||||
|
||||
-- name: GetGroupsByOrganizationAndUserID :many
|
||||
SELECT
|
||||
groups.*
|
||||
*
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
groups.id IN (
|
||||
SELECT
|
||||
group_id
|
||||
FROM
|
||||
group_members_expanded gme
|
||||
WHERE
|
||||
gme.user_id = @user_id
|
||||
AND
|
||||
gme.organization_id = @organization_id
|
||||
);
|
||||
true
|
||||
AND CASE
|
||||
WHEN @organization_id:: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
|
||||
groups.organization_id = @organization_id
|
||||
ELSE true
|
||||
END
|
||||
AND CASE
|
||||
-- Filter to only include groups a user is a member of
|
||||
WHEN @has_member_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
|
||||
EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
-- this view handles the 'everyone' group in orgs.
|
||||
group_members_expanded
|
||||
WHERE
|
||||
group_members_expanded.group_id = groups.id
|
||||
AND
|
||||
group_members_expanded.user_id = @has_member_id
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
;
|
||||
|
||||
-- name: InsertGroup :one
|
||||
INSERT INTO groups (
|
||||
@ -68,15 +70,15 @@ INSERT INTO groups (
|
||||
id,
|
||||
name,
|
||||
organization_id,
|
||||
source
|
||||
source
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
group_name,
|
||||
@organization_id,
|
||||
@source
|
||||
gen_random_uuid(),
|
||||
group_name,
|
||||
@organization_id,
|
||||
@source
|
||||
FROM
|
||||
UNNEST(@group_names :: text[]) AS group_name
|
||||
UNNEST(@group_names :: text[]) AS group_name
|
||||
-- If the name conflicts, do nothing.
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING *;
|
||||
|
Reference in New Issue
Block a user