fix(32.2): WR-04 never fire BackendAccessRevokedEvent without the save's transaction

fireBackendAccessRevoked refuses a nil tx before any listener runs, and the Administrators and Roles update hooks fail closed (like the delete hook) when the save carries no transaction, instead of firing with whatever TxFromContext answered.
This commit is contained in:
Jakub Zych
2026-11-21 09:17:33 +01:00
parent 19bb3f9485
commit a261a8fdfe
6 changed files with 90 additions and 7 deletions

View File

@@ -197,7 +197,12 @@ func (c rolesAdmin) FormAfterUpdate(ctx context.Context, model any) error {
if err := db.Unscoped().Model(&BackendUser{}).Where("role_id = ?", role.ID).Pluck("id", &holders).Error; err != nil {
return err
}
tx, _ := TxFromContext(ctx)
// writeDB proved the save carries its transaction; the event gets that
// transaction itself, like every other site.
tx, ok := TxFromContext(ctx)
if !ok {
return errors.New("cabana: roles: a save needs its transaction")
}
if err := fireBackendAccessRevoked(ctx, c.screens.application(), tx, BackendAccessPermissions, holders...); err != nil {
return err
}