From 6d55d782806c9660e9e65dc5250faacb5d0033ed Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 9 Oct 2023 16:13:41 +0100 Subject: [PATCH 1/2] Set resend acceptance to POST Signed-off-by: snipe --- app/Http/Controllers/ReportsController.php | 16 +++++++++++++--- .../views/reports/unaccepted_assets.blade.php | 16 ++++++++++++++-- routes/web.php | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index bacc27f423..4873c7f2a5 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1043,27 +1043,37 @@ class ReportsController extends Controller * @throws \Illuminate\Auth\Access\AuthorizationException * @version v1.0 */ - public function sentAssetAcceptanceReminder($acceptanceId = null) + public function sentAssetAcceptanceReminder(Request $request) { $this->authorize('reports.view'); - if (!$acceptance = CheckoutAcceptance::pending()->find($acceptanceId)) { + if (!$acceptance = CheckoutAcceptance::pending()->find($request->input('acceptance_id'))) { + \Log::debug('No pending acceptances'); // Redirect to the unaccepted assets report page with error return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } + $assetItem = $acceptance->checkoutable; + \Log::debug(print_r($assetItem, true)); + if (is_null($acceptance->created_at)){ + \Log::debug('No acceptance created_at'); return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } else { $logItem_res = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get(); + + \Log::debug('Acceptance created at: '.$acceptance->created_at); + \Log::debug(print_r($logItem_res, true)); + if ($logItem_res->isEmpty()){ + \Log::debug('Acceptance date mismatch'); return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data')); } $logItem = $logItem_res[0]; } - if(!$assetItem->assignedTo->locale){ + if (!$assetItem->assignedTo->locale){ Notification::locale(Setting::getSettings()->locale)->send( $assetItem->assignedTo, new CheckoutAssetNotification($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note) diff --git a/resources/views/reports/unaccepted_assets.blade.php b/resources/views/reports/unaccepted_assets.blade.php index 37ae66ce30..80d151fd42 100644 --- a/resources/views/reports/unaccepted_assets.blade.php +++ b/resources/views/reports/unaccepted_assets.blade.php @@ -77,11 +77,23 @@ {!! $item['assetItem']->present()->nameUrl() !!} {{ $item['assetItem']->asset_tag }} assignedTo === null || $item['acceptance']->assignedTo->trashed()) style="text-decoration: line-through" @endif>{!! ($item['acceptance']->assignedTo) ? $item['acceptance']->assignedTo->present()->nameUrl() : trans('admin/reports/general.deleted_user') !!} - + + @if(!$item['acceptance']->trashed()) - @if ($item['acceptance']->assignedTo){{ trans('admin/reports/general.send_reminder') }}@endif +
+ @if ($item['acceptance']->assignedTo) + @csrf + + + + @endif +
@endif + +
@endif diff --git a/routes/web.php b/routes/web.php index 4bc8b3bb58..0aacf85135 100644 --- a/routes/web.php +++ b/routes/web.php @@ -368,8 +368,8 @@ Route::group(['middleware' => ['auth']], function () { 'reports/unaccepted_assets/{deleted?}', [ReportsController::class, 'getAssetAcceptanceReport'] )->name('reports/unaccepted_assets'); - Route::get( - 'reports/unaccepted_assets/{acceptanceId}/sent_reminder', + Route::post( + 'reports/unaccepted_assets/sent_reminder', [ReportsController::class, 'sentAssetAcceptanceReminder'] )->name('reports/unaccepted_assets_sent_reminder'); Route::delete( From 866bbe5e1149223baa265f8d04a2854dfb9bfa99 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 9 Oct 2023 16:15:14 +0100 Subject: [PATCH 2/2] Removed extra debugging Signed-off-by: snipe --- app/Http/Controllers/ReportsController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 4873c7f2a5..2791624216 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -1063,9 +1063,6 @@ class ReportsController extends Controller } else { $logItem_res = $assetItem->checkouts()->where('created_at', '=', $acceptance->created_at)->get(); - \Log::debug('Acceptance created at: '.$acceptance->created_at); - \Log::debug(print_r($logItem_res, true)); - if ($logItem_res->isEmpty()){ \Log::debug('Acceptance date mismatch'); return redirect()->route('reports/unaccepted_assets')->with('error', trans('general.bad_data'));