mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: Implement joins with golang templates (#6429)
* feat: Implement view for workspace builds to include rbac info * Removes the need to fetch the workspace to run an rbac check. * chore: Use workspace build as RBAC object * chore: Use golang templates instead of sqlc files
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
)
|
||||
|
||||
@@ -101,6 +103,12 @@ func (g Group) RBACObject() rbac.Object {
|
||||
InOrg(g.OrganizationID)
|
||||
}
|
||||
|
||||
func (b WorkspaceBuildRBAC) RBACObject() rbac.Object {
|
||||
return rbac.ResourceWorkspace.WithID(b.WorkspaceID).
|
||||
InOrg(b.OrganizationID).
|
||||
WithOwner(b.WorkspaceOwnerID.String())
|
||||
}
|
||||
|
||||
func (w Workspace) RBACObject() rbac.Object {
|
||||
return rbac.ResourceWorkspace.WithID(w.ID).
|
||||
InOrg(w.OrganizationID).
|
||||
@@ -183,6 +191,18 @@ func (l License) RBACObject() rbac.Object {
|
||||
return rbac.ResourceLicense.WithIDString(strconv.FormatInt(int64(l.ID), 10))
|
||||
}
|
||||
|
||||
func (b WorkspaceBuild) WithWorkspace(workspace Workspace) WorkspaceBuildRBAC {
|
||||
return b.Expand(workspace.OrganizationID, workspace.OwnerID)
|
||||
}
|
||||
|
||||
func (b WorkspaceBuild) Expand(orgID, ownerID uuid.UUID) WorkspaceBuildRBAC {
|
||||
return WorkspaceBuildRBAC{
|
||||
WorkspaceBuild: b,
|
||||
OrganizationID: orgID,
|
||||
WorkspaceOwnerID: ownerID,
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertUserRows(rows []GetUsersRow) []User {
|
||||
users := make([]User, len(rows))
|
||||
for i, r := range rows {
|
||||
|
||||
Reference in New Issue
Block a user