Skip to content

Commit e914390

Browse files
committed
feat: add author filter command to template filtering
1 parent 408e19f commit e914390

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

coderd/database/modelqueries.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
8282
pq.Array(arg.IDs),
8383
arg.Deprecated,
8484
arg.HasAITask,
85+
arg.AuthorID,
86+
arg.AuthorUsername,
8587
)
8688
if err != nil {
8789
return nil, err

coderd/database/queries.sql.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ WHERE
5959
tv.has_ai_task = sqlc.narg('has_ai_task') :: boolean
6060
ELSE true
6161
END
62+
-- Filter by author_id
63+
AND CASE
64+
WHEN @author_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
65+
t.created_by = @author_id
66+
ELSE true
67+
END
68+
-- Filter by author_username
69+
AND CASE
70+
WHEN @author_username :: text != '' THEN
71+
t.created_by = (SELECT id FROM users WHERE lower(users.username) = lower(@author_username) AND deleted = false)
72+
ELSE true
73+
END
74+
6275
-- Authorize Filter clause will be injected below in GetAuthorizedTemplates
6376
-- @authorize_filter
6477
ORDER BY (t.name, t.id) ASC

coderd/searchquery/search.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,14 @@ func Templates(ctx context.Context, db database.Store, query string) (database.G
278278
parser := httpapi.NewQueryParamParser()
279279
filter := database.GetTemplatesWithFilterParams{
280280
Deleted: parser.Boolean(values, false, "deleted"),
281+
OrganizationID: parseOrganization(ctx, db, parser, values, "organization"),
281282
ExactName: parser.String(values, "", "exact_name"),
282283
FuzzyName: parser.String(values, "", "name"),
283284
IDs: parser.UUIDs(values, []uuid.UUID{}, "ids"),
284285
Deprecated: parser.NullableBoolean(values, sql.NullBool{}, "deprecated"),
285-
OrganizationID: parseOrganization(ctx, db, parser, values, "organization"),
286286
HasAITask: parser.NullableBoolean(values, sql.NullBool{}, "has-ai-task"),
287+
AuthorID: parser.UUID(values, uuid.Nil, "author_id"),
288+
AuthorUsername: parser.String(values, "", "author"),
287289
}
288290

289291
parser.ErrorExcessParams(values)

0 commit comments

Comments
 (0)