Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add classic parameter flow to tempalte meta api
  • Loading branch information
Emyrk committed May 14, 2025
commit 459ec293c741d0a5b6edfadb27295cd77a192180
1 change: 1 addition & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11082,6 +11082,7 @@ func (q *FakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
tpl.GroupACL = arg.GroupACL
tpl.AllowUserCancelWorkspaceJobs = arg.AllowUserCancelWorkspaceJobs
tpl.MaxPortSharingLevel = arg.MaxPortSharingLevel
tpl.ClassicParameterFlow = arg.ClassicParameterFlow
q.templates[idx] = tpl
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
ALTER TABLE templates DROP COLUMN dynamic_parameter_flow;
ALTER TABLE templates DROP COLUMN classic_parameter_flow;
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
-- Default to `true`. Users will have to opt out of the new flow if they have issues.
ALTER TABLE templates ADD COLUMN dynamic_parameter_flow BOOL NOT NULL DEFAULT true;
-- Default to `false`. Users will have to manually opt back into the classic parameter flow.
-- We want the new experience to be tried first.
ALTER TABLE templates ADD COLUMN classic_parameter_flow BOOL NOT NULL DEFAULT false;

COMMENT ON COLUMN templates.dynamic_parameter_flow IS
'Determines whether to default to the dynamic parameter creation flow for this template. '
'As a template wide setting, the template admin can opt out if there are any issues. '
COMMENT ON COLUMN templates.classic_parameter_flow IS
'Determines whether to default to the dynamic parameter creation flow for this template '
'or continue using the legacy classic parameter creation flow.'
'This is a template wide setting, the template admin can revert to the classic flow if there are any issues. '
'An escape hatch is required, as workspace creation is a core workflow and cannot break. '
'This column will be removed when the dynamic parameter creation flow is stable.';


-- Update the template_with_names view by recreating it.
DROP VIEW template_with_names;
CREATE VIEW
template_with_names
AS
SELECT
templates.*,
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
coalesce(visible_users.username, '') AS created_by_username,
coalesce(organizations.name, '') AS organization_name,
coalesce(organizations.display_name, '') AS organization_display_name,
coalesce(organizations.icon, '') AS organization_icon
FROM
templates
LEFT JOIN
visible_users
ON
templates.created_by = visible_users.id
LEFT JOIN
organizations
ON templates.organization_id = organizations.id
;

COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
1 change: 1 addition & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
&i.Deprecated,
&i.ActivityBump,
&i.MaxPortSharingLevel,
&i.ClassicParameterFlow,
&i.CreatedByAvatarURL,
&i.CreatedByUsername,
&i.OrganizationName,
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ SET
display_name = $6,
allow_user_cancel_workspace_jobs = $7,
group_acl = $8,
max_port_sharing_level = $9
max_port_sharing_level = $9,
classic_parameter_flow = $10
WHERE
id = $1
;
Expand Down
8 changes: 8 additions & 0 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,12 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
return
}

// Defaults to the existing.
classicTemplateFlow := template.ClassicParameterFlow
if req.ClassicParameterFlow != nil {
classicTemplateFlow = *req.ClassicParameterFlow
}

var updated database.Template
err = api.Database.InTx(func(tx database.Store) error {
if req.Name == template.Name &&
Expand All @@ -747,6 +753,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
req.TimeTilDormantAutoDeleteMillis == time.Duration(template.TimeTilDormantAutoDelete).Milliseconds() &&
req.RequireActiveVersion == template.RequireActiveVersion &&
(deprecationMessage == template.Deprecated) &&
(classicTemplateFlow == template.ClassicParameterFlow) &&
maxPortShareLevel == template.MaxPortSharingLevel {
return nil
}
Expand Down Expand Up @@ -788,6 +795,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
AllowUserCancelWorkspaceJobs: req.AllowUserCancelWorkspaceJobs,
GroupACL: groupACL,
MaxPortSharingLevel: maxPortShareLevel,
ClassicParameterFlow: classicTemplateFlow,
})
if err != nil {
return xerrors.Errorf("update template metadata: %w", err)
Expand Down
6 changes: 6 additions & 0 deletions codersdk/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ type UpdateTemplateMeta struct {
// of the template.
DisableEveryoneGroupAccess bool `json:"disable_everyone_group_access"`
MaxPortShareLevel *WorkspaceAgentPortShareLevel `json:"max_port_share_level,omitempty"`
// ClassicParameterFlow is a flag that switches the default behavior to use the classic
// parameter flow when creating a workspace. This only affects deployments with the experiment
// "dynamic-parameters" enabled. This setting will live for a period after the experiment is
// made the default.
// An "opt-out" is present in case the new feature breaks some existing templates.
ClassicParameterFlow *bool `json:"dynamic_parameter_flow,omitempty"`
}

type TemplateExample struct {
Expand Down
1 change: 1 addition & 0 deletions enterprise/audit/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var auditableResourcesTypes = map[any]map[string]Action{
"deprecated": ActionTrack,
"max_port_sharing_level": ActionTrack,
"activity_bump": ActionTrack,
"classic_parameter_flow": ActionTrack,
},
&database.TemplateVersion{}: {
"id": ActionTrack,
Expand Down
Loading