Skip to content
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
fix: doing a noop patch to templates resulted in 404
The patch response did not include the template. The UI required the
template to be returned to form the new page path
  • Loading branch information
Emyrk committed Jan 18, 2024
commit 6d2055207bc6278f8cd47e33f3d94f51381d2afb
4 changes: 3 additions & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {

if updated.UpdatedAt.IsZero() {
aReq.New = template
httpapi.Write(ctx, rw, http.StatusNotModified, nil)
// Still write back the template so apis can use the updated regardless
// if there was a change. Such as the UI.
httpapi.Write(ctx, rw, http.StatusNotModified, api.convertTemplate(updated))
return
}
aReq.New = updated
Expand Down
27 changes: 0 additions & 27 deletions coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,6 @@ func TestTemplate(t *testing.T) {
_, err := client.Template(ctx, template.ID)
require.NoError(t, err)
})

// Create a template, remove the everyone group, see if an owner can
// still fetch the template.
t.Run("GetOnEveryoneRemove", func(t *testing.T) {
t.Parallel()
owner := coderdtest.New(t, nil)
first := coderdtest.CreateFirstUser(t, owner)

client, _ := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, first.OrganizationID, nil)
template := coderdtest.CreateTemplate(t, client, first.OrganizationID, version.ID)

ctx := testutil.Context(t, testutil.WaitMedium)
err := client.UpdateTemplateACL(ctx, template.ID, codersdk.UpdateTemplateACL{
UserPerms: nil,
GroupPerms: map[string]codersdk.TemplateRole{
"everyone": codersdk.TemplateRoleDeleted,
},
})
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

_, err = owner.Template(ctx, template.ID)
require.NoError(t, err)
})
}

func TestPostTemplateByOrganization(t *testing.T) {
Expand Down
38 changes: 38 additions & 0 deletions enterprise/coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,44 @@ func TestTemplates(t *testing.T) {
require.Empty(t, template.DeprecationMessage)
require.False(t, template.Deprecated)
})

// Create a template, remove the group, see if an owner can
// still fetch the template.
t.Run("GetOnEveryoneRemove", func(t *testing.T) {
Comment on lines +691 to +693
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth keeping, it was the original report.

t.Parallel()
owner, first := coderdenttest.New(t, &coderdenttest.Options{
Options: &coderdtest.Options{
IncludeProvisionerDaemon: true,
TemplateScheduleStore: schedule.NewEnterpriseTemplateScheduleStore(agplUserQuietHoursScheduleStore()),
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAccessControl: 1,
codersdk.FeatureTemplateRBAC: 1,
},
},
})

client, _ := coderdtest.CreateAnotherUser(t, owner, first.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, first.OrganizationID, nil)
template := coderdtest.CreateTemplate(t, client, first.OrganizationID, version.ID)

ctx := testutil.Context(t, testutil.WaitMedium)
err := client.UpdateTemplateACL(ctx, template.ID, codersdk.UpdateTemplateACL{
UserPerms: nil,
GroupPerms: map[string]codersdk.TemplateRole{
// OrgID is the everyone ID
first.OrganizationID.String(): codersdk.TemplateRoleDeleted,
},
})
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

_, err = owner.Template(ctx, template.ID)
require.NoError(t, err)
})
}

func TestTemplateACL(t *testing.T) {
Expand Down