Skip to content

Commit 4e15540

Browse files
committed
feat: add owner groups to workspace data
1 parent 79441e3 commit 4e15540

File tree

12 files changed

+266
-127
lines changed

12 files changed

+266
-127
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@ func (q *querier) GetGroupsByOrganizationID(ctx context.Context, organizationID
11411141
return fetchWithPostFilter(q.auth, q.db.GetGroupsByOrganizationID)(ctx, organizationID)
11421142
}
11431143

1144+
func (q *querier) GetGroupsByUserId(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
1145+
panic("not implemented")
1146+
}
1147+
11441148
func (q *querier) GetHealthSettings(ctx context.Context) (string, error) {
11451149
// No authz checks
11461150
return q.db.GetHealthSettings(ctx)

coderd/database/dbmem/dbmem.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,10 @@ func (q *FakeQuerier) GetGroupsByOrganizationID(_ context.Context, id uuid.UUID)
22542254
return groups, nil
22552255
}
22562256

2257+
func (q *FakeQuerier) GetGroupsByUserId(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
2258+
panic("not implemented")
2259+
}
2260+
22572261
func (q *FakeQuerier) GetHealthSettings(_ context.Context) (string, error) {
22582262
q.mutex.RLock()
22592263
defer q.mutex.RUnlock()

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 0 deletions
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: 15 additions & 0 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 & 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: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/groupmembers.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ WHERE
2323
AND
2424
users.deleted = 'false';
2525

26+
-- name: GetGroupsByUserId :many
27+
SELECT
28+
groups.*
29+
FROM
30+
groups
31+
LEFT JOIN
32+
group_members
33+
ON
34+
group_members.group_id = groups.id
35+
WHERE
36+
group_members.user_id = @user_id;
37+
2638
-- InsertUserGroupsByName adds a user to all provided groups, if they exist.
2739
-- name: InsertUserGroupsByName :exec
2840
WITH groups AS (

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
467467
if err != nil {
468468
return nil, failJob(fmt.Sprintf("get owner: %s", err))
469469
}
470+
ownerGroups, err := s.Database.GetGroupsByUserId(ctx, owner.ID)
471+
ownerGroupNames := make([]string, 0, len(ownerGroups))
472+
for _, group := range ownerGroups {
473+
ownerGroupNames = append(ownerGroupNames, group.Name)
474+
}
475+
if err != nil {
476+
return nil, failJob(fmt.Sprintf("get owner groups: %s", err))
477+
}
470478
err = s.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspace.ID), []byte{})
471479
if err != nil {
472480
return nil, failJob(fmt.Sprintf("publish workspace update: %s", err))
@@ -567,6 +575,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
567575
WorkspaceOwner: owner.Username,
568576
WorkspaceOwnerEmail: owner.Email,
569577
WorkspaceOwnerName: owner.Name,
578+
WorkspaceOwnerGroups: ownerGroupNames,
570579
WorkspaceOwnerOidcAccessToken: workspaceOwnerOIDCAccessToken,
571580
WorkspaceId: workspace.ID.String(),
572581
WorkspaceOwnerId: owner.ID.String(),

coderd/wsbuilder/wsbuilder.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ func (e BuildError) Unwrap() error {
197197
return e.Wrapped
198198
}
199199

200+
type Adder interface {
201+
Add() int
202+
}
203+
204+
type myAdder struct {
205+
val int
206+
}
207+
208+
func (m *myAdder) Add() int {
209+
return m.val
210+
}
211+
212+
func sum(adder []Adder) int {
213+
sum := 0
214+
for _, a := range adder {
215+
sum += a.Add()
216+
}
217+
return sum
218+
}
219+
220+
var x = sum([]Adder{&myAdder{
221+
val: 2,
222+
}, &myAdder{
223+
val: 4,
224+
}})
225+
200226
// Build computes and inserts a new workspace build into the database. If authFunc is provided, it also performs
201227
// authorization preflight checks.
202228
func (b *Builder) Build(

0 commit comments

Comments
 (0)