mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
feat: add avatar urls to groups (#4525)
This commit is contained in:
@ -2784,6 +2784,7 @@ func (q *fakeQuerier) UpdateGroupByID(_ context.Context, arg database.UpdateGrou
|
||||
for i, group := range q.groups {
|
||||
if group.ID == arg.ID {
|
||||
group.Name = arg.Name
|
||||
group.AvatarURL = arg.AvatarURL
|
||||
q.groups[i] = group
|
||||
return group, nil
|
||||
}
|
||||
@ -3135,6 +3136,7 @@ func (q *fakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
|
||||
ID: arg.ID,
|
||||
Name: arg.Name,
|
||||
OrganizationID: arg.OrganizationID,
|
||||
AvatarURL: arg.AvatarURL,
|
||||
}
|
||||
|
||||
q.groups = append(q.groups, group)
|
||||
|
3
coderd/database/dump.sql
generated
3
coderd/database/dump.sql
generated
@ -181,7 +181,8 @@ CREATE TABLE group_members (
|
||||
CREATE TABLE groups (
|
||||
id uuid NOT NULL,
|
||||
name text NOT NULL,
|
||||
organization_id uuid NOT NULL
|
||||
organization_id uuid NOT NULL,
|
||||
avatar_url text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE licenses (
|
||||
|
5
coderd/database/migrations/000062_group_avatars.down.sql
Normal file
5
coderd/database/migrations/000062_group_avatars.down.sql
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE groups DROP COLUMN avatar_url;
|
||||
|
||||
COMMIT;
|
5
coderd/database/migrations/000062_group_avatars.up.sql
Normal file
5
coderd/database/migrations/000062_group_avatars.up.sql
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE groups ADD COLUMN avatar_url text NOT NULL DEFAULT '';
|
||||
|
||||
COMMIT;
|
@ -439,6 +439,7 @@ type Group struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
AvatarURL string `db:"avatar_url" json:"avatar_url"`
|
||||
}
|
||||
|
||||
type GroupMember struct {
|
||||
|
@ -928,7 +928,7 @@ func (q *sqlQuerier) GetAllOrganizationMembers(ctx context.Context, organization
|
||||
|
||||
const getGroupByID = `-- name: GetGroupByID :one
|
||||
SELECT
|
||||
id, name, organization_id
|
||||
id, name, organization_id, avatar_url
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
@ -940,13 +940,18 @@ LIMIT
|
||||
func (q *sqlQuerier) GetGroupByID(ctx context.Context, id uuid.UUID) (Group, error) {
|
||||
row := q.db.QueryRowContext(ctx, getGroupByID, id)
|
||||
var i Group
|
||||
err := row.Scan(&i.ID, &i.Name, &i.OrganizationID)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getGroupByOrgAndName = `-- name: GetGroupByOrgAndName :one
|
||||
SELECT
|
||||
id, name, organization_id
|
||||
id, name, organization_id, avatar_url
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
@ -965,7 +970,12 @@ type GetGroupByOrgAndNameParams struct {
|
||||
func (q *sqlQuerier) GetGroupByOrgAndName(ctx context.Context, arg GetGroupByOrgAndNameParams) (Group, error) {
|
||||
row := q.db.QueryRowContext(ctx, getGroupByOrgAndName, arg.OrganizationID, arg.Name)
|
||||
var i Group
|
||||
err := row.Scan(&i.ID, &i.Name, &i.OrganizationID)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@ -1024,7 +1034,7 @@ func (q *sqlQuerier) GetGroupMembers(ctx context.Context, groupID uuid.UUID) ([]
|
||||
|
||||
const getGroupsByOrganizationID = `-- name: GetGroupsByOrganizationID :many
|
||||
SELECT
|
||||
id, name, organization_id
|
||||
id, name, organization_id, avatar_url
|
||||
FROM
|
||||
groups
|
||||
WHERE
|
||||
@ -1042,7 +1052,12 @@ func (q *sqlQuerier) GetGroupsByOrganizationID(ctx context.Context, organization
|
||||
var items []Group
|
||||
for rows.Next() {
|
||||
var i Group
|
||||
if err := rows.Scan(&i.ID, &i.Name, &i.OrganizationID); err != nil {
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
@ -1058,7 +1073,7 @@ func (q *sqlQuerier) GetGroupsByOrganizationID(ctx context.Context, organization
|
||||
|
||||
const getUserGroups = `-- name: GetUserGroups :many
|
||||
SELECT
|
||||
groups.id, groups.name, groups.organization_id
|
||||
groups.id, groups.name, groups.organization_id, groups.avatar_url
|
||||
FROM
|
||||
groups
|
||||
JOIN
|
||||
@ -1078,7 +1093,12 @@ func (q *sqlQuerier) GetUserGroups(ctx context.Context, userID uuid.UUID) ([]Gro
|
||||
var items []Group
|
||||
for rows.Next() {
|
||||
var i Group
|
||||
if err := rows.Scan(&i.ID, &i.Name, &i.OrganizationID); err != nil {
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
@ -1099,7 +1119,7 @@ INSERT INTO groups (
|
||||
organization_id
|
||||
)
|
||||
VALUES
|
||||
( $1, 'Everyone', $1) RETURNING id, name, organization_id
|
||||
( $1, 'Everyone', $1) RETURNING id, name, organization_id, avatar_url
|
||||
`
|
||||
|
||||
// We use the organization_id as the id
|
||||
@ -1108,7 +1128,12 @@ VALUES
|
||||
func (q *sqlQuerier) InsertAllUsersGroup(ctx context.Context, organizationID uuid.UUID) (Group, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertAllUsersGroup, organizationID)
|
||||
var i Group
|
||||
err := row.Scan(&i.ID, &i.Name, &i.OrganizationID)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@ -1116,22 +1141,34 @@ const insertGroup = `-- name: InsertGroup :one
|
||||
INSERT INTO groups (
|
||||
id,
|
||||
name,
|
||||
organization_id
|
||||
organization_id,
|
||||
avatar_url
|
||||
)
|
||||
VALUES
|
||||
( $1, $2, $3) RETURNING id, name, organization_id
|
||||
( $1, $2, $3, $4) RETURNING id, name, organization_id, avatar_url
|
||||
`
|
||||
|
||||
type InsertGroupParams struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
AvatarURL string `db:"avatar_url" json:"avatar_url"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertGroup(ctx context.Context, arg InsertGroupParams) (Group, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertGroup, arg.ID, arg.Name, arg.OrganizationID)
|
||||
row := q.db.QueryRowContext(ctx, insertGroup,
|
||||
arg.ID,
|
||||
arg.Name,
|
||||
arg.OrganizationID,
|
||||
arg.AvatarURL,
|
||||
)
|
||||
var i Group
|
||||
err := row.Scan(&i.ID, &i.Name, &i.OrganizationID)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@ -1157,21 +1194,28 @@ const updateGroupByID = `-- name: UpdateGroupByID :one
|
||||
UPDATE
|
||||
groups
|
||||
SET
|
||||
name = $1
|
||||
name = $1,
|
||||
avatar_url = $2
|
||||
WHERE
|
||||
id = $2
|
||||
RETURNING id, name, organization_id
|
||||
id = $3
|
||||
RETURNING id, name, organization_id, avatar_url
|
||||
`
|
||||
|
||||
type UpdateGroupByIDParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
AvatarURL string `db:"avatar_url" json:"avatar_url"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) UpdateGroupByID(ctx context.Context, arg UpdateGroupByIDParams) (Group, error) {
|
||||
row := q.db.QueryRowContext(ctx, updateGroupByID, arg.Name, arg.ID)
|
||||
row := q.db.QueryRowContext(ctx, updateGroupByID, arg.Name, arg.AvatarURL, arg.ID)
|
||||
var i Group
|
||||
err := row.Scan(&i.ID, &i.Name, &i.OrganizationID)
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.OrganizationID,
|
||||
&i.AvatarURL,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
|
@ -74,10 +74,11 @@ AND
|
||||
INSERT INTO groups (
|
||||
id,
|
||||
name,
|
||||
organization_id
|
||||
organization_id,
|
||||
avatar_url
|
||||
)
|
||||
VALUES
|
||||
( $1, $2, $3) RETURNING *;
|
||||
( $1, $2, $3, $4) RETURNING *;
|
||||
|
||||
-- We use the organization_id as the id
|
||||
-- for simplicity since all users is
|
||||
@ -95,9 +96,10 @@ VALUES
|
||||
UPDATE
|
||||
groups
|
||||
SET
|
||||
name = $1
|
||||
name = $1,
|
||||
avatar_url = $2
|
||||
WHERE
|
||||
id = $2
|
||||
id = $3
|
||||
RETURNING *;
|
||||
|
||||
-- name: InsertGroupMember :exec
|
||||
|
Reference in New Issue
Block a user