From 21fdb349d9f3985ef97b83339c8add54600fd8a5 Mon Sep 17 00:00:00 2001 From: miguel456 Date: Mon, 4 Apr 2022 09:59:18 +0100 Subject: [PATCH] refactor: revamp devtools page This commit refactors the development tools page to make it look better. Additionally, it makes small adjustments in the notifications and corrects missing strings from the page. --- app/Http/Controllers/AbsenceController.php | 2 +- app/Http/Controllers/DevToolsController.php | 14 ++++ app/Notifications/AbsenceRequestCancelled.php | 1 - app/Notifications/AbsenceRequestDeclined.php | 1 - app/Notifications/AbsenceRequestEnded.php | 1 - app/Services/AbsenceService.php | 10 +-- resources/views/components/modal.blade.php | 4 +- .../administration/devtools.blade.php | 69 ++++++++++++------- routes/web.php | 5 +- 9 files changed, 70 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/AbsenceController.php b/app/Http/Controllers/AbsenceController.php index 91f710b..1062867 100755 --- a/app/Http/Controllers/AbsenceController.php +++ b/app/Http/Controllers/AbsenceController.php @@ -82,7 +82,7 @@ class AbsenceController extends Controller { $this->authorize('create', Absence::class); - if ($this->hasActiveRequest(Auth::user())) { + if ($this->absenceService->hasActiveRequest(Auth::user())) { return redirect() ->back() ->with('error', __('You already have an active request. Cancel it or let it expire first.')); diff --git a/app/Http/Controllers/DevToolsController.php b/app/Http/Controllers/DevToolsController.php index 666366d..582a09a 100755 --- a/app/Http/Controllers/DevToolsController.php +++ b/app/Http/Controllers/DevToolsController.php @@ -24,10 +24,12 @@ namespace App\Http\Controllers; use App\Application; use App\Events\ApplicationApprovedEvent; use App\Events\ApplicationDeniedEvent; +use App\Services\AbsenceService; use App\Services\AccountSuspensionService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; class DevToolsController extends Controller { @@ -105,4 +107,16 @@ class DevToolsController extends Controller ->with('error', __('There were no expired suspensions (or no suspensions at all) to purge.')); } + + public function endAbsencesNow(AbsenceService $service) + { + $this->singleAuthorise(); + + $service->endExpired(); + Log::alert('(absence cleaner) Forcefully started absence expiration check!'); + + return redirect() + ->back() + ->with('success', 'Cleaned up expired absences.'); + } } diff --git a/app/Notifications/AbsenceRequestCancelled.php b/app/Notifications/AbsenceRequestCancelled.php index 1cf25ee..7e3d27f 100644 --- a/app/Notifications/AbsenceRequestCancelled.php +++ b/app/Notifications/AbsenceRequestCancelled.php @@ -49,7 +49,6 @@ class AbsenceRequestCancelled extends Notification implements ShouldQueue ->subject(config('app.name').' - absence request cancelled') ->line("This notification confirms that your recent Leave of Absence from {$this->absence->created_at} has just been cancelled by you.") ->line('Please note that any inactivity will be counted in our activity metrics. You may also make a new request if you wish.') - ->action('View your request', url(route('absences.show', ['absence' => $this->absence->id]))) ->action('Send new request', url(route('absences.create'))) ->salutation('The team at ' . config('app.name')); } diff --git a/app/Notifications/AbsenceRequestDeclined.php b/app/Notifications/AbsenceRequestDeclined.php index 8986bdc..3fd5da3 100644 --- a/app/Notifications/AbsenceRequestDeclined.php +++ b/app/Notifications/AbsenceRequestDeclined.php @@ -49,7 +49,6 @@ class AbsenceRequestDeclined extends Notification implements ShouldQueue ->subject(config('app.name').' - absence request declined') ->line("Your recent Leave of Absence request from {$this->absence->created_at} has just been declined by an admin.") ->line('Please note that any inactivity will be counted in our activity metrics. You may make a new request, but we recommend you ask your team lead regarding your declined request.') - ->action('View your request', url(route('absences.show', ['absence' => $this->absence->id]))) ->action('Send new request', url(route('absences.create'))) ->salutation('The team at ' . config('app.name')); } diff --git a/app/Notifications/AbsenceRequestEnded.php b/app/Notifications/AbsenceRequestEnded.php index 362a352..cbbf512 100644 --- a/app/Notifications/AbsenceRequestEnded.php +++ b/app/Notifications/AbsenceRequestEnded.php @@ -49,7 +49,6 @@ class AbsenceRequestEnded extends Notification implements ShouldQueue ->subject(config('app.name').' - absence request expired') ->line("Your Leave of Absence request from {$this->absence->created_at} (until {$this->absence->predicted_end}) has expired today.") ->line('Please note that any inactivity will be counted in our activity metrics. You may now make a new request if you still need more time.') - ->action('View expired request', url(route('absences.show', ['absence' => $this->absence->id]))) ->action('Send new request', url(route('absences.create'))) ->salutation('The team at ' . config('app.name')); } diff --git a/app/Services/AbsenceService.php b/app/Services/AbsenceService.php index df80f21..31c89f9 100644 --- a/app/Services/AbsenceService.php +++ b/app/Services/AbsenceService.php @@ -49,7 +49,7 @@ class AbsenceService { $absence = Absence::create([ - 'requesterID' => $user->id, + 'requesterID' => $requester->id, 'start' => $request->start_date, 'predicted_end' => $request->predicted_end, 'available_assist' => $request->available_assist == "on", @@ -62,7 +62,7 @@ class AbsenceService } Log::info('Processing new leave of absence request.', [ - 'requesting_user' => $user->email, + 'requesting_user' => $requester->email, 'absenceid' => $absence->id, 'reason' => $request->reason ]); @@ -78,7 +78,7 @@ class AbsenceService * @return Absence The approved absence. * @throws AbsenceNotActionableException */ - public function approveAbsence(Absence $absence): Absence + public function approveAbsence(Absence $absence) { Log::info('An absence request has just been approved.', [ 'absenceid' => $absence->id, @@ -99,7 +99,7 @@ class AbsenceService * @return Absence The declined absence. * @throws AbsenceNotActionableException */ - public function declineAbsence(Absence $absence): Absence + public function declineAbsence(Absence $absence) { Log::warning('An absence request has just been declined.', [ 'absenceid' => $absence->id, @@ -138,7 +138,7 @@ class AbsenceService * @param Absence $absence * @return bool */ - public function endAbsence(Absence $absence): Absence + public function endAbsence(Absence $absence) { Log::info('An absence request has just expired.', [ 'absenceid' => $absence->id, diff --git a/resources/views/components/modal.blade.php b/resources/views/components/modal.blade.php index ccbcb52..f638070 100755 --- a/resources/views/components/modal.blade.php +++ b/resources/views/components/modal.blade.php @@ -14,10 +14,10 @@ diff --git a/resources/views/dashboard/administration/devtools.blade.php b/resources/views/dashboard/administration/devtools.blade.php index 1d2508b..efa6fad 100755 --- a/resources/views/dashboard/administration/devtools.blade.php +++ b/resources/views/dashboard/administration/devtools.blade.php @@ -14,7 +14,7 @@ @section('content') - +

{{__('Please choose an application to force approve')}}

{{ __('Note that this process overrides users\'s votes.') }}

@@ -35,7 +35,7 @@ - +
@@ -70,45 +70,64 @@
- {{__('Warning')}} + +

{{__('These tools were intended for development purposes. Unless you know exactly what each command does, we recommend you don\'t use any of them.')}}

-
- -
- - +
+
+ - - - - - -
- @csrf - -
- -
- @csrf - @method('DELETE') - -
+
+ + +
-

.

+

{{ __('This panel allows you to override statuses for specific applications. Overriding them will trigger the correct events as well. Note that this system entirely ignores the voting system because these statuses ignore all other logic.') }}

-
+
+
+ + + + + +
+
+ @csrf + +
+ +
+ @csrf + @method('DELETE') + +
+ +
+ @csrf + @method('DELETE') + +
+
+ + +

{{ __('Housekeeping jobs usually run once every day, but if one of them has failed for some reason, you can manually run them here.') }}

+
+ +
+
@stop diff --git a/routes/web.php b/routes/web.php index 1168f6a..cfa8703 100755 --- a/routes/web.php +++ b/routes/web.php @@ -351,7 +351,10 @@ Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['lo ->name('devForceEvaluateVotes'); Route::delete('/suspensions/purge-expired', [DevToolsController::class, 'purgeSuspensions']) - ->name('devPurgeExpired'); + ->name('devPurgeExpiredSuspensions'); + + Route::delete('/absences/purge-expired', [DevToolsController::class, 'endAbsencesNow']) + ->name('devPurgeExpiredAbsences'); });