Skip to content

feat: archive template versions to hide them from the ui #10179

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 17 commits into from
Oct 11, 2023
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
Add unit test to prevent workspace create on archived version
  • Loading branch information
Emyrk committed Oct 10, 2023
commit e7d8359b0801e2394238d20fd05ccb39c73ba1de
2 changes: 1 addition & 1 deletion cli/templateversionarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *RootCmd) archiveTemplateVersions() *clibase.Cmd {
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Use: "archive [template-name...] ",
Short: "Archive unused failed template versions from a given template(s)",
Short: "Archive unused or failed template versions from a given template(s)",
Middleware: clibase.Chain(
r.InitClient(client),
),
Expand Down
28 changes: 28 additions & 0 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,34 @@ func TestWorkspace(t *testing.T) {
assert.NotEmpty(t, agent2.Health.Reason)
})
})

t.Run("Archived", func(t *testing.T) {
t.Parallel()
ownerClient := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, ownerClient)

client, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID, rbac.RoleTemplateAdmin())

active := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJobCompleted(t, client, active.ID)
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, active.ID)
// We need another version because the active template version cannot be
// archived.
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil, func(request *codersdk.CreateTemplateVersionRequest) {
request.TemplateID = template.ID
})
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

err := client.SetArchiveTemplateVersion(ctx, version.ID, true)
require.NoError(t, err, "archive version")

_, err = client.CreateWorkspace(ctx, owner.OrganizationID, codersdk.Me, codersdk.CreateWorkspaceRequest{
TemplateVersionID: version.ID,
Name: "testworkspace",
})
require.Error(t, err, "create workspace with archived version")
require.ErrorContains(t, err, "Archived template versions cannot")
})
}

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