mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
adds support for workspace presets to the coderd database. Support in the API and web frontend will be added in subsequent pull requests. This is the smallest meaningful contribution that I could get passing tests for.
* Add workspace preset tables to the database in a migration * Add queries to manipulate workspace presets to the database * Generate db related code for the newly added queries * Implement new methods to satisfy the Querier interface in dbauthz, dbmem, dbmock and querymetrics * Implement the required tests for dbauthz * Update the audit table to track changes to the new column in workspace builds
This commit is contained in:
@ -1930,6 +1930,30 @@ func (q *querier) GetParameterSchemasByJobID(ctx context.Context, jobID uuid.UUI
|
||||
return q.db.GetParameterSchemasByJobID(ctx, jobID)
|
||||
}
|
||||
|
||||
func (q *querier) GetPresetByWorkspaceBuildID(ctx context.Context, workspaceID uuid.UUID) (database.GetPresetByWorkspaceBuildIDRow, error) {
|
||||
// TODO (sasswart): Double check when to and not to call .InOrg?
|
||||
// TODO (sasswart): it makes sense to me that a caller can read a preset if they can read the template, but double check this.
|
||||
// TODO (sasswart): apply these todos to GetPresetParametersByPresetID and GetPresetsByTemplateVersionID.
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
|
||||
return database.GetPresetByWorkspaceBuildIDRow{}, err
|
||||
}
|
||||
return q.db.GetPresetByWorkspaceBuildID(ctx, workspaceID)
|
||||
}
|
||||
|
||||
func (q *querier) GetPresetParametersByPresetID(ctx context.Context, templateVersionPresetID uuid.UUID) ([]database.GetPresetParametersByPresetIDRow, error) {
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return q.db.GetPresetParametersByPresetID(ctx, templateVersionPresetID)
|
||||
}
|
||||
|
||||
func (q *querier) GetPresetsByTemplateVersionID(ctx context.Context, templateVersionID uuid.UUID) ([]database.GetPresetsByTemplateVersionIDRow, error) {
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return q.db.GetPresetsByTemplateVersionID(ctx, templateVersionID)
|
||||
}
|
||||
|
||||
func (q *querier) GetPreviousTemplateVersion(ctx context.Context, arg database.GetPreviousTemplateVersionParams) (database.TemplateVersion, error) {
|
||||
// An actor can read the previous template version if they can read the related template.
|
||||
// If no linked template exists, we check if the actor can read *a* template.
|
||||
@ -3088,6 +3112,13 @@ func (q *querier) InsertOrganizationMember(ctx context.Context, arg database.Ins
|
||||
return insert(q.log, q.auth, obj, q.db.InsertOrganizationMember)(ctx, arg)
|
||||
}
|
||||
|
||||
func (q *querier) InsertPreset(ctx context.Context, arg database.InsertPresetParams) (database.TemplateVersionPreset, error) {
|
||||
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceTemplate); err != nil {
|
||||
return database.TemplateVersionPreset{}, err
|
||||
}
|
||||
return q.db.InsertPreset(ctx, arg)
|
||||
}
|
||||
|
||||
// TODO: We need to create a ProvisionerJob resource type
|
||||
func (q *querier) InsertProvisionerJob(ctx context.Context, arg database.InsertProvisionerJobParams) (database.ProvisionerJob, error) {
|
||||
// if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceSystem); err != nil {
|
||||
|
Reference in New Issue
Block a user