Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions pkg/controller/admin/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@ func (c *Controller) HandleEventsShow() http.Handler {
case "":
// All events
case "0":
scopes = append(scopes, database.WithAuditRealmID(0))
realm = &database.Realm{
Model: gorm.Model{ID: 0},
Name: "System",
}
default:
if id, err := strconv.ParseUint(realmID, 10, 64); err != nil {
scopes = append(scopes, database.WithAuditRealmID(uint(id)))
}

if realm, err = c.db.FindRealm(realmID); err != nil {
realm, err = c.db.FindRealm(realmID)
if err != nil {
controller.InternalError(w, r, c.h, err)
return
}
}

// If a specific realm was provided, filter by that realm.
if realm != nil {
scopes = append(scopes, database.WithAuditRealmID(realm.ID))
}

// List the events
events, paginator, err := c.db.ListAudits(pageParams, scopes...)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/database/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ func WithAuditTime(from, to string) Scope {
}
}

// WithAuditRealmID returns a scope that adds querying for Audit events by realm.
func WithAuditRealmID(r uint) Scope {
// WithAuditRealmID returns a scope that adds querying for Audit events by
// realm. The provided ID is expected to be stringable (int, uint, string).
func WithAuditRealmID(id uint) Scope {
return func(db *gorm.DB) *gorm.DB {
return db.Where("audit_entries.realm_id = ?", r)
return db.Where("audit_entries.realm_id = ?", id)
}
}

Expand Down