mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix!: support empty or default fields when updating templates (#19256)
Breaking change: Field types in `codersdk.UpdateTemplateMeta` for `Icon`, `Description`, and `DisplayName` moved to `*string` ## Summary In this pull request we're updating the `UpdateTemplateMeta` struct to allow `DisplayName`, `Description`, and `Icon` to be set as empty `""` or default to the value from the template if not provided in an update call. Fixes https://github.com/coder/coder/issues/19036 ### The bug The reported bug occurred when clients were attempting to update a metadata field in a template via an edit call. When the request was decoded into an `UpdateTemplateMeta` struct the default values for fields in the struct were used to update the template even if they weren't provided. This led to fields like `Icon` being set to `""` (the default value). ### Changes To allow for specific fields to be set to `""` these fields were updated to be `*string` as opposed to `string`. This allows for clients to set these fields as `""` in an update request or they will default to the template value if they are not provided in the update request (will be `nil`). Added tests to confirm empty and nil values and updated other tests that use these fields.
This commit is contained in:
@@ -208,11 +208,11 @@ type ACLAvailable struct {
|
||||
}
|
||||
|
||||
type UpdateTemplateMeta struct {
|
||||
Name string `json:"name,omitempty" validate:"omitempty,template_name"`
|
||||
DisplayName string `json:"display_name,omitempty" validate:"omitempty,template_display_name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
DefaultTTLMillis int64 `json:"default_ttl_ms,omitempty"`
|
||||
Name string `json:"name,omitempty" validate:"omitempty,template_name"`
|
||||
DisplayName *string `json:"display_name,omitempty" validate:"omitempty,template_display_name"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
DefaultTTLMillis int64 `json:"default_ttl_ms,omitempty"`
|
||||
// ActivityBumpMillis allows optionally specifying the activity bump
|
||||
// duration for all workspaces created from this template. Defaults to 1h
|
||||
// but can be set to 0 to disable activity bumping.
|
||||
|
||||
Reference in New Issue
Block a user