mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
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:
@ -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,
|
||||
|
Reference in New Issue
Block a user