fix: properly convert max port share level for oss (#13261)

This commit is contained in:
Garrett Delfosse
2024-05-13 14:37:51 -04:00
committed by GitHub
parent a5a64948cd
commit ebee9288ae
5 changed files with 25 additions and 13 deletions

View File

@ -623,8 +623,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
validErrs = append(validErrs, codersdk.ValidationError{Field: "time_til_dormant_autodelete_ms", Detail: "Value must be at least one minute."})
}
maxPortShareLevel := template.MaxPortSharingLevel
if req.MaxPortShareLevel != nil && *req.MaxPortShareLevel != codersdk.WorkspaceAgentPortShareLevel(maxPortShareLevel) {
err := portSharer.ValidateTemplateMaxPortSharingLevel(*req.MaxPortShareLevel)
if req.MaxPortShareLevel != nil && *req.MaxPortShareLevel != portSharer.ConvertMaxLevel(template.MaxPortSharingLevel) {
err := portSharer.ValidateTemplateMaxLevel(*req.MaxPortShareLevel)
if err != nil {
validErrs = append(validErrs, codersdk.ValidationError{Field: "max_port_sharing_level", Detail: err.Error()})
} else {
@ -857,6 +857,9 @@ func (api *API) convertTemplate(
autostopRequirementWeeks = 1
}
portSharer := *(api.PortSharer.Load())
maxPortShareLevel := portSharer.ConvertMaxLevel(template.MaxPortSharingLevel)
return codersdk.Template{
ID: template.ID,
CreatedAt: template.CreatedAt,
@ -891,6 +894,6 @@ func (api *API) convertTemplate(
RequireActiveVersion: templateAccessControl.RequireActiveVersion,
Deprecated: templateAccessControl.IsDeprecated(),
DeprecationMessage: templateAccessControl.Deprecated,
MaxPortShareLevel: codersdk.WorkspaceAgentPortShareLevel(template.MaxPortSharingLevel),
MaxPortShareLevel: maxPortShareLevel,
}
}