fix(32.2): WR-05 hand the deactivate revocation the plain transaction
The deactivate lifecycle fired BackendAccessRevokedEvent with actionDB's Unscoped session, so a listener's Delete through ev.Tx was a hard delete only for that reason. It now passes the save's transaction like every other site.
This commit is contained in:
@@ -18,7 +18,8 @@ import (
|
|||||||
//
|
//
|
||||||
// It is fired synchronously through app.Events.Fire as a
|
// It is fired synchronously through app.Events.Fire as a
|
||||||
// *BackendAccessRevokedEvent inside the transaction of the save, before the
|
// *BackendAccessRevokedEvent inside the transaction of the save, before the
|
||||||
// commit, with that transaction in Tx. A listener's error is returned to the
|
// commit, with that transaction in Tx (the transaction itself at every
|
||||||
|
// site, never an Unscoped session). A listener's error is returned to the
|
||||||
// save and rolls it back, so the change and the revocation commit together
|
// save and rolls it back, so the change and the revocation commit together
|
||||||
// or not at all. A listener must write through Tx and must not open its own
|
// or not at all. A listener must write through Tx and must not open its own
|
||||||
// transaction. Tx is never nil: a site without its save's transaction
|
// transaction. Tx is never nil: a site without its save's transaction
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ func TestBackendAccessRevokedSmoke(t *testing.T) {
|
|||||||
if got[0].Reason != reason || !slices.Equal(got[0].AdminIDs, ids) || got[0].Tx == nil {
|
if got[0].Reason != reason || !slices.Equal(got[0].AdminIDs, ids) || got[0].Tx == nil {
|
||||||
t.Fatalf("%s: event = %+v, want ids %v with a transaction", reason, got[0], ids)
|
t.Fatalf("%s: event = %+v, want ids %v with a transaction", reason, got[0], ids)
|
||||||
}
|
}
|
||||||
|
// Every site hands listeners the plain transaction: never an
|
||||||
|
// Unscoped session, on which Delete would be a hard delete.
|
||||||
|
if got[0].Tx.Statement != nil && got[0].Tx.Statement.Unscoped {
|
||||||
|
t.Fatalf("%s: event Tx is Unscoped", reason)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("delete", func(t *testing.T) {
|
t.Run("delete", func(t *testing.T) {
|
||||||
|
|||||||
@@ -288,7 +288,14 @@ func (c usersAdmin) lifecycles() []usersLifecycle {
|
|||||||
Updates(map[string]any{"is_activated": false, "tokens_valid_after": revocationCutoff()}).Error; err != nil {
|
Updates(map[string]any{"is_activated": false, "tokens_valid_after": revocationCutoff()}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := fireBackendAccessRevoked(ctx, c.application(), db, BackendAccessDeactivated, user.ID); err != nil {
|
// Listeners get the save's transaction itself, as at every
|
||||||
|
// other site, not db: that is an Unscoped session, on which
|
||||||
|
// a listener's Delete would be a hard delete.
|
||||||
|
tx, ok := TxFromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("cabana: administrators: an action needs its transaction")
|
||||||
|
}
|
||||||
|
if err := fireBackendAccessRevoked(ctx, c.application(), tx, BackendAccessDeactivated, user.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// A deactivated administrator can no longer act anywhere,
|
// A deactivated administrator can no longer act anywhere,
|
||||||
|
|||||||
Reference in New Issue
Block a user