From 075e9492c36cf26b40b4028f1ac53572008d1d31 Mon Sep 17 00:00:00 2001 From: miguel456 Date: Fri, 19 Aug 2022 02:08:39 +0100 Subject: [PATCH] feat(users): add suspended user warning --- app/Ban.php | 2 +- app/Http/Controllers/UserController.php | 1 + app/Services/AccountSuspensionService.php | 6 ++++++ .../views/dashboard/user/manage.blade.php | 20 ++++++++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/Ban.php b/app/Ban.php index f4c2dfb..e5044cf 100755 --- a/app/Ban.php +++ b/app/Ban.php @@ -36,7 +36,7 @@ class Ban extends Model ]; public $dates = [ - 'suspendedUntil', + 'bannedUntil', ]; public function user() diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 62743c5..a75c112 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -174,6 +174,7 @@ class UserController extends Controller 'isLocked' => $suspensionService->isLocked($user), 'isSuspended' => $suspensionService->isSuspended($user), 'suspensionReason' => $suspensionService->getSuspensionReason($user), + 'suspensionDuration' => $suspensionService->getSuspensionDuration($user), 'has2FA' => $user->has2FA(), 'applications' => $user->applications()->get() ]); diff --git a/app/Services/AccountSuspensionService.php b/app/Services/AccountSuspensionService.php index 1598219..2ee946c 100755 --- a/app/Services/AccountSuspensionService.php +++ b/app/Services/AccountSuspensionService.php @@ -124,7 +124,13 @@ class AccountSuspensionService return ($this->isSuspended($user)) ? $user->bans->reason : false; } + public function getSuspensionDuration(User $user): string|null { + if ($this->isSuspended($user)) { + return $user->bans->bannedUntil->diffForHumans(); + } + return null; + } /** * Checks whether an account is locked * diff --git a/resources/views/dashboard/user/manage.blade.php b/resources/views/dashboard/user/manage.blade.php index 8fcba3e..09fa497 100755 --- a/resources/views/dashboard/user/manage.blade.php +++ b/resources/views/dashboard/user/manage.blade.php @@ -342,7 +342,25 @@
- + + @if ($isSuspended) + +

 {{ __('This account has been :suspensionType suspended.', ['suspensionType' => (is_null($suspensionDuration)) ? __('permanently') : __('temporarily') ]) }}

+

 {!! __('Reason: :reason', ['reason' => $suspensionReason]) !!}

+

 {!! __('Suspension expires: :duration', ['duration' => $suspensionDuration]) !!}

+
+ @endif + + @if (!$isSuspended) + + @else +
+ @csrf + @method('DELETE') + + +
+ @endif