Skip to content

feat: show organization name for groups on user profile #14448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@
return memberCount, nil
}

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

return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetGroups)(ctx, arg)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (macos-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (macos-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (macos-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (macos-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (macos-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / lint

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject) (typecheck)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / lint

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)) (typecheck)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / lint

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)) (typecheck)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / lint

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)) (typecheck)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / lint

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)) (typecheck)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-e2e

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-e2e-enterprise

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg-16

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg-16

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg-16

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg-16

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-pg-16

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / gen

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-race

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-race

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-race

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-race

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go-race

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (windows-2022)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (windows-2022)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (windows-2022)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (windows-2022)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)

Check failure on line 1515 in coderd/database/dbauthz/dbauthz.go

View workflow job for this annotation

GitHub Actions / test-go (windows-2022)

ObjectType (type database.GetGroupsRow) does not satisfy rbac.Objecter (missing method RBACObject)
}

func (q *querier) GetHealthSettings(ctx context.Context) (string, error) {
Expand Down
28 changes: 25 additions & 3 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ func (q *FakeQuerier) GetGroupMembersCountByGroupID(ctx context.Context, groupID
return int64(len(users)), nil
}

func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams) ([]database.Group, error) {
func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams) ([]database.GetGroupsRow, error) {
err := validateDatabaseType(arg)
if err != nil {
return nil, err
Expand All @@ -2632,9 +2632,11 @@ func (q *FakeQuerier) GetGroups(_ context.Context, arg database.GetGroupsParams)
groupIDs[orgMember.OrganizationID] = struct{}{}
}
}

}

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

filtered = append(filtered, group)
orgDisplayName, ok := organizationDisplayNames[group.ID]
if !ok {
for _, org := range q.organizations {
if group.OrganizationID == org.ID {
orgDisplayName = org.DisplayName
break
}
}
organizationDisplayNames[group.ID] = orgDisplayName
}

filtered = append(filtered, database.GetGroupsRow{
ID: group.ID,
Name: group.Name,
OrganizationID: group.OrganizationID,
AvatarURL: group.AvatarURL,
QuotaAllowance: group.QuotaAllowance,
DisplayName: group.DisplayName,
Source: group.Source,
OrganizationDisplayName: orgDisplayName,
})
}

return filtered, nil
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbmetrics/dbmetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 47 additions & 33 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 32 additions & 32 deletions coderd/database/queries/groups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ LIMIT

-- name: GetGroups :many
SELECT
*
groups.*, organizations.display_name AS organization_display_name
FROM
groups
groups
INNER JOIN
organizations ON ((groups.organization_id = organizations.id))
WHERE
true
AND CASE
WHEN @organization_id:: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
groups.organization_id = @organization_id
ELSE true
END
AND CASE
-- Filter to only include groups a user is a member of
WHEN @has_member_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
EXISTS (
SELECT
1
FROM
-- this view handles the 'everyone' group in orgs.
group_members_expanded
WHERE
group_members_expanded.group_id = groups.id
AND
group_members_expanded.user_id = @has_member_id
)
ELSE true
END
true
AND CASE
WHEN @organization_id:: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
groups.organization_id = @organization_id
ELSE true
END
AND CASE
-- Filter to only include groups a user is a member of
WHEN @has_member_id::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
EXISTS (
SELECT
1
FROM
-- this view handles the 'everyone' group in orgs.
group_members_expanded
WHERE
group_members_expanded.group_id = groups.id
AND
group_members_expanded.user_id = @has_member_id
)
ELSE true
END
;

-- name: InsertGroup :one
Expand All @@ -70,15 +72,15 @@ INSERT INTO groups (
id,
name,
organization_id,
source
source
)
SELECT
gen_random_uuid(),
group_name,
@organization_id,
@source
gen_random_uuid(),
group_name,
@organization_id,
@source
FROM
UNNEST(@group_names :: text[]) AS group_name
UNNEST(@group_names :: text[]) AS group_name
-- If the name conflicts, do nothing.
ON CONFLICT DO NOTHING
RETURNING *;
Expand Down Expand Up @@ -113,5 +115,3 @@ DELETE FROM
groups
WHERE
id = $1;


11 changes: 6 additions & 5 deletions codersdk/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ type CreateGroupRequest struct {
}

type Group struct {
ID uuid.UUID `json:"id" format:"uuid"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
Members []ReducedUser `json:"members"`
ID uuid.UUID `json:"id" format:"uuid"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
OrganizationDisplayName string `json:"organization_display_name"`
Members []ReducedUser `json:"members"`
// How many members are in this group. Shows the total count,
// even if the user is not authorized to read group member details.
// May be greater than `len(Group.Members)`.
Expand Down
12 changes: 9 additions & 3 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,14 +1603,20 @@ class ApiMethods {
return response.data;
};

getGroups = async (): Promise<TypesGen.Group[]> => {
const response = await this.axios.get("/api/v2/groups");
return response.data;
};

/**
* @param organization Can be the organization's ID or name
*/
getGroups = async (organization: string): Promise<TypesGen.Group[]> => {
getGroupsByOrganization = async (
organization: string,
): Promise<TypesGen.Group[]> => {
const response = await this.axios.get(
`/api/v2/organizations/${organization}/groups`,
`/api/v2/organization/${organization}/groups`,
);

return response.data;
};

Expand Down
Loading
Loading