10000 feat: archive template versions to hide them from the ui by Emyrk · Pull Request #10086 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

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

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fc715fd
prune template versions
Emyrk Oct 5, 2023
611dac1
Implement fakes and mocks
Emyrk Oct 5, 2023
1de0a5d
Exclude template active versions
Emyrk Oct 5, 2023
3e5f91d
Delete versions are unusable
Emyrk Oct 5, 2023
9200779
Merge remote-tracking branch 'origin/main' into stevenmasley/soft_del…
Emyrk Oct 5, 2023
6e6fbc3
migration bump
Emyrk Oct 5, 2023
2e2c092
Spaces to tabs
Emyrk Oct 5, 2023
7f3d805
add template version prune command
Emyrk Oct 9, 2023
02aa085
Rename to archive
Emyrk Oct 9, 2023
9a416c3
Rename to "archive"
Emyrk Oct 9, 2023
c82ff9a
Merge remote-tracking branch 'origin/main' into stevenmasley/soft_del…
Emyrk Oct 9, 2023
c06d63a
Bump migration file
Emyrk Oct 9, 2023
460b0d2
Make update golden files
Emyrk Oct 9, 2023
d9bfea5
Fix swagger id
Emyrk Oct 9, 2023
655c906
Fix swagger accept json
Emyrk Oct 9, 2023
d4e54b2
Make gen
Emyrk Oct 9, 2023
938f256
Add unarchive
Emyrk Oct 9, 2023
7498c73
Add unarchive api
Emyrk Oct 9, 2023
685512a
Add cli command to unarchive a version
Emyrk Oct 9, 2023
f446ae5
Linting
Emyrk Oct 9, 2023
a9ff9d6
Update golden files
Emyrk Oct 9, 2023
b83a15e
Move cmd commands, allow archiuve deleted
Emyrk Oct 9, 2023
0ecbb79
update golden files
Emyrk Oct 9, 2023
bb3571b
Fix cli errors
Emyrk Oct 9, 2023
533e913
Move cmd
Emyrk Oct 9, 2023
02555b1
Implement fake
Emyrk Oct 9, 2023
1606b99
Linting and gen
Emyrk Oct 9, 2023
3818a57
fixup! Linting and gen
Emyrk Oct 9, 2023
48e44b6
fix: properly trim spaces so multi-line shebang executes (#10146)
kylecarbs Oct 9, 2023
3c97681
chore: reorganize storybook (#10144)
aslilac Oct 9, 2023
f01a4b3
chore: bump the golang-x group with 6 updates (#10128)
dependabot[bot] Oct 9, 2023
e9b4d15
chore: bump google.golang.org/api from 0.143.0 to 0.145.0 (#10130)
dependabot[bot] Oct 9, 2023
4236fc8
ci: bump the github-actions group with 2 updates (#10131)
dependabot[bot] Oct 9, 2023
8c86767
chore: add icons for popular programming languages (#10141)
aslilac Oct 9, 2023
02bcd20
chore: run `go mod tidy`
coadler Oct 9, 2023
91a2025
feat: add `external-auth` cli (#10052)
kylecarbs Oct 9, 2023
54509e5
feat: allow storing extra oauth token properties in the database (#10…
kylecarbs Oct 9, 2023
3fe8966
bump migration number:
Emyrk Oct 10, 2023
44bbbfe
Swagger annotations
Emyrk Oct 10, 2023
f0294c3
Merge remote-tracking branch 'origin/main' into stevenmasley/soft_del…
Emyrk Oct 10, 2023
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
Rename to "archive"
  • Loading branch information
Emyrk committed Oct 9, 2023
commit 9a416c3318d36447bbe4f70099467f1aa8a8f756
41 changes: 41 additions & 0 deletions coderd/apidoc/docs.go

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

35 changes: 35 additions & 0 deletions coderd/apidoc/swagger.json

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

8 changes: 4 additions & 4 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ func (q *FakeQuerier) ArchiveUnusedTemplateVersions(_ context.Context, arg datab
usedVersions[tpl.ActiveVersionID] = true
}

var deleted []uuid.UUID
var archived []uuid.UUID
for i, v := range q.templateVersions {
if v.Archived {
continue
Expand All @@ -905,11 +905,11 @@ func (q *FakeQuerier) ArchiveUnusedTemplateVersions(_ context.Context, arg datab

v.Archived = true
q.templateVersions[i] = v
deleted = append(deleted, v.ID)
archived = append(archived, v.ID)
}
}

return deleted, nil
return archived, nil
}

func (*FakeQuerier) CleanTailnetCoordinators(_ context.Context) error {
Expand Down Expand Up @@ -2825,7 +2825,7 @@ func (q *FakeQuerier) GetTemplateVersionsByTemplateID(_ context.Context, arg dat
if templateVersion.TemplateID.UUID != arg.TemplateID {
continue
}
if arg.Deleted.Valid && arg.Deleted.Bool != templateVersion.Deleted {
if arg.Archived.Valid && arg.Archived.Bool != templateVersion.Archived {
continue
}
version = append(version, q.templateVersionWithUserNoLock(templateVersion))
Expand Down
30 changes: 15 additions & 15 deletions coderd/database/dbmock/dbmock.go

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

2 changes: 1 addition & 1 deletion coderd/database/queries.sql.go

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

2 changes: 1 addition & 1 deletion coderd/database/queries/templateversions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ SET
archived = true,
updated_at = sqlc.arg('updated_at')
FROM
-- Delete all versions that are returned from this query.
-- Archive all versions that are returned from this query.
(
SELECT
scoped_template_versions.id
Expand Down
11 changes: 11 additions & 0 deletions coderd/httpapi/queryparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func (p *QueryParamParser) Int(vals url.Values, def int, queryParam string) int
return v
}

func (p *QueryParamParser) Boolean(vals url.Values, def bool, queryParam string) bool {
v, err := parseQueryParam(p, vals, strconv.ParseBool, def, queryParam)
if err != nil {
p.Errors = append(p.Errors, codersdk.ValidationError{
Field: queryParam,
Detail: fmt.Sprintf("Query param %q must be a valid boolean (%s)", queryParam, err.Error()),
})
}
return v
}

func (p *QueryParamParser) Required(queryParam string) *QueryParamParser {
p.RequiredParams[queryParam] = true
return p
Expand Down
42 changes: 42 additions & 0 deletions coderd/httpapi/queryparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,48 @@ func TestParseQueryParams(t *testing.T) {
testQueryParams(t, expParams, parser, parser.String)
})

t.Run("Boolean", func(t *testing.T) {
t.Parallel()
expParams := []queryParamTestCase[bool]{
{
QueryParam: "valid_true",
Value: "true",
Expected: true,
},
{
QueryParam: "casing",
Value: "True",
Expected: true,
},
{
QueryParam: "all_caps",
Value: "TRUE",
Expected: true,
},
{
QueryParam: "no_value_true_def",
NoSet: true,
Default: true,
Expected: true,
},
{
QueryParam: "no_value",
NoSet: true,
Expected: false,
},

{
QueryParam: "invalid_boolean",
Value: "yes",
Expected: false,
ExpectedErrorContains: "must be a valid boolean",
},
}

parser := httpapi.NewQueryParamParser()
testQueryParams(t, expParams, parser, parser.Boolean)
})

t.Run("Int", func(t *testing.T) {
t.Parallel()
expParams := []queryParamTestCase[int]{
Expand Down
6 changes: 3 additions & 3 deletions coderd/templates.go
Original file lin 17AE e number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
})
return
}
if templateVersion.Deleted {
if templateVersion.Archived {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: fmt.Sprintf("Template version %s is deleted.", createTemplate.VersionID),
Message: fmt.Sprintf("Template version %s is archived.", createTemplate.VersionID),
Validations: []codersdk.ValidationError{
{Field: "template_version_id", Detail: "Template version is deleted"},
{Field: "template_version_id", Detail: "Template version is archived"},
},
})
return
Expand Down
31 changes: 24 additions & 7 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
return
}

// If this throws an error, the boolean is false. Which is the default we want.
parser := httpapi.NewQueryParamParser()
includeArchived := parser.Boolean(r.URL.Query(), false, "include_archived")
if len(parser.Errors) > 0 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Invalid query parameters.",
Validations: parser.Errors,
})
return
}

var err error
apiVersions := []codersdk.TemplateVersion{}
err = api.Database.InTx(func(store database.Store) error {
Expand All @@ -738,16 +749,21 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
}
}

// Exclude archived templates versions
archiveFilter := sql.NullBool{
Bool: false,
Valid: true,
}
if includeArchived {
archiveFilter = sql.NullBool{Valid: false}
}

versions, err := store.GetTemplateVersionsByTemplateID(ctx, database.GetTemplateVersionsByTemplateIDParams{
TemplateID: template.ID,
AfterID: paginationParams.AfterID,
LimitOpt: int32(paginationParams.Limit),
OffsetOpt: int32(paginationParams.Offset),
// Exclude deleted templates versions
Deleted: sql.NullBool{
Bool: false,
Valid: true,
},
Archived: archiveFilter,
})
if errors.Is(err, sql.ErrNoRows) {
httpapi.Write(ctx, rw, http.StatusOK, apiVersions)
Expand Down Expand Up @@ -1033,7 +1049,7 @@ func (api *API) postArchiveTemplateVersions(rw http.ResponseWriter, r *http.Requ
status = database.NullProvisionerJobStatus{}
}

deleted, err := api.Database.ArchiveUnusedTemplateVersions(ctx, database.ArchiveUnusedTemplateVersionsParams{
archived, err := api.Database.ArchiveUnusedTemplateVersions(ctx, database.ArchiveUnusedTemplateVersionsParams{
UpdatedAt: dbtime.Now(),
TemplateID: template.ID,
JobStatus: status,
Expand All @@ -1055,7 +1071,7 @@ func (api *API) postArchiveTemplateVersions(rw http.ResponseWriter, r *http.Requ

httpapi.Write(ctx, rw, http.StatusOK, codersdk.ArchiveTemplateVersionsResponse{
TemplateID: template.ID,
ArchivedIDs: deleted,
ArchivedIDs: archived,
})
}

Expand Down Expand Up @@ -1478,6 +1494,7 @@ func convertTemplateVersion(version database.TemplateVersion, job codersdk.Provi
Username: version.CreatedByUsername,
AvatarURL: version.CreatedByAvatarURL.String,
},
Archived: version.Archived,
Warnings: warnings,
}
}
Expand Down
Loading
0