Skip to content

fix: respect uppercase letters in username filter for audit #7880

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 2 commits into from
Jun 7, 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
Next Next commit
fix: respect uppercase letters in username filter for audit
  • Loading branch information
Kira-Pilot committed Jun 6, 2023
commit 37d1cb653ebe19be6f126e166ab83ce1aeb10ff9
6 changes: 6 additions & 0 deletions coderd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
// @Router /audit [get]
func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
apiKey := httpmw.APIKey(r)

page, ok := parsePagination(rw, r)
if !ok {
Expand All @@ -55,6 +56,11 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
filter.Offset = int32(page.Offset)
filter.Limit = int32(page.Limit)

if filter.Username == "me" {
filter.UserID = apiKey.UserID
filter.Username = ""
}

dblogs, err := api.Database.GetAuditLogsOffset(ctx, filter)
if err != nil {
httpapi.InternalServerError(rw, err)
Expand Down
28 changes: 18 additions & 10 deletions coderd/database/queries.sql.go

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

8 changes: 7 additions & 1 deletion coderd/database/queries/auditlogs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ WHERE
action = @action :: audit_action
ELSE true
END
-- Filter by user_id
AND CASE
WHEN @user_id :: uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
user_id = @user_id
ELSE true
END
-- Filter by username
AND CASE
WHEN @username :: text != '' THEN
users.username = @username
user_id = (SELECT id FROM users WHERE lower(username) = lower(@username) AND deleted = false)
ELSE true
END
-- Filter by user_email
Expand Down