chore: join owner, template, and org in new workspace view (#15116)

Joins in fields like `username`, `avatar_url`, `organization_name`,
`template_name` to `workspaces` via a **view**. 
The view must be maintained moving forward, but this prevents needing to
add RBAC permissions to fetch related workspace fields.
This commit is contained in:
Steven Masley
2024-10-22 09:20:54 -05:00
committed by GitHub
parent 5076161078
commit 343f8ec9ab
81 changed files with 1063 additions and 735 deletions

View File

@ -234,22 +234,24 @@ func (e *Executor) runOnce(t time.Time) Stats {
// threshold for inactivity.
if reason == database.BuildReasonDormancy {
wsOld := ws
ws, err = tx.UpdateWorkspaceDormantDeletingAt(e.ctx, database.UpdateWorkspaceDormantDeletingAtParams{
wsNew, err := tx.UpdateWorkspaceDormantDeletingAt(e.ctx, database.UpdateWorkspaceDormantDeletingAtParams{
ID: ws.ID,
DormantAt: sql.NullTime{
Time: dbtime.Now(),
Valid: true,
},
})
auditLog = &auditParams{
Old: wsOld,
New: ws,
}
if err != nil {
return xerrors.Errorf("update workspace dormant deleting at: %w", err)
}
auditLog = &auditParams{
Old: wsOld.WorkspaceTable(),
New: wsNew,
}
// To keep the `ws` accurate without doing a sql fetch
ws.DormantAt = wsNew.DormantAt
shouldNotifyDormancy = true
log.Info(e.ctx, "dormant workspace",
@ -510,8 +512,8 @@ func isEligibleForFailedStop(build database.WorkspaceBuild, job database.Provisi
}
type auditParams struct {
Old database.Workspace
New database.Workspace
Old database.WorkspaceTable
New database.WorkspaceTable
Success bool
}
@ -521,7 +523,7 @@ func auditBuild(ctx context.Context, log slog.Logger, auditor audit.Auditor, par
status = http.StatusOK
}
audit.BackgroundAudit(ctx, &audit.BackgroundAuditParams[database.Workspace]{
audit.BackgroundAudit(ctx, &audit.BackgroundAuditParams[database.WorkspaceTable]{
Audit: auditor,
Log: log,
UserID: params.New.OwnerID,