Skip to content

Commit f3f0183

Browse files
committed
refactor: extract PrebuiltWorkspaceResource interface for prebuilt RBAC support
1 parent 4b8775f commit f3f0183

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

coderd/database/modelmethods.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ func (gm GroupMember) RBACObject() rbac.Object {
199199
return rbac.ResourceGroupMember.WithID(gm.UserID).InOrg(gm.OrganizationID).WithOwner(gm.UserID.String())
200200
}
201201

202+
// PrebuiltWorkspaceResource defines the interface for types that can be identified as prebuilt workspaces
203+
// and converted to their corresponding prebuilt workspace RBAC object.
204+
type PrebuiltWorkspaceResource interface {
205+
IsPrebuild() bool
206+
AsPrebuild() rbac.Object
207+
}
208+
202209
// WorkspaceTable converts a Workspace to it's reduced version.
203210
// A more generalized solution is to use json marshaling to
204211
// consistently keep these two structs in sync.

coderd/workspacebuilds.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
396396
}
397397
// Special handling for prebuilt workspace deletion
398398
if action == policy.ActionDelete {
399-
if workspaceObj, ok := object.(interface {
400-
IsPrebuild() bool
401-
AsPrebuild() rbac.Object
402-
}); ok && workspaceObj.IsPrebuild() {
399+
if workspaceObj, ok := object.(database.PrebuiltWorkspaceResource); ok && workspaceObj.IsPrebuild() {
403400
return api.Authorize(r, action, workspaceObj.AsPrebuild())
404401
}
405402
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy