package cabana import ( "context" "git.golem15.com/golem15/summercms/modules/backpack" "git.golem15.com/golem15/summercms/modules/pact" ) // backendSubjectGuard is the guard name backend subject events carry: the // admin's own bouncer guard. const backendSubjectGuard = "backend" // fireSubjectChanged fires one pact.MCPSubjectChanged of the given kind for // every administrator id through the application's event bus, so the MCP // endpoint re-lists a linked admin's tools or ends their sessions. A missing // application or bus is a no-op and a listener's error is logged: the save // that caused the event never fails because of it. func fireSubjectChanged(ctx context.Context, app *backpack.App, kind string, adminIDs ...uint) { if app == nil || app.Events == nil { return } if ctx == nil { ctx = context.Background() } for _, id := range adminIDs { if id == 0 { continue } event := pact.MCPSubjectChanged{Guard: backendSubjectGuard, UserID: id, Kind: kind} if err := app.Events.Fire(ctx, event); err != nil { moduleLog.WarnContext(ctx, "cabana: subject changed listener failed", "kind", kind, "admin_id", id, "error", err) } } }