Feat admin rbac migration (#1)
Some checks failed
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / build-and-deploy (push) Has been cancelled
CI/CD / test-sqlite (push) Has been cancelled
CI/CD / test-go-pg (push) Has been cancelled

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
2026-03-26 17:30:36 +00:00
committed by xcaliber
parent b9180d4184
commit 5836ddad21
37 changed files with 381 additions and 547 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"switchboard-core/auth"
"switchboard-core/events"
"switchboard-core/models"
"switchboard-core/store"
@@ -44,26 +45,23 @@ func RoleFallbackHandler(svc *Service, stores store.Stores) events.Handler {
body = fmt.Sprintf("Primary model error: %s", p.Error)
}
// Notify all admin users
// Notify all Admins group members
ctx := context.Background()
admins, _, err := stores.Users.List(ctx, store.ListOptions{Limit: 500})
admins, err := stores.Groups.ListMembers(ctx, auth.AdminsGroupID)
if err != nil {
log.Printf("[notifications] failed to list users for role.fallback: %v", err)
log.Printf("[notifications] failed to list admins for role.fallback: %v", err)
return
}
for _, u := range admins {
if u.Role != "admin" {
continue
}
n := models.Notification{
UserID: u.ID,
UserID: u.UserID,
Type: models.NotifTypeRoleFallback,
Title: title,
Body: body,
}
if err := svc.Notify(ctx, &n); err != nil {
log.Printf("[notifications] failed to create role.fallback notification for %s: %v", u.ID, err)
log.Printf("[notifications] failed to create role.fallback notification for %s: %v", u.UserID, err)
}
}
}