Skip to content

chore: add 'classic_parameter_flow' column setting to templates #17828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

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

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

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

1 change: 1 addition & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11084,6 +11084,7 @@ func (q *FakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
tpl.GroupACL = arg.GroupACL
tpl.AllowUserCancelWorkspaceJobs = arg.AllowUserCancelWorkspaceJobs
tpl.MaxPortSharingLevel = arg.MaxPortSharingLevel
tpl.UseClassicParameterFlow = arg.UseClassicParameterFlow
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
@@ -0,0 +1,28 @@
DROP VIEW template_with_names;

-- Drop the column
ALTER TABLE templates DROP COLUMN use_classic_parameter_flow;


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.';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- 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 use_classic_parameter_flow BOOL NOT NULL DEFAULT false;

COMMENT ON COLUMN templates.use_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.UseClassicParameterFlow,
&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,
use_classic_parameter_flow = $10
WHERE
id = $1
;
Expand Down
17 changes: 13 additions & 4 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.UseClassicParameterFlow
if req.UseClassicParameterFlow != nil {
classicTemplateFlow = *req.UseClassicParameterFlow
}

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.UseClassicParameterFlow) &&
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,
UseClassicParameterFlow: classicTemplateFlow,
})
if err != nil {
return xerrors.Errorf("update template metadata: %w", err)
Expand Down Expand Up @@ -1066,10 +1074,11 @@ func (api *API) convertTemplate(
DaysOfWeek: codersdk.BitmapToWeekdays(template.AutostartAllowedDays()),
},
// These values depend on entitlements and come from the templateAccessControl
RequireActiveVersion: templateAccessControl.RequireActiveVersion,
Deprecated: templateAccessControl.IsDeprecated(),
DeprecationMessage: templateAccessControl.Deprecated,
MaxPortShareLevel: maxPortShareLevel,
RequireActiveVersion: templateAccessControl.RequireActiveVersion,
Deprecated: templateAccessControl.IsDeprecated(),
DeprecationMessage: templateAccessControl.Deprecated,
MaxPortShareLevel: maxPortShareLevel,
UseClassicParameterFlow: template.UseClassicParameterFlow,
}
}

Expand Down
35 changes: 35 additions & 0 deletions coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,41 @@ func TestPatchTemplateMeta(t *testing.T) {
require.False(t, template.Deprecated)
})
})

t.Run("ClassicParameterFlow", func(t *testing.T) {
t.Parallel()

client := coderdtest.New(t, nil)
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
require.False(t, template.UseClassicParameterFlow, "default is false")

bTrue := true
bFalse := false
req := codersdk.UpdateTemplateMeta{
UseClassicParameterFlow: &bTrue,
}

ctx := testutil.Context(t, testutil.WaitLong)

// set to true
updated, err := client.UpdateTemplateMeta(ctx, template.ID, req)
require.NoError(t, err)
assert.True(t, updated.UseClassicParameterFlow, "expected true")

// noop
req.UseClassicParameterFlow = nil
updated, err = client.UpdateTemplateMeta(ctx, template.ID, req)
require.NoError(t, err)
assert.True(t, updated.UseClassicParameterFlow, "expected true")

// back to false
req.UseClassicParameterFlow = &bFalse
updated, err = client.UpdateTemplateMeta(ctx, template.ID, req)
require.NoError(t, err)
assert.False(t, updated.UseClassicParameterFlow, "expected false")
})
}

func TestDeleteTemplate(t *testing.T) {
Expand Down
Loading
Loading