fix: add constraint actions to db structure
This commit adds several missing "cascade delete" actions to relationships on database tables. This effectively fixes errors while trying to delete user accounts because of pending child records. Additionally, the observers for applications and vacancies were removed, since they are now obsolete. The account deletion system was also refactored.
This commit is contained in:
@@ -62,6 +62,47 @@ class AccountSuspensionService
|
||||
$user->bans->delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets an administrative lock on a user account.
|
||||
* Used to prevent logins after a deletion process is initiated, but may be used for
|
||||
* other things where a suspension is not necessary/warranted, such as a security breach event.
|
||||
* These locks cannot be overridden manually be administrators.
|
||||
*
|
||||
* @param User $user The account to lock
|
||||
* @return bool
|
||||
*/
|
||||
public function lockAccount(User $user): bool
|
||||
{
|
||||
Log::alert('User account locked!', [
|
||||
'email' => $user->email
|
||||
]);
|
||||
|
||||
$user->administratively_locked = 1;
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks a user account. Reverse of lockAccount().
|
||||
*
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public function unlockAccount(User $user): bool
|
||||
{
|
||||
Log::alert('User account unlocked!', [
|
||||
'email' => $user->email
|
||||
]);
|
||||
|
||||
$user->administratively_locked = 0;
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a user is suspended
|
||||
*
|
||||
@@ -73,6 +114,16 @@ class AccountSuspensionService
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether an account is locked
|
||||
*
|
||||
* @param User $user The user to check
|
||||
* @return bool Whether the mentioned account is locked
|
||||
*/
|
||||
public function isLocked(User $user): bool {
|
||||
return $user->administratively_locked == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a suspension directly and makes it permanent.
|
||||
*
|
||||
|
Reference in New Issue
Block a user