mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: Add user roles, but do not yet enforce them (#1200)
* chore: Rework roles to be expandable by name alone
This commit is contained in:
@ -21,6 +21,15 @@ INSERT INTO
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5) RETURNING *;
|
||||
|
||||
|
||||
-- name: GetOrganizationMembershipsByUserID :many
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
organization_members
|
||||
WHERE
|
||||
user_id = $1;
|
||||
|
||||
-- name: GetOrganizationIDsByMemberIDs :many
|
||||
SELECT
|
||||
user_id, array_agg(organization_id) :: uuid [ ] AS "organization_IDs"
|
||||
@ -30,3 +39,14 @@ WHERE
|
||||
user_id = ANY(@ids :: uuid [ ])
|
||||
GROUP BY
|
||||
user_id;
|
||||
|
||||
-- name: UpdateMemberRoles :one
|
||||
UPDATE
|
||||
organization_members
|
||||
SET
|
||||
-- Remove all duplicates from the roles.
|
||||
roles = ARRAY(SELECT DISTINCT UNNEST(@granted_roles :: text[]))
|
||||
WHERE
|
||||
user_id = @user_id
|
||||
AND organization_id = @org_id
|
||||
RETURNING *;
|
@ -33,10 +33,11 @@ INSERT INTO
|
||||
username,
|
||||
hashed_password,
|
||||
created_at,
|
||||
updated_at
|
||||
updated_at,
|
||||
rbac_roles
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6) RETURNING *;
|
||||
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
|
||||
|
||||
-- name: UpdateUserProfile :one
|
||||
UPDATE
|
||||
@ -48,6 +49,16 @@ SET
|
||||
WHERE
|
||||
id = $1 RETURNING *;
|
||||
|
||||
-- name: UpdateUserRoles :one
|
||||
UPDATE
|
||||
users
|
||||
SET
|
||||
-- Remove all duplicates from the roles.
|
||||
rbac_roles = ARRAY(SELECT DISTINCT UNNEST(@granted_roles :: text[]))
|
||||
WHERE
|
||||
id = @id
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetUsers :many
|
||||
SELECT
|
||||
*
|
||||
|
Reference in New Issue
Block a user