Skip to content

Commit c2bc801

Browse files
authored
chore: add 'classic_parameter_flow' column setting to templates (#17828)
We are forcing users to try the dynamic parameter experience first. Currently this setting only comes into effect if an experiment is enabled.
1 parent 9063b67 commit c2bc801

File tree

21 files changed

+229
-45
lines changed

21 files changed

+229
-45
lines changed

coderd/apidoc/docs.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmem/dbmem.go

+1
Original file line numberDiff line numberDiff line change
@@ -11084,6 +11084,7 @@ func (q *FakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
1108411084
tpl.GroupACL = arg.GroupACL
1108511085
tpl.AllowUserCancelWorkspaceJobs = arg.AllowUserCancelWorkspaceJobs
1108611086
tpl.MaxPortSharingLevel = arg.MaxPortSharingLevel
11087+
tpl.UseClassicParameterFlow = arg.UseClassicParameterFlow
1108711088
q.templates[idx] = tpl
1108811089
return nil
1108911090
}

coderd/database/dump.sql

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
DROP VIEW template_with_names;
2+
3+
-- Drop the column
4+
ALTER TABLE templates DROP COLUMN use_classic_parameter_flow;
5+
6+
7+
CREATE VIEW
8+
template_with_names
9+
AS
10+
SELECT
11+
templates.*,
12+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
13+
coalesce(visible_users.username, '') AS created_by_username,
14+
coalesce(organizations.name, '') AS organization_name,
15+
coalesce(organizations.display_name, '') AS organization_display_name,
16+
coalesce(organizations.icon, '') AS organization_icon
17+
FROM
18+
templates
19+
LEFT JOIN
20+
visible_users
21+
ON
22+
templates.created_by = visible_users.id
23+
LEFT JOIN
24+
organizations
25+
ON templates.organization_id = organizations.id
26+
;
27+
28+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- Default to `false`. Users will have to manually opt back into the classic parameter flow.
2+
-- We want the new experience to be tried first.
3+
ALTER TABLE templates ADD COLUMN use_classic_parameter_flow BOOL NOT NULL DEFAULT false;
4+
5+
COMMENT ON COLUMN templates.use_classic_parameter_flow IS
6+
'Determines whether to default to the dynamic parameter creation flow for this template '
7+
'or continue using the legacy classic parameter creation flow.'
8+
'This is a template wide setting, the template admin can revert to the classic flow if there are any issues. '
9+
'An escape hatch is required, as workspace creation is a core workflow and cannot break. '
10+
'This column will be removed when the dynamic parameter creation flow is stable.';
11+
12+
13+
-- Update the template_with_names view by recreating it.
14+
DROP VIEW template_with_names;
15+
CREATE VIEW
16+
template_with_names
17+
AS
18+
SELECT
19+
templates.*,
20+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
21+
coalesce(visible_users.username, '') AS created_by_username,
22+
coalesce(organizations.name, '') AS organization_name,
23+
coalesce(organizations.display_name, '') AS organization_display_name,
24+
coalesce(organizations.icon, '') AS organization_icon
25+
FROM
26+
templates
27+
LEFT JOIN
28+
visible_users
29+
ON
30+
templates.created_by = visible_users.id
31+
LEFT JOIN
32+
organizations
33+
ON templates.organization_id = organizations.id
34+
;
35+
36+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';

coderd/database/modelqueries.go

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
117117
&i.Deprecated,
118118
&i.ActivityBump,
119119
&i.MaxPortSharingLevel,
120+
&i.UseClassicParameterFlow,
120121
&i.CreatedByAvatarURL,
121122
&i.CreatedByUsername,
122123
&i.OrganizationName,

coderd/database/models.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+13-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ SET
124124
display_name = $6,
125125
allow_user_cancel_workspace_jobs = $7,
126126
group_acl = $8,
127-
max_port_sharing_level = $9
127+
max_port_sharing_level = $9,
128+
use_classic_parameter_flow = $10
128129
WHERE
129130
id = $1
130131
;

coderd/templates.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,12 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
728728
return
729729
}
730730

731+
// Defaults to the existing.
732+
classicTemplateFlow := template.UseClassicParameterFlow
733+
if req.UseClassicParameterFlow != nil {
734+
classicTemplateFlow = *req.UseClassicParameterFlow
735+
}
736+
731737
var updated database.Template
732738
err = api.Database.InTx(func(tx database.Store) error {
733739
if req.Name == template.Name &&
@@ -747,6 +753,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
747753
req.TimeTilDormantAutoDeleteMillis == time.Duration(template.TimeTilDormantAutoDelete).Milliseconds() &&
748754
req.RequireActiveVersion == template.RequireActiveVersion &&
749755
(deprecationMessage == template.Deprecated) &&
756+
(classicTemplateFlow == template.UseClassicParameterFlow) &&
750757
maxPortShareLevel == template.MaxPortSharingLevel {
751758
return nil
752759
}
@@ -788,6 +795,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
788795
AllowUserCancelWorkspaceJobs: req.AllowUserCancelWorkspaceJobs,
789796
GroupACL: groupACL,
790797
MaxPortSharingLevel: maxPortShareLevel,
798+
UseClassicParameterFlow: classicTemplateFlow,
791799
})
792800
if err != nil {
793801
return xerrors.Errorf("update template metadata: %w", err)
@@ -1066,10 +1074,11 @@ func (api *API) convertTemplate(
10661074
DaysOfWeek: codersdk.BitmapToWeekdays(template.AutostartAllowedDays()),
10671075
},
10681076
// These values depend on entitlements and come from the templateAccessControl
1069-
RequireActiveVersion: templateAccessControl.RequireActiveVersion,
1070-
Deprecated: templateAccessControl.IsDeprecated(),
1071-
DeprecationMessage: templateAccessControl.Deprecated,
1072-
MaxPortShareLevel: maxPortShareLevel,
1077+
RequireActiveVersion: templateAccessControl.RequireActiveVersion,
1078+
Deprecated: templateAccessControl.IsDeprecated(),
1079+
DeprecationMessage: templateAccessControl.Deprecated,
1080+
MaxPortShareLevel: maxPortShareLevel,
1081+
UseClassicParameterFlow: template.UseClassicParameterFlow,
10731082
}
10741083
}
10751084

coderd/templates_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,41 @@ func TestPatchTemplateMeta(t *testing.T) {
15401540
require.False(t, template.Deprecated)
15411541
})
15421542
})
1543+
1544+
t.Run("ClassicParameterFlow", func(t *testing.T) {
1545+
t.Parallel()
1546+
1547+
client := coderdtest.New(t, nil)
1548+
user := coderdtest.CreateFirstUser(t, client)
1549+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
1550+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
1551+
require.False(t, template.UseClassicParameterFlow, "default is false")
1552+
1553+
bTrue := true
1554+
bFalse := false
1555+
req := codersdk.UpdateTemplateMeta{
1556+
UseClassicParameterFlow: &bTrue,
1557+
}
1558+
1559+
ctx := testutil.Context(t, testutil.WaitLong)
1560+
1561+
// set to true
1562+
updated, err := client.UpdateTemplateMeta(ctx, template.ID, req)
1563+
require.NoError(t, err)
1564+
assert.True(t, updated.UseClassicParameterFlow, "expected true")
1565+
1566+
// noop
1567+
req.UseClassicParameterFlow = nil
1568+
updated, err = client.UpdateTemplateMeta(ctx, template.ID, req)
1569+
require.NoError(t, err)
1570+
assert.True(t, updated.UseClassicParameterFlow, "expected true")
1571+
1572+
// back to false
1573+
req.UseClassicParameterFlow = &bFalse
1574+
updated, err = client.UpdateTemplateMeta(ctx, template.ID, req)
1575+
require.NoError(t, err)
1576+
assert.False(t, updated.UseClassicParameterFlow, "expected false")
1577+
})
15431578
}
15441579

15451580
func TestDeleteTemplate(t *testing.T) {

0 commit comments

Comments
 (0)