Skip to content

Commit e000bd1

Browse files
committed
feat: show organization name for groups on user profile
1 parent 4997691 commit e000bd1

File tree

17 files changed

+687
-221
lines changed

17 files changed

+687
-221
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ func (q *querier) GetGroupMembersCountByGroupID(ctx context.Context, groupID uui
15031503
return memberCount, nil
15041504
}
15051505

1506-
func (q *querier) GetGroups(ctx context.Context, arg database.GetGroupsParams) ([]database.Group, error) {
1506+
func (q *querier) GetGroups(ctx context.Context, arg database.GetGroupsParams) ([]database.GetGroupsRow, error) {
15071507
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err == nil {
15081508
// Optimize this query for system users as it is used in telemetry.
15091509
// Calling authz on all groups in a deployment for telemetry jobs is

coderd/database/dbmem/dbmem.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ func (q *FakeQuerier) GetGroupMembersCountByGroupID(ctx context.Context, groupID
26092609
return int64(len(users)), nil
26102610
}
26112611

2612-
func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams) ([]database.Group, error) {
2612+
func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams) ([]database.GetGroupsRow, error) {
26132613
err := validateDatabaseType(arg)
26142614
if err != nil {
26152615
return nil, err
@@ -2632,9 +2632,11 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
26322632
groupIDs[orgMember.OrganizationID] = struct{}{}
26332633
}
26342634
}
2635+
26352636
}
26362637

2637-
filtered := make([]database.Group, 0)
2638+
organizationDisplayNames := make(map[uuid.UUID]string)
2639+
filtered := make([]database.GetGroupsRow, 0)
26382640
for _, group := range q.groups {
26392641
if arg.OrganizationID != uuid.Nil && group.OrganizationID != arg.OrganizationID {
26402642
continue
@@ -2645,7 +2647,27 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
26452647
continue
26462648
}
26472649

2648-
filtered = append(filtered, group)
2650+
orgDisplayName, ok := organizationDisplayNames[group.ID]
2651+
if !ok {
2652+
for _, org := range q.organizations {
2653+
if group.OrganizationID == org.ID {
2654+
orgDisplayName = org.DisplayName
2655+
break
2656+
}
2657+
}
2658+
organizationDisplayNames[group.ID] = orgDisplayName
2659+
}
2660+
2661+
filtered = append(filtered, database.GetGroupsRow{
2662+
ID: group.ID,
2663+
Name: group.Name,
2664+
OrganizationID: group.OrganizationID,
2665+
AvatarURL: group.AvatarURL,
2666+
QuotaAllowance: group.QuotaAllowance,
2667+
DisplayName: group.DisplayName,
2668+
Source: group.Source,
2669+
OrganizationDisplayName: orgDisplayName,
2670+
})
26492671
}
26502672

26512673
return filtered, nil

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 47 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/groups.sql

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,34 @@ LIMIT
2222

2323
-- name: GetGroups :many
2424
SELECT
25-
*
25+
groups.*, organizations.display_name AS organization_display_name
2626
FROM
27-
groups
27+
groups
28+
INNER JOIN
29+
organizations ON ((groups.organization_id = organizations.id))
2830
WHERE
29-
true
30-
AND CASE
31-
WHEN @organization_id:: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
32-
groups.organization_id = @organization_id
33-
ELSE true
34-
END
35-
AND CASE
36-
-- Filter to only include groups a user is a member of
37-
WHEN @has_member_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
38-
EXISTS (
39-
SELECT
40-
1
41-
FROM
42-
-- this view handles the 'everyone' group in orgs.
43-
group_members_expanded
44-
WHERE
45-
group_members_expanded.group_id = groups.id
46-
AND
47-
group_members_expanded.user_id = @has_member_id
48-
)
49-
ELSE true
50-
END
31+
true
32+
AND CASE
33+
WHEN @organization_id:: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
34+
groups.organization_id = @organization_id
35+
ELSE true
36+
END
37+
AND CASE
38+
-- Filter to only include groups a user is a member of
39+
WHEN @has_member_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
40+
EXISTS (
41+
SELECT
42+
1
43+
FROM
44+
-- this view handles the 'everyone' group in orgs.
45+
group_members_expanded
46+
WHERE
47+
group_members_expanded.group_id = groups.id
48+
AND
49+
group_members_expanded.user_id = @has_member_id
50+
)
51+
ELSE true
52+
END
5153
;
5254

5355
-- name: InsertGroup :one
@@ -70,15 +72,15 @@ INSERT INTO groups (
7072
id,
7173
name,
7274
organization_id,
73-
source
75+
source
7476
)
7577
SELECT
76-
gen_random_uuid(),
77-
group_name,
78-
@organization_id,
79-
@source
78+
gen_random_uuid(),
79+
group_name,
80+
@organization_id,
81+
@source
8082
FROM
81-
UNNEST(@group_names :: text[]) AS group_name
83+
UNNEST(@group_names :: text[]) AS group_name
8284
-- If the name conflicts, do nothing.
8385
ON CONFLICT DO NOTHING
8486
RETURNING *;
@@ -113,5 +115,3 @@ DELETE FROM
113115
groups
114116
WHERE
115117
id = $1;
116-
117-

codersdk/groups.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ type CreateGroupRequest struct {
2626
}
2727

2828
type Group struct {
29-
ID uuid.UUID `json:"id" format:"uuid"`
30-
Name string `json:"name"`
31-
DisplayName string `json:"display_name"`
32-
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
33-
Members []ReducedUser `json:"members"`
29+
ID uuid.UUID `json:"id" format:"uuid"`
30+
Name string `json:"name"`
31+
DisplayName string `json:"display_name"`
32+
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
33+
OrganizationDisplayName string `json:"organization_display_name"`
34+
Members []ReducedUser `json:"members"`
3435
// How many members are in this group. Shows the total count,
3536
// even if the user is not authorized to read group member details.
3637
// May be greater than `len(Group.Members)`.

site/src/api/api.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,14 +1603,20 @@ class ApiMethods {
16031603
return response.data;
16041604
};
16051605

1606+
getGroups = async (): Promise<TypesGen.Group[]> => {
1607+
const response = await this.axios.get("/api/v2/groups");
1608+
return response.data;
1609+
};
1610+
16061611
/**
16071612
* @param organization Can be the organization's ID or name
16081613
*/
1609-
getGroups = async (organization: string): Promise<TypesGen.Group[]> => {
1614+
getGroupsByOrganization = async (
1615+
organization: string,
1616+
): Promise<TypesGen.Group[]> => {
16101617
const response = await this.axios.get(
1611-
`/api/v2/organizations/${organization}/groups`,
1618+
`/api/v2/organization/${organization}/groups`,
16121619
);
1613-
16141620
return response.data;
16151621
};
16161622

0 commit comments

Comments
 (0)