Skip to content

Commit 1f0cb46

Browse files
committed
sql query
1 parent 3e15ee3 commit 1f0cb46

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

coderd/audit.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
3434

3535
queryStr := r.URL.Query().Get("q")
3636
filter, errs := auditSearchQuery(queryStr)
37+
fmt.Println("BLOOP FILTER", filter)
38+
3739
if len(errs) > 0 {
3840
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
3941
Message: "Invalid audit search query.",
@@ -50,6 +52,7 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
5052
Action: filter.Action,
5153
Username: filter.Username,
5254
Email: filter.Email,
55+
TimeFrom: filter.TimeFrom,
5356
})
5457
if err != nil {
5558
httpapi.InternalServerError(rw, err)
@@ -257,12 +260,17 @@ func auditSearchQuery(query string) (database.GetAuditLogsOffsetParams, []coders
257260
return database.GetAuditLogsOffsetParams{}, nil
258261
}
259262
query = strings.ToLower(query)
263+
fmt.Println("KIRA query", query)
260264
// Because we do this in 2 passes, we want to maintain quotes on the first
261265
// pass.Further splitting occurs on the second pass and quotes will be
262266
// dropped.
263267
elements := splitQueryParameterByDelimiter(query, ' ', true)
268+
fmt.Println("MARGE elements", elements)
269+
264270
for _, element := range elements {
265271
parts := splitQueryParameterByDelimiter(element, ':', false)
272+
fmt.Println("MARGOT parts", parts)
273+
266274
switch len(parts) {
267275
case 1:
268276
// No key:value pair.
@@ -285,6 +293,8 @@ func auditSearchQuery(query string) (database.GetAuditLogsOffsetParams, []coders
285293
Action: actionFromString(parser.String(searchParams, "", "action")),
286294
Username: parser.String(searchParams, "", "username"),
287295
Email: parser.String(searchParams, "", "email"),
296+
TimeFrom: time.Date(
297+
2022, 10, 27, 00, 00, 00, 000000000, time.UTC),
288298
}
289299

290300
return filter, parser.Errors

coderd/database/queries.sql.go

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/auditlogs.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SELECT
1111
users.avatar_url AS user_avatar_url
1212
FROM
1313
audit_logs
14-
LEFT JOIN
14+
LEFT JOIN
1515
users ON audit_logs.user_id = users.id
1616
WHERE
1717
-- Filter resource_type
@@ -50,6 +50,12 @@ WHERE
5050
users.email = @email
5151
ELSE true
5252
END
53+
-- Filter by time_from
54+
AND CASE
55+
WHEN @time_from :: timestamp with time zone != '0001-01-01 00:00:00' THEN
56+
"time" > @time_from
57+
ELSE true
58+
END
5359
ORDER BY
5460
"time" DESC
5561
LIMIT

enterprise/audit/table.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ var AuditableResources = auditMap(map[any]map[string]Action{
109109
"organization_id": ActionIgnore, // Never changes.
110110
"avatar_url": ActionTrack,
111111
},
112-
// We don't show any diff for the WorkspaceBuild resource
112+
// We don't show any diff for the WorkspaceBuild resource,
113+
// save for the template_version_id
113114
&database.WorkspaceBuild{}: {
114115
"id": ActionIgnore,
115116
"created_at": ActionIgnore,
116117
"updated_at": ActionIgnore,
117118
"workspace_id": ActionIgnore,
118-
"template_version_id": ActionIgnore,
119+
"template_version_id": ActionTrack,
119120
"build_number": ActionIgnore,
120121
"transition": ActionIgnore,
121122
"initiator_id": ActionIgnore,

site/src/api/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,10 @@ export const getAuditLogs = async (
563563
searchParams.set("offset", options.offset.toString())
564564
}
565565
if (options.q) {
566+
console.log('q', options.q)
566567
searchParams.set("q", options.q)
567568
}
569+
console.log('searchParams', searchParams)
568570

569571
const response = await axios.get(`/api/v2/audit?${searchParams.toString()}`)
570572
return response.data

0 commit comments

Comments
 (0)