Skip to content
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
23 changes: 13 additions & 10 deletions cli/templateedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (

func templateEdit() *cobra.Command {
var (
name string
displayName string
description string
icon string
defaultTTL time.Duration
name string
displayName string
description string
icon string
defaultTTL time.Duration
allowUserCancelWorkspaceJobs bool
)

cmd := &cobra.Command{
Expand All @@ -40,11 +41,12 @@ func templateEdit() *cobra.Command {

// NOTE: coderd will ignore empty fields.
req := codersdk.UpdateTemplateMeta{
Name: name,
DisplayName: displayName,
Description: description,
Icon: icon,
DefaultTTLMillis: defaultTTL.Milliseconds(),
Name: name,
DisplayName: displayName,
Description: description,
Icon: icon,
DefaultTTLMillis: defaultTTL.Milliseconds(),
AllowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
}

_, err = client.UpdateTemplateMeta(cmd.Context(), template.ID, req)
Expand All @@ -61,6 +63,7 @@ func templateEdit() *cobra.Command {
cmd.Flags().StringVarP(&description, "description", "", "", "Edit the template description")
cmd.Flags().StringVarP(&icon, "icon", "", "", "Edit the template icon path")
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 0, "Edit the template default time before shutdown - workspaces created from this template to this value.")
cmd.Flags().BoolVarP(&allowUserCancelWorkspaceJobs, "allow-user-cancel-workspace-jobs", "", true, "Allow users to cancel in-progress workspace jobs.")
cliui.AllowSkipPrompt(cmd)

return cmd
Expand Down
7 changes: 7 additions & 0 deletions cli/templateedit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli_test

import (
"context"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -31,6 +32,8 @@ func TestTemplateEdit(t *testing.T) {
desc := "lorem ipsum dolor sit amet et cetera"
icon := "/icons/new-icon.png"
defaultTTL := 12 * time.Hour
allowUserCancelWorkspaceJobs := false

cmdArgs := []string{
"templates",
"edit",
Expand All @@ -40,6 +43,7 @@ func TestTemplateEdit(t *testing.T) {
"--description", desc,
"--icon", icon,
"--default-ttl", defaultTTL.String(),
"--allow-user-cancel-workspace-jobs=" + strconv.FormatBool(allowUserCancelWorkspaceJobs),
}
cmd, root := clitest.New(t, cmdArgs...)
clitest.SetupConfig(t, client, root)
Expand All @@ -57,6 +61,7 @@ func TestTemplateEdit(t *testing.T) {
assert.Equal(t, desc, updated.Description)
assert.Equal(t, icon, updated.Icon)
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
assert.Equal(t, allowUserCancelWorkspaceJobs, updated.AllowUserCancelWorkspaceJobs)
})
t.Run("FirstEmptyThenNotModified", func(t *testing.T) {
t.Parallel()
Expand All @@ -75,6 +80,7 @@ func TestTemplateEdit(t *testing.T) {
"--description", template.Description,
"--icon", template.Icon,
"--default-ttl", (time.Duration(template.DefaultTTLMillis) * time.Millisecond).String(),
"--allow-user-cancel-workspace-jobs=" + strconv.FormatBool(template.AllowUserCancelWorkspaceJobs),
}
cmd, root := clitest.New(t, cmdArgs...)
clitest.SetupConfig(t, client, root)
Expand All @@ -91,6 +97,7 @@ func TestTemplateEdit(t *testing.T) {
assert.Equal(t, template.Description, updated.Description)
assert.Equal(t, template.Icon, updated.Icon)
assert.Equal(t, template.DefaultTTLMillis, updated.DefaultTTLMillis)
assert.Equal(t, template.AllowUserCancelWorkspaceJobs, updated.AllowUserCancelWorkspaceJobs)
})
t.Run("InvalidDisplayName", func(t *testing.T) {
t.Parallel()
Expand Down
5 changes: 4 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 @@
ALTER TABLE templates DROP COLUMN allow_user_cancel_workspace_jobs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE templates ADD COLUMN allow_user_cancel_workspace_jobs boolean NOT NULL DEFAULT true;

COMMENT ON COLUMN templates.allow_user_cancel_workspace_jobs
IS 'Allow users to cancel in-progress workspace jobs.';
Comment thread
mtojek marked this conversation as resolved.
Resolved
2 changes: 2 additions & 0 deletions coderd/database/models.go

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

73 changes: 43 additions & 30 deletions coderd/database/queries.sql.go

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

8 changes: 5 additions & 3 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ INSERT INTO
icon,
user_acl,
group_acl,
display_name
display_name,
allow_user_cancel_workspace_jobs
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *;

-- name: UpdateTemplateActiveVersionByID :exec
UPDATE
Expand Down Expand Up @@ -102,7 +103,8 @@ SET
default_ttl = $4,
name = $5,
icon = $6,
display_name = $7
display_name = $7,
allow_user_cancel_workspace_jobs = $8
WHERE
id = $1
RETURNING
Expand Down
Loading