Skip to content
Merged
Prev Previous commit
Next Next commit
Move to in tx and ignore new fields in audit diff
  • Loading branch information
Emyrk committed Jul 19, 2023
commit 4715f521c442b8373fcc3ad328a44523ce1473f1
4 changes: 2 additions & 2 deletions enterprise/audit/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ var auditableResourcesTypes = map[any]map[string]Action{
"icon": ActionTrack,
"default_ttl": ActionTrack,
"created_by": ActionTrack,
"created_by_username": ActionTrack,
"created_by_avatar_url": ActionTrack,
"created_by_username": ActionIgnore,
"created_by_avatar_url": ActionIgnore,
"group_acl": ActionTrack,
"user_acl": ActionTrack,
"allow_user_autostart": ActionTrack,
Expand Down
40 changes: 20 additions & 20 deletions enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,26 @@ func (*EnterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
return xerrors.Errorf("update template schedule: %w", err)
}

// Update all workspaces using the template to set the user defined schedule
// to be within the new bounds. This essentially does the following for each
// workspace using the template.
// if (template.ttl != NULL) {
// workspace.ttl = min(workspace.ttl, template.ttl)
// }
//
// NOTE: this does not apply to currently running workspaces as their
// schedule information is committed to the workspace_build during start.
// This limitation is displayed to the user while editing the template.
if opts.MaxTTL > 0 {
err = db.UpdateWorkspaceTTLToBeWithinTemplateMax(ctx, database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams{
TemplateID: template.ID,
TemplateMaxTTL: int64(opts.MaxTTL),
})
if err != nil {
return xerrors.Errorf("update TTL of all workspaces on template to be within new template max TTL: %w", err)
}
}

template, err = db.GetTemplateByID(ctx, tpl.ID)
if err != nil {
return xerrors.Errorf("get updated template schedule: %w", err)
Expand All @@ -371,25 +391,5 @@ func (*EnterpriseTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.C
return database.Template{}, err
}

// Update all workspaces using the template to set the user defined schedule
// to be within the new bounds. This essentially does the following for each
// workspace using the template.
// if (template.ttl != NULL) {
// workspace.ttl = min(workspace.ttl, template.ttl)
// }
//
// NOTE: this does not apply to currently running workspaces as their
// schedule information is committed to the workspace_build during start.
// This limitation is displayed to the user while editing the template.
if opts.MaxTTL > 0 {
err = db.UpdateWorkspaceTTLToBeWithinTemplateMax(ctx, database.UpdateWorkspaceTTLToBeWithinTemplateMaxParams{
TemplateID: template.ID,
TemplateMaxTTL: int64(opts.MaxTTL),
})
if err != nil {
return database.Template{}, xerrors.Errorf("update TTL of all workspaces on template to be within new template max TTL: %w", err)
}
}

return template, nil
}