Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 007f3fd

Browse files
committed
chore: address comments - add IsPrebuild and AsPrebuild methods to WorkspaceTable
1 parent 998fa3b commit 007f3fd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

coderd/database/modelmethods.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ func (w WorkspaceTable) DormantRBAC() rbac.Object {
264264
WithOwner(w.OwnerID.String())
265265
}
266266

267+
// IsPrebuild returns true if the workspace is a prebuild workspace.
268+
// A workspace is considered a prebuild if its owner is the prebuild system user.
269+
func (w WorkspaceTable) IsPrebuild() bool {
270+
return w.OwnerID == PrebuildsSystemUserID
271+
}
272+
273+
// AsPrebuild returns the RBAC object corresponding to the workspace type.
274+
// If the workspace is a prebuild, it returns a prebuilt_workspace RBAC object.
275+
// Otherwise, it returns a normal workspace RBAC object.
276+
func (w WorkspaceTable) AsPrebuild() rbac.Object {
277+
if w.IsPrebuild() {
278+
return rbac.ResourcePrebuiltWorkspace.WithID(w.ID).
279+
InOrg(w.OrganizationID).
280+
WithOwner(w.OwnerID.String())
281+
}
282+
return w.RBACObject()
283+
}
284+
267285
func (m OrganizationMember) RBACObject() rbac.Object {
268286
return rbac.ResourceOrganizationMember.
269287
WithID(m.UserID).

0 commit comments

Comments
 (0)