Revert "Revert "merge 1""

This reverts commit 0c463d1f10.
This commit is contained in:
2022-10-24 01:04:22 +01:00
parent 0c463d1f10
commit b89d71b371
166 changed files with 4250 additions and 1833 deletions

View File

@@ -16,18 +16,14 @@ class AccountSuspensionService
/**
* Suspends a user account, with given $reason.
* Permanent if no duration given.
*
* This method will take the target user and add a suspension to the database,
* effectively banning the user from the app. Suspensions may be temporary or permanent.
* Suspensions also block registration attempts.
*
* @param string $reason Suspension reason.
* @param string $duration Duration. This is a timestamp.
* @param User $target Who to suspend.
* @param string $type Permanent or temporary?
* @param string $reason Suspension reason.
* @param int|null $duration Duration in days
* @return Ban The ban itself
*/
public function suspend($reason, $duration, User $target, $type = "on"): Ban {
public function suspend(User $target, string $reason, int $duration = null): Ban {
Log::alert("An user account has just been suspended.", [
'taget_email' => $target->email,
@@ -35,19 +31,17 @@ class AccountSuspensionService
'reason' => $reason
]);
if ($type == "on") {
if ($duration > 0) {
$expiryDate = now()->addDays($duration);
}
$ban = Ban::create([
return Ban::create([
'userID' => $target->id,
'reason' => $reason,
'bannedUntil' => ($type == "on") ? $expiryDate->format('Y-m-d H:i:s') : null,
'bannedUntil' => ($duration > 0) ? $expiryDate->format('Y-m-d H:i:s') : null,
'authorUserID' => Auth::user()->id,
'isPermanent' => ($type == "off") ? true : false
'isPermanent' => ($duration == 0) ? true : false
]);
return $ban;
}
/**
@@ -64,6 +58,16 @@ class AccountSuspensionService
$user->bans->delete();
}
/**
* Checks whether a user is suspended
*
* @param User $user The user to check
* @return bool Whether the mentioned user is suspended
*/
public function isSuspended(User $user): bool {
return !is_null($user->bans);
}
@@ -107,19 +111,6 @@ class AccountSuspensionService
return $user->save();
}
/**
* Checks whether a user is suspended
*
* @param User $user The user to check
* @return bool Whether the mentioned user is suspended
*/
public function isSuspended(User $user): bool {
return !is_null($user->bans);
}
/**
* Checks whether an account is locked
*
@@ -131,21 +122,21 @@ class AccountSuspensionService
}
/**
* Takes a suspension directly and makes it permanent.
* Retrieves the reason for the user's suspension.
*
* @param Ban $ban The suspension to make permanent
* @param User $user The user account to check
* @return string|bool Reason for the suspension, false if not suspended
*/
public function makePermanent(Ban $ban): void {
public function getSuspensionReason(User $user): string|bool {
return ($this->isSuspended($user)) ? $user->bans->reason : false;
}
Log::alert('A suspension has just been made permanent.', [
'target_email' => $ban->user->email
]);
$ban->bannedUntil = null;
$ban->isPermanent = true;
$ban->save();
public function getSuspensionDuration(User $user): string|null {
if ($this->isSuspended($user) && !is_null($user->bans->bannedUntil)) {
return $user->bans->bannedUntil->diffForHumans();
}
return null;
}
/**