Skip to content

Commit 1c1d579

Browse files
committed
feat: add avatar urls to groups
1 parent 0d0ea98 commit 1c1d579

File tree

16 files changed

+156
-40
lines changed

16 files changed

+156
-40
lines changed

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BEGIN;
2+
3+
ALTER TABLE groups DROP COLUMN avatar_url;
4+
5+
COMMIT;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BEGIN;
2+
3+
ALTER TABLE groups ADD COLUMN avatar_url text NOT NULL DEFAULT '';
4+
5+
COMMIT;

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
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: 65 additions & 21 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ AND
7474
INSERT INTO groups (
7575
id,
7676
name,
77-
organization_id
77+
organization_id,
78+
avatar_url
7879
)
7980
VALUES
80-
( $1, $2, $3) RETURNING *;
81+
( $1, $2, $3, $4) RETURNING *;
8182

8283
-- We use the organization_id as the id
8384
-- for simplicity since all users is
@@ -95,9 +96,10 @@ VALUES
9596
UPDATE
9697
groups
9798
SET
98-
name = $1
99+
name = $1,
100+
avatar_url = $2
99101
WHERE
100-
id = $2
102+
id = $3
101103
RETURNING *;
102104

103105
-- name: InsertGroupMember :exec

codersdk/groups.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import (
1111
)
1212

1313
type CreateGroupRequest struct {
14-
Name string `json:"name"`
14+
Name string `json:"name"`
15+
AvatarURL string `json:"avatar_url"`
1516
}
1617

1718
type Group struct {
1819
ID uuid.UUID `json:"id"`
1920
Name string `json:"name"`
2021
OrganizationID uuid.UUID `json:"organization_id"`
2122
Members []User `json:"members"`
23+
AvatarURL string `json:"avatar_url"`
2224
}
2325

2426
func (c *Client) CreateGroup(ctx context.Context, orgID uuid.UUID, req CreateGroupRequest) (Group, error) {
@@ -77,6 +79,7 @@ type PatchGroupRequest struct {
7779
AddUsers []string `json:"add_users"`
7880
RemoveUsers []string `json:"remove_users"`
7981
Name string `json:"name"`
82+
AvatarURL *string `json:"avatar_url"`
8083
}
8184

8285
func (c *Client) PatchGroup(ctx context.Context, group uuid.UUID, req PatchGroupRequest) (Group, error) {

enterprise/coderd/groups.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (api *API) postGroupByOrganization(rw http.ResponseWriter, r *http.Request)
4343
ID: uuid.New(),
4444
Name: req.Name,
4545
OrganizationID: org.ID,
46+
AvatarURL: req.AvatarURL,
4647
})
4748
if database.IsUniqueViolation(err) {
4849
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
@@ -123,16 +124,28 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
123124
}
124125

125126
err := api.Database.InTx(func(tx database.Store) error {
127+
group, err := tx.GetGroupByID(ctx, group.ID)
128+
if err != nil {
129+
return xerrors.Errorf("get group by ID: %w", err)
130+
}
131+
132+
// TODO: Do we care about validating this?
133+
if req.AvatarURL != nil {
134+
group.AvatarURL = *req.AvatarURL
135+
}
126136
if req.Name != "" {
127-
var err error
128-
group, err = tx.UpdateGroupByID(ctx, database.UpdateGroupByIDParams{
129-
ID: group.ID,
130-
Name: req.Name,
131-
})
132-
if err != nil {
133-
return xerrors.Errorf("update group by ID: %w", err)
134-
}
137+
group.Name = req.Name
138+
}
139+
140+
group, err = tx.UpdateGroupByID(ctx, database.UpdateGroupByIDParams{
141+
ID: group.ID,
142+
Name: req.Name,
143+
AvatarURL: group.AvatarURL,
144+
})
145+
if err != nil {
146+
return xerrors.Errorf("update group by ID: %w", err)
135147
}
148+
136149
for _, id := range req.AddUsers {
137150
err := tx.InsertGroupMember(ctx, database.InsertGroupMemberParams{
138151
GroupID: group.ID,
@@ -276,6 +289,7 @@ func convertGroup(g database.Group, users []database.User) codersdk.Group {
276289
ID: g.ID,
277290
Name: g.Name,
278291
OrganizationID: g.OrganizationID,
292+
AvatarURL: g.AvatarURL,
279293
Members: convertUsers(users, orgs),
280294
}
281295
}

site/src/api/typesGenerated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export interface CreateFirstUserResponse {
168168
// From codersdk/groups.go
169169
export interface CreateGroupRequest {
170170
readonly name: string
171+
readonly avatar_url: string
171172
}
172173

173174
// From codersdk/users.go
@@ -368,6 +369,7 @@ export interface Group {
368369
readonly name: string
369370
readonly organization_id: string
370371
readonly members: User[]
372+
readonly avatar_url: string
371373
}
372374

373375
// From codersdk/workspaceapps.go
@@ -483,6 +485,7 @@ export interface PatchGroupRequest {
483485
readonly add_users: string[]
484486
readonly remove_users: string[]
485487
readonly name: string
488+
readonly avatar_url?: string
486489
}
487490

488491
// From codersdk/provisionerdaemons.go

site/src/components/GroupAvatar/GroupAvatar.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ const Template: Story<GroupAvatarProps> = (args) => <GroupAvatar {...args} />
1111
export const Example = Template.bind({})
1212
Example.args = {
1313
name: "My Group",
14+
avatarURL: "",
1415
}

site/src/components/GroupAvatar/GroupAvatar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ const StyledBadge = withStyles((theme) => ({
2525

2626
export type GroupAvatarProps = {
2727
name: string
28+
avatarURL?: string
2829
}
2930

30-
export const GroupAvatar: FC<GroupAvatarProps> = ({ name }) => {
31+
export const GroupAvatar: FC<GroupAvatarProps> = ({ name, avatarURL }) => {
3132
return (
3233
<StyledBadge
3334
overlap="circular"
@@ -37,7 +38,13 @@ export const GroupAvatar: FC<GroupAvatarProps> = ({ name }) => {
3738
}}
3839
badgeContent={<Group />}
3940
>
40-
<Avatar>{firstLetter(name)}</Avatar>
41+
<Avatar>
42+
{avatarURL ? (
43+
<img alt={`${name}'s Avatar`} src={avatarURL} width="100%" />
44+
) : (
45+
firstLetter(name)
46+
)}
47+
</Avatar>
4148
</StyledBadge>
4249
)
4350
}

0 commit comments

Comments
 (0)