mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* - allow group members to read basic Group info - allow group members to see they are part of the group, but not see that information about other members - add a GetGroupMembersCountByGroupID SQL query, which allows group members to see members count without revealing other information about the members - add the group_members_expanded db view - rewrite group member queries to use the group_members_expanded view - add the RBAC ResourceGroupMember and add it to relevant roles - rewrite GetGroupMembersByGroupID permission checks - make the GroupMember type contain all user fields - fix type issues coming from replacing User with GroupMember in group member queries - add the MemberTotalCount field to codersdk.Group - display `group.total_member_count` instead of `group.members.length` on the account page
50 lines
1.2 KiB
SQL
50 lines
1.2 KiB
SQL
-- name: GetGroupMembers :many
|
|
SELECT * FROM group_members_expanded;
|
|
|
|
-- name: GetGroupMembersByGroupID :many
|
|
SELECT * FROM group_members_expanded WHERE group_id = @group_id;
|
|
|
|
-- name: GetGroupMembersCountByGroupID :one
|
|
-- Returns the total count of members in a group. Shows the total
|
|
-- count even if the caller does not have read access to ResourceGroupMember.
|
|
-- They only need ResourceGroup read access.
|
|
SELECT COUNT(*) FROM group_members_expanded WHERE group_id = @group_id;
|
|
|
|
-- InsertUserGroupsByName adds a user to all provided groups, if they exist.
|
|
-- name: InsertUserGroupsByName :exec
|
|
WITH groups AS (
|
|
SELECT
|
|
id
|
|
FROM
|
|
groups
|
|
WHERE
|
|
groups.organization_id = @organization_id AND
|
|
groups.name = ANY(@group_names :: text [])
|
|
)
|
|
INSERT INTO
|
|
group_members (user_id, group_id)
|
|
SELECT
|
|
@user_id,
|
|
groups.id
|
|
FROM
|
|
groups;
|
|
|
|
-- name: RemoveUserFromAllGroups :exec
|
|
DELETE FROM
|
|
group_members
|
|
WHERE
|
|
user_id = @user_id;
|
|
|
|
-- name: InsertGroupMember :exec
|
|
INSERT INTO
|
|
group_members (user_id, group_id)
|
|
VALUES
|
|
($1, $2);
|
|
|
|
-- name: DeleteGroupMemberFromGroup :exec
|
|
DELETE FROM
|
|
group_members
|
|
WHERE
|
|
user_id = $1 AND
|
|
group_id = $2;
|