mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: implement deprecated flag for templates to prevent new workspaces (#10745)
* feat: implement deprecated flag for templates to prevent new workspaces * Add deprecated filter to template fetching * Add deprecated to template table * Add deprecated notice to template page * Add ui to deprecate a template
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
const deprecatedFlagName = "deprecated"
|
||||
var (
|
||||
name string
|
||||
displayName string
|
||||
@@ -32,6 +33,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
allowUserAutostart bool
|
||||
allowUserAutostop bool
|
||||
requireActiveVersion bool
|
||||
deprecationMessage string
|
||||
)
|
||||
client := new(codersdk.Client)
|
||||
|
||||
@@ -118,6 +120,15 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
autostopRequirementDaysOfWeek = []string{}
|
||||
}
|
||||
|
||||
// Only pass explicitly set deprecated values since the empty string
|
||||
// removes the deprecated message. By default if we pass a nil,
|
||||
// there is no change to this field.
|
||||
var deprecated *string
|
||||
opt := inv.Command.Options.ByName(deprecatedFlagName)
|
||||
if !(opt.ValueSource == "" || opt.ValueSource == clibase.ValueSourceDefault) {
|
||||
deprecated = &deprecationMessage
|
||||
}
|
||||
|
||||
// NOTE: coderd will ignore empty fields.
|
||||
req := codersdk.UpdateTemplateMeta{
|
||||
Name: name,
|
||||
@@ -139,6 +150,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
AllowUserAutostart: allowUserAutostart,
|
||||
AllowUserAutostop: allowUserAutostop,
|
||||
RequireActiveVersion: requireActiveVersion,
|
||||
DeprecationMessage: deprecated,
|
||||
}
|
||||
|
||||
_, err = client.UpdateTemplateMeta(inv.Context(), template.ID, req)
|
||||
@@ -166,6 +178,12 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
Description: "Edit the template description.",
|
||||
Value: clibase.StringOf(&description),
|
||||
},
|
||||
{
|
||||
Name: deprecatedFlagName,
|
||||
Flag: "deprecated",
|
||||
Description: "Sets the template as deprecated. Must be a message explaining why the template is deprecated.",
|
||||
Value: clibase.StringOf(&deprecationMessage),
|
||||
},
|
||||
{
|
||||
Flag: "icon",
|
||||
Description: "Edit the template icon path.",
|
||||
|
||||
@@ -28,6 +28,10 @@ OPTIONS:
|
||||
from this template default to this value. Maps to "Default autostop"
|
||||
in the UI.
|
||||
|
||||
--deprecated string
|
||||
Sets the template as deprecated. Must be a message explaining why the
|
||||
template is deprecated.
|
||||
|
||||
--description string
|
||||
Edit the template description.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user