mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: support multi-org group sync with runtime configuration (#14578)
- Implement multi-org group sync - Implement runtime configuration to change sync behavior - Legacy group sync migrated to new package
This commit is contained in:
@@ -29,12 +29,41 @@ SELECT
|
||||
FROM
|
||||
groups;
|
||||
|
||||
-- InsertUserGroupsByID adds a user to all provided groups, if they exist.
|
||||
-- name: InsertUserGroupsByID :many
|
||||
WITH groups AS (
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
groups.id = ANY(@group_ids :: uuid [])
|
||||
)
|
||||
INSERT INTO
|
||||
group_members (user_id, group_id)
|
||||
SELECT
|
||||
@user_id,
|
||||
groups.id
|
||||
FROM
|
||||
groups
|
||||
-- If there is a conflict, the user is already a member
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING group_id;
|
||||
|
||||
-- name: RemoveUserFromAllGroups :exec
|
||||
DELETE FROM
|
||||
group_members
|
||||
WHERE
|
||||
user_id = @user_id;
|
||||
|
||||
-- name: RemoveUserFromGroups :many
|
||||
DELETE FROM
|
||||
group_members
|
||||
WHERE
|
||||
user_id = @user_id AND
|
||||
group_id = ANY(@group_ids :: uuid [])
|
||||
RETURNING group_id;
|
||||
|
||||
-- name: InsertGroupMember :exec
|
||||
INSERT INTO
|
||||
group_members (user_id, group_id)
|
||||
|
||||
@@ -52,6 +52,10 @@ WHERE
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
AND CASE WHEN array_length(@group_names :: text[], 1) > 0 THEN
|
||||
groups.name = ANY(@group_names)
|
||||
ELSE true
|
||||
END
|
||||
;
|
||||
|
||||
-- name: InsertGroup :one
|
||||
|
||||
Reference in New Issue
Block a user