feat(32.2-01): in-transaction BackendAccessRevokedEvent at every admin access change

- cabana: BackendAccessRevokedEvent with reasons deleted, deactivated,
  password_changed, password_set, password_reset and permissions, fired
  synchronously inside the save's transaction; a listener error rolls back
- fired on admin delete, deactivate, a password set by another admin, an own
  password change, admin:reset-password, a role/permissions/superuser change
  and a role's permission change (every holder); MCPSubjectChanged unchanged
- role delete fires nothing (refused while the role has holders); no sign
  out everywhere action exists
- smoke test TestBackendAccessRevokedSmoke (Postgres)
This commit is contained in:
Jakub Zych
2026-11-21 00:32:26 +01:00
parent 3f7ce6020d
commit fcc7bbde25
10 changed files with 270 additions and 8 deletions

View File

@@ -176,9 +176,11 @@ func (rolesAdmin) AdminSetPermissionValues(_ context.Context, field string, reco
return nil
}
// FormAfterUpdate fires pact.MCPSubjectChanged (permissions) for every
// administrator holding the role when its grants changed, their ids read
// through the save's transaction. The save itself is unchanged.
// FormAfterUpdate fires BackendAccessRevokedEvent (permissions) inside the
// save's transaction and pact.MCPSubjectChanged (permissions) after the
// commit for every administrator holding the role when its grants changed,
// their ids read through the save's transaction. A listener error of the
// first rolls the save back.
func (c rolesAdmin) FormAfterUpdate(ctx context.Context, model any) error {
role, err := asRole(model)
if err != nil {
@@ -195,6 +197,10 @@ 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)
if err := fireBackendAccessRevoked(ctx, c.screens.application(), tx, BackendAccessPermissions, holders...); err != nil {
return err
}
fireSubjectChanged(ctx, c.screens.application(), pact.MCPSubjectPermissions, holders...)
return nil
}