Feat admin rbac migration (#1)
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user