complete story 2.4 with qa test and added a feature disallowing admin from deactivating his own account
This commit is contained in:
@@ -117,6 +117,30 @@ class User extends Authenticatable
|
||||
return $this->status === UserStatus::Active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is deactivated.
|
||||
*/
|
||||
public function isDeactivated(): bool
|
||||
{
|
||||
return $this->status === UserStatus::Deactivated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate the user account.
|
||||
*/
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->update(['status' => UserStatus::Deactivated]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate the user account.
|
||||
*/
|
||||
public function reactivate(): void
|
||||
{
|
||||
$this->update(['status' => UserStatus::Active]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter admin users.
|
||||
*/
|
||||
@@ -196,4 +220,24 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(TimelineUpdate::class, 'admin_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the model and register cascade delete event.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (User $user) {
|
||||
// Cascade delete consultations
|
||||
$user->consultations()->delete();
|
||||
|
||||
// Cascade delete timelines and their updates
|
||||
$user->timelines->each(function ($timeline) {
|
||||
$timeline->updates()->delete();
|
||||
$timeline->delete();
|
||||
});
|
||||
|
||||
// Cascade delete custom notifications
|
||||
$user->customNotifications()->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user