mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: skip audit log filter for owner/admin users (#14132)
* chore: audit log filter to be skipped if user is owner/admin Optimize for speed in the case the user can read all audit_logs * fixup! chore: audit log filter to be skipped if user is owner/admin
This commit is contained in:
@ -1248,6 +1248,13 @@ func (q *querier) GetApplicationName(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
func (q *querier) GetAuditLogsOffset(ctx context.Context, arg database.GetAuditLogsOffsetParams) ([]database.GetAuditLogsOffsetRow, error) {
|
||||
// Shortcut if the user is an owner. The SQL filter is noticeable,
|
||||
// and this is an easy win for owners. Which is the common case.
|
||||
err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceAuditLog)
|
||||
if err == nil {
|
||||
return q.db.GetAuditLogsOffset(ctx, arg)
|
||||
}
|
||||
|
||||
prep, err := prepareSQLFilter(ctx, q.auth, policy.ActionRead, rbac.ResourceAuditLog.Type)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("(dev error) prepare sql filter: %w", err)
|
||||
|
@ -267,14 +267,14 @@ func (s *MethodTestSuite) TestAuditLogs() {
|
||||
_ = dbgen.AuditLog(s.T(), db, database.AuditLog{})
|
||||
check.Args(database.GetAuditLogsOffsetParams{
|
||||
LimitOpt: 10,
|
||||
}).Asserts()
|
||||
}).Asserts(rbac.ResourceAuditLog, policy.ActionRead)
|
||||
}))
|
||||
s.Run("GetAuthorizedAuditLogsOffset", s.Subtest(func(db database.Store, check *expects) {
|
||||
_ = dbgen.AuditLog(s.T(), db, database.AuditLog{})
|
||||
_ = dbgen.AuditLog(s.T(), db, database.AuditLog{})
|
||||
check.Args(database.GetAuditLogsOffsetParams{
|
||||
LimitOpt: 10,
|
||||
}, emptyPreparedAuthorized{}).Asserts()
|
||||
}, emptyPreparedAuthorized{}).Asserts(rbac.ResourceAuditLog, policy.ActionRead)
|
||||
}))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user