mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-02 11:39:19 +01:00
Fix demoting event not being registered (again) - Complete #331
This commit is contained in:
parent
be3aaf319c
commit
bdfc70732d
@ -90,18 +90,13 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform any actions required after the model boots.
|
* User exposed observable events.
|
||||||
*
|
*
|
||||||
* @return void
|
* These are extra user-defined events observers may subscribe to.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static function booted()
|
protected $observables = ['demoting'];
|
||||||
{
|
|
||||||
static::creating(function (User $user) {
|
|
||||||
$user->addObservableEvents([
|
|
||||||
'demoting'
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user's preferred locale.
|
* Get the user's preferred locale.
|
||||||
@ -137,7 +132,9 @@ public function isAdministrator()
|
|||||||
*/
|
*/
|
||||||
public function promoteToAdministrator(bool $promote = true) : bool
|
public function promoteToAdministrator(bool $promote = true) : bool
|
||||||
{
|
{
|
||||||
if ($promote == false && $this->fireModelEvent('demoting') === false) {
|
$eventResult = $promote ? $this->fireModelEvent('promoting') : $this->fireModelEvent('demoting');
|
||||||
|
|
||||||
|
if ($promote == false && $eventResult === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +73,15 @@ public function test_promoteToAdministrator_sets_administrator_status()
|
|||||||
*/
|
*/
|
||||||
public function test_promoteToAdministrator_demote_administrator_status()
|
public function test_promoteToAdministrator_demote_administrator_status()
|
||||||
{
|
{
|
||||||
$user = User::factory()->administrator()->create();
|
$admin = User::factory()->administrator()->create();
|
||||||
|
// We need another admin to prevent demoting event returning false
|
||||||
|
// and blocking the demotion
|
||||||
|
$another_admin = User::factory()->administrator()->create();
|
||||||
|
|
||||||
$user->promoteToAdministrator(false);
|
$admin->promoteToAdministrator(false);
|
||||||
|
$admin->save();
|
||||||
|
|
||||||
$this->assertEquals($user->isAdministrator(), false);
|
$this->assertFalse($admin->isAdministrator());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user