Skip to content

Commit 49afab1

Browse files
authored
feat: show organization name for groups on user profile (#14448)
1 parent 4b5c45d commit 49afab1

File tree

29 files changed

+357
-229
lines changed

29 files changed

+357
-229
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/db2sdk/db2sdk.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,19 @@ func Users(users []database.User, organizationIDs map[uuid.UUID][]uuid.UUID) []c
208208
})
209209
}
210210

211-
func Group(group database.Group, members []database.GroupMember, totalMemberCount int) codersdk.Group {
211+
func Group(row database.GetGroupsRow, members []database.GroupMember, totalMemberCount int) codersdk.Group {
212212
return codersdk.Group{
213-
ID: group.ID,
214-
Name: group.Name,
215-
DisplayName: group.DisplayName,
216-
OrganizationID: group.OrganizationID,
217-
AvatarURL: group.AvatarURL,
218-
Members: ReducedUsersFromGroupMembers(members),
219-
TotalMemberCount: totalMemberCount,
220-
QuotaAllowance: int(group.QuotaAllowance),
221-
Source: codersdk.GroupSource(group.Source),
213+
ID: row.Group.ID,
214+
Name: row.Group.Name,
215+
DisplayName: row.Group.DisplayName,
216+
OrganizationID: row.Group.OrganizationID,
217+
AvatarURL: row.Group.AvatarURL,
218+
Members: ReducedUsersFromGroupMembers(members),
219+
TotalMemberCount: totalMemberCount,
220+
QuotaAllowance: int(row.Group.QuotaAllowance),
221+
Source: codersdk.GroupSource(row.Group.Source),
222+
OrganizationName: row.OrganizationName,
223+
OrganizationDisplayName: row.OrganizationDisplayName,
222224
}
223225
}
224226

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/dbauthz/dbauthz_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,10 @@ func (s *MethodTestSuite) TestOrganization() {
607607
check.Args(database.GetGroupsParams{
608608
OrganizationID: o.ID,
609609
}).Asserts(rbac.ResourceSystem, policy.ActionRead, a, policy.ActionRead, b, policy.ActionRead).
610-
Returns([]database.Group{a, b}).
610+
Returns([]database.GetGroupsRow{
611+
{Group: a, OrganizationName: o.Name, OrganizationDisplayName: o.DisplayName},
612+
{Group: b, OrganizationName: o.Name, OrganizationDisplayName: o.DisplayName},
613+
}).
611614
// Fail the system check shortcut
612615
FailSystemObjectChecks()
613616
}))

coderd/database/dbmem/dbmem.go

Lines changed: 21 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
@@ -2634,7 +2634,8 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
26342634
}
26352635
}
26362636

2637-
filtered := make([]database.Group, 0)
2637+
orgDetailsCache := make(map[uuid.UUID]struct{ name, displayName string })
2638+
filtered := make([]database.GetGroupsRow, 0)
26382639
for _, group := range q.groups {
26392640
if arg.OrganizationID != uuid.Nil && group.OrganizationID != arg.OrganizationID {
26402641
continue
@@ -2645,7 +2646,24 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
26452646
continue
26462647
}
26472648

2648-
filtered = append(filtered, group)
2649+
orgDetails, ok := orgDetailsCache[group.ID]
2650+
if !ok {
2651+
for _, org := range q.organizations {
2652+
if group.OrganizationID == org.ID {
2653+
orgDetails = struct{ name, displayName string }{
2654+
name: org.Name, displayName: org.DisplayName,
2655+
}
2656+
break
2657+
}
2658+
}
2659+
orgDetailsCache[group.ID] = orgDetails
2660+
}
2661+
2662+
filtered = append(filtered, database.GetGroupsRow{
2663+
Group: group,
2664+
OrganizationName: orgDetails.name,
2665+
OrganizationDisplayName: orgDetails.displayName,
2666+
})
26492667
}
26502668

26512669
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/modelmethods.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ func (g Group) RBACObject() rbac.Object {
183183
})
184184
}
185185

186+
func (g GetGroupsRow) RBACObject() rbac.Object {
187+
return g.Group.RBACObject()
188+
}
189+
186190
func (gm GroupMember) RBACObject() rbac.Object {
187191
return rbac.ResourceGroupMember.WithID(gm.UserID).InOrg(gm.OrganizationID).WithOwner(gm.UserID.String())
188192
}

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.

0 commit comments

Comments
 (0)