mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user