feat: add author filter command to template filtering (#19202)

Can do `author:username` to filter templates created by a certain
author. Adding to help clean out some templates that I created on our
dev instance. This makes sorting a bit easier.
This commit is contained in:
Steven Masley
2025-08-06 10:41:01 -05:00
committed by GitHub
parent 408e19fd98
commit 5b80c47e8c
6 changed files with 81 additions and 1 deletions
+2
View File
@@ -82,6 +82,8 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
pq.Array(arg.IDs),
arg.Deprecated,
arg.HasAITask,
arg.AuthorID,
arg.AuthorUsername,
)
if err != nil {
return nil, err
+17
View File
@@ -12059,6 +12059,19 @@ WHERE
tv.has_ai_task = $7 :: boolean
ELSE true
END
-- Filter by author_id
AND CASE
WHEN $8 :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
t.created_by = $8
ELSE true
END
-- Filter by author_username
AND CASE
WHEN $9 :: text != '' THEN
t.created_by = (SELECT id FROM users WHERE lower(users.username) = lower($9) AND deleted = false)
ELSE true
END
-- Authorize Filter clause will be injected below in GetAuthorizedTemplates
-- @authorize_filter
ORDER BY (t.name, t.id) ASC
@@ -12072,6 +12085,8 @@ type GetTemplatesWithFilterParams struct {
IDs []uuid.UUID `db:"ids" json:"ids"`
Deprecated sql.NullBool `db:"deprecated" json:"deprecated"`
HasAITask sql.NullBool `db:"has_ai_task" json:"has_ai_task"`
AuthorID uuid.UUID `db:"author_id" json:"author_id"`
AuthorUsername string `db:"author_username" json:"author_username"`
}
func (q *sqlQuerier) GetTemplatesWithFilter(ctx context.Context, arg GetTemplatesWithFilterParams) ([]Template, error) {
@@ -12083,6 +12098,8 @@ func (q *sqlQuerier) GetTemplatesWithFilter(ctx context.Context, arg GetTemplate
pq.Array(arg.IDs),
arg.Deprecated,
arg.HasAITask,
arg.AuthorID,
arg.AuthorUsername,
)
if err != nil {
return nil, err
+13
View File
@@ -59,6 +59,19 @@ WHERE
tv.has_ai_task = sqlc.narg('has_ai_task') :: boolean
ELSE true
END
-- Filter by author_id
AND CASE
WHEN @author_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
t.created_by = @author_id
ELSE true
END
-- Filter by author_username
AND CASE
WHEN @author_username :: text != '' THEN
t.created_by = (SELECT id FROM users WHERE lower(users.username) = lower(@author_username) AND deleted = false)
ELSE true
END
-- Authorize Filter clause will be injected below in GetAuthorizedTemplates
-- @authorize_filter
ORDER BY (t.name, t.id) ASC