Skip to content

Commit ffe31f2

Browse files
committed
feat: Add endpoint to get all workspaces a user can access
This iterates through user organizations to get permitted workspaces. This will allow admins to manage user workspaces!
1 parent 3660483 commit ffe31f2

File tree

10 files changed

+183
-280
lines changed

10 files changed

+183
-280
lines changed

cmd/templater/main.go

Lines changed: 0 additions & 279 deletions
This file was deleted.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ func New(options *Options) (http.Handler, func()) {
258258
})
259259
r.Get("/gitsshkey", api.gitSSHKey)
260260
r.Put("/gitsshkey", api.regenerateGitSSHKey)
261+
r.Get("/workspaces", api.workspacesByOwner)
261262
})
262263
})
263264
})

coderd/database/databasefake/databasefake.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ func (q *fakeQuerier) GetWorkspacesByOrganizationID(_ context.Context, req datab
478478
return workspaces, nil
479479
}
480480

481+
func (q *fakeQuerier) GetWorkspacesByOrganizationIDs(_ context.Context, req database.GetWorkspacesByOrganizationIDsParams) ([]database.Workspace, error) {
482+
q.mutex.RLock()
483+
defer q.mutex.RUnlock()
484+
485+
workspaces := make([]database.Workspace, 0)
486+
for _, workspace := range q.workspaces {
487+
for _, id := range req.Ids {
488+
if workspace.ID.String() != id.String() {
489+
continue
490+
}
491+
if workspace.Deleted != req.Deleted {
492+
continue
493+
}
494+
workspaces = append(workspaces, workspace)
495+
}
496+
}
497+
if len(workspaces) == 0 {
498+
return nil, sql.ErrNoRows
499+
}
500+
return workspaces, nil
501+
}
502+
481503
func (q *fakeQuerier) GetWorkspacesByOwnerID(_ context.Context, req database.GetWorkspacesByOwnerIDParams) ([]database.Workspace, error) {
482504
q.mutex.RLock()
483505
defer q.mutex.RUnlock()

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

coderd/database/queries/workspaces.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ LIMIT
1111
-- name: GetWorkspacesByOrganizationID :many
1212
SELECT * FROM workspaces WHERE organization_id = $1 AND deleted = $2;
1313

14+
-- name: GetWorkspacesByOrganizationIDs :many
15+
SELECT * FROM workspaces WHERE organization_id = ANY(@ids :: uuid [ ]) AND deleted = @deleted;
16+
1417
-- name: GetWorkspacesByTemplateID :many
1518
SELECT
1619
*

0 commit comments

Comments
 (0)