Skip to content

Commit 36451d5

Browse files
committed
feat: add owner groups to workspace data
1 parent 426e9f2 commit 36451d5

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
@@ -1145,6 +1145,10 @@ func (q *querier) GetGroupsByOrganizationID(ctx context.Context, organizationID
11451145
return fetchWithPostFilter(q.auth, q.db.GetGroupsByOrganizationID)(ctx, organizationID)
11461146
}
11471147

1148+
func (q *querier) GetGroupsByUserId(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
1149+
panic("not implemented")
1150+
}
1151+
11481152
func (q *querier) GetHealthSettings(ctx context.Context) (string, error) {
11491153
// No authz checks
11501154
return q.db.GetHealthSettings(ctx)

coderd/database/dbmem/dbmem.go

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

2267+
func (q *FakeQuerier) GetGroupsByUserId(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
2268+
panic("not implemented")
2269+
}
2270+
22672271
func (q *FakeQuerier) GetHealthSettings(_ context.Context) (string, error) {
22682272
q.mutex.RLock()
22692273
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)