Skip to content

fix: fix template edit overriding with flag defaults #11564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
linting
  • Loading branch information
sreya committed Jan 11, 2024
commit 6802eb919f8d02aaf243bf609c05390746b0ddf0
8 changes: 4 additions & 4 deletions cli/templateedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
),
Short: "Edit the metadata of a template by name.",
Handler: func(inv *clibase.Invocation) error {
unsetAutostopRequirementDaysOfWeek := userSetOption(inv, "autostop-requirement-weekdays")
unsetAutostopRequirementDaysOfWeek := len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none"
requiresScheduling := (len(autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) ||
autostopRequirementWeeks > 0 ||
!allowUserAutostart ||
Expand Down Expand Up @@ -140,7 +140,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
autostopRequirementDaysOfWeek = template.AutostopRequirement.DaysOfWeek
}

if len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none" {
if unsetAutostopRequirementDaysOfWeek {
autostopRequirementDaysOfWeek = []string{}
}

Expand All @@ -162,9 +162,9 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
deprecated = &deprecationMessage
}

var disableEveryoneGroup *bool
var disableEveryoneGroup bool
if userSetOption(inv, "private") {
disableEveryoneGroup = &disableEveryone
disableEveryoneGroup = disableEveryone
}

req := codersdk.UpdateTemplateMeta{
Expand Down
2 changes: 1 addition & 1 deletion coderd/externalauth/externalauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
// return a better error.
switch resp.StatusCode {
case http.StatusTooManyRequests:
return nil, fmt.Errorf("rate limit hit, unable to authorize device. please try again later")
return nil, xerrors.New("rate limit hit, unable to authorize device. please try again later")
default:
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions coderd/promoauth/github.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package promoauth

import (
"fmt"
"net/http"
"strconv"
"time"

"golang.org/x/xerrors"
)

type rateLimits struct {
Expand Down Expand Up @@ -81,7 +82,7 @@ func (p *headerParser) string(key string) string {

v := p.header.Get(key)
if v == "" {
p.errors[key] = fmt.Errorf("missing header %q", key)
p.errors[key] = xerrors.Errorf("missing header %q", key)
}
return v
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
}

groupACL := template.GroupACL
if req.DisableEveryoneGroupAccess != nil && *req.DisableEveryoneGroupAccess == true {
if req.DisableEveryoneGroupAccess {
delete(groupACL, template.OrganizationID.String())
}

Expand Down
2 changes: 1 addition & 1 deletion codersdk/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ type UpdateTemplateMeta struct {
// If this is set to true, the template will not be available to all users,
// and must be explicitly granted to users or groups in the permissions settings
// of the template.
DisableEveryoneGroupAccess *bool `json:"disable_everyone_group_access"`
DisableEveryoneGroupAccess bool `json:"disable_everyone_group_access"`
}

type TemplateExample struct {
Expand Down
10 changes: 5 additions & 5 deletions enterprise/cli/templateedit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"
"time"

"github.com/aws/smithy-go/ptr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -13,6 +12,7 @@ import (
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbfake"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
"github.com/coder/coder/v2/enterprise/coderd/license"
Expand Down Expand Up @@ -232,8 +232,8 @@ func TestTemplateEdit(t *testing.T) {
TimeTilDormantMillis: expectedDormancyMillis,
TimeTilDormantAutoDeleteMillis: expectedAutoDeleteMillis,
RequireActiveVersion: expectedRequireActiveVersion,
DeprecationMessage: ptr.String(deprecationMessage),
DisableEveryoneGroupAccess: ptr.Bool(expectedDisableEveryone),
DeprecationMessage: ptr.Ref(deprecationMessage),
DisableEveryoneGroupAccess: expectedDisableEveryone,
AllowUserCancelWorkspaceJobs: expectedAllowCancelJobs,
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: expectedAutostartDaysOfWeek,
Expand Down Expand Up @@ -281,8 +281,8 @@ func TestTemplateEdit(t *testing.T) {
TimeTilDormantMillis: expectedDormancyMillis,
TimeTilDormantAutoDeleteMillis: expectedAutoDeleteMillis,
RequireActiveVersion: expectedRequireActiveVersion,
DeprecationMessage: ptr.String(deprecationMessage),
DisableEveryoneGroupAccess: ptr.Bool(expectedDisableEveryone),
DeprecationMessage: ptr.Ref(deprecationMessage),
DisableEveryoneGroupAccess: expectedDisableEveryone,
AllowUserCancelWorkspaceJobs: expectedAllowCancelJobs,
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: expectedAutostartDaysOfWeek,
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func TestTemplateACL(t *testing.T) {
Description: template.Description,
Icon: template.Icon,
AllowUserCancelWorkspaceJobs: template.AllowUserCancelWorkspaceJobs,
DisableEveryoneGroupAccess: true,
DisableEveryoneGroupAccess: ptr.Ref(true),
})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion site/src/api/typesGenerated.ts

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