feat(webui): audit feed API, export and read_audit grant
This commit is contained in:
1 parent
6ffbf0e2a2
commit
717f9d5219
23 files changed
+969
-626
No files matched your search
@@ -10,66 +10,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const auditForRecords = `-- name: AuditForRecords :many
|
||||
SELECT id, at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id
|
||||
FROM sys_audit
|
||||
WHERE table_name = $1::text AND record_key = ANY($2::text[])
|
||||
ORDER BY id DESC
|
||||
LIMIT $3::bigint
|
||||
`
|
||||
|
||||
type AuditForRecordsParams struct {
|
||||
TableName string
|
||||
RecordKeys []string
|
||||
EntryLimit int64
|
||||
}
|
||||
|
||||
type AuditForRecordsRow struct {
|
||||
ID int64
|
||||
At time.Time
|
||||
TableName string
|
||||
RecordKey string
|
||||
Field string
|
||||
OldValue []byte
|
||||
NewValue []byte
|
||||
RecordVersion int64
|
||||
Actor string
|
||||
Source string
|
||||
RequestID string
|
||||
}
|
||||
|
||||
func (q *Queries) AuditForRecords(ctx context.Context, arg AuditForRecordsParams) ([]AuditForRecordsRow, error) {
|
||||
rows, err := q.db.Query(ctx, auditForRecords, arg.TableName, arg.RecordKeys, arg.EntryLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []AuditForRecordsRow
|
||||
for rows.Next() {
|
||||
var i AuditForRecordsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.At,
|
||||
&i.TableName,
|
||||
&i.RecordKey,
|
||||
&i.Field,
|
||||
&i.OldValue,
|
||||
&i.NewValue,
|
||||
&i.RecordVersion,
|
||||
&i.Actor,
|
||||
&i.Source,
|
||||
&i.RequestID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const insertAudit = `-- name: InsertAudit :exec
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id, org_id)
|
||||
VALUES (now(), $1::text, $2::text, $3::text,
|
||||
|
||||
Reference in new issue
Block a user