From c040e3d4fd63e9afbce3059f0dc2e93b0fe75fc7 Mon Sep 17 00:00:00 2001 From: AmandaNP Date: Sun, 21 May 2023 21:36:23 -0400 Subject: [PATCH] resolve #622 --- app/Http/Controllers/AppealController.php | 87 +++++++++-------------- app/Models/Appeal.php | 6 ++ routes/web.php | 2 +- 3 files changed, 39 insertions(+), 56 deletions(-) diff --git a/app/Http/Controllers/AppealController.php b/app/Http/Controllers/AppealController.php index dd16d1e3..4a5e6e9f 100644 --- a/app/Http/Controllers/AppealController.php +++ b/app/Http/Controllers/AppealController.php @@ -227,8 +227,14 @@ public function comment(Request $request, Appeal $appeal) return redirect()->route('appeal.view', $appeal); } - public function respond(Request $request, Appeal $appeal, Template $template) + public function respond(Request $request, Appeal $appeal, Template $template=NULL) { + if(!$template) { + $respondText = $request->input('custom'); + } + else { + $respondText = $template->template; + } $this->authorize('update', $appeal); $user = $request->user(); @@ -263,89 +269,60 @@ public function respond(Request $request, Appeal $appeal, Template $template) 'model_id' => $appeal->id, 'model_type' => Appeal::class, 'action' => 'responded', - 'reason' => $template->template, + 'reason' => $respondText, 'ip' => $ip, 'ua' => $ua . " " . $lang, 'protected' => LogEntry::LOG_PROTECTION_NONE, ]); - if ($appeal->user_verified==1) { + if ($appeal->user_verified==1 && !in_array($appeal->status, Appeal::APPEAL_CLOSED)) { $title = 'UTRS appeal response'; $baseURL = route('home'); $message = <<id, has be reviewed and the following message was left for you: - $template->template + $respondText Please reply by going to the following link and entering your appealkey: $baseURL In case you forgot your appealkey, it is: $appeal->appealsecretkey Thanks, - the UTRS team + $user->username EOF; $result = MediaWikiRepository::getApiForTarget($appeal->wiki)->getMediaWikiExtras()->sendEmail($appeal->getWikiEmailUsername(), $title, $message); } - return redirect()->route('appeal.view', $appeal); - } - - public function respondCustomSubmit(Request $request, Appeal $appeal) - { - $this->authorize('update', $appeal); - $user = $request->user(); - - abort_unless($appeal->handlingadmin === $user->id, 403, 'You are not the handling administrator.'); - - $status = $request->validate([ - 'status' => ['nullable', new PermittedStatusChange($appeal)], - ])['status']; - - $ua = $request->userAgent(); - $ip = $request->ip(); - $lang = $request->header('Accept-Language'); - - if ($status && $status !== $appeal->status) { - $appeal->update([ - 'status' => $status, - ]); - - LogEntry::create([ - 'user_id' => $user->id, - 'model_id' => $appeal->id, - 'model_type' => Appeal::class, - 'action' => 'set status as ' . $status, - 'ip' => $ip, - 'ua' => $ua . ' ' . $lang, - 'protected' => LogEntry::LOG_PROTECTION_NONE, - ]); - } - - LogEntry::create([ - 'user_id' => $user->id, - 'model_id' => $appeal->id, - 'model_type' => Appeal::class, - 'action' => 'responded', - 'reason' => $request->input('custom'), - 'ip' => $ip, - 'ua' => $ua . " " . $lang, - 'protected' => LogEntry::LOG_PROTECTION_NONE, - ]); - - if ($appeal->user_verified==1) { + elseif ($appeal->user_verified==1) { $title = 'UTRS appeal response'; $baseURL = route('home'); + switch (variable) { + case Appeal::STATUS_ACCEPT: + $textStatus = "has been accepted"; + break; + case Appeal::STATUS_DECLINE: + $textStatus = "has been declined"; + break; + case Appeal::STATUS_EXPIRE: + $textStatus = "has expired"; + break; + default: + $textStatus = "has been reviewed"; + break; + } + $message = <<id, has be reviewed and the following message was left for you: + Your appeal, #$appeal->id, $textStatus and the following message was left for you: - $request->input('custom') + $respondText - Please reply by going to the following link and entering your appealkey: $baseURL + Your appeal is now closed. You will need to take time to consider the reply from the administrator. Should you wish to file a new appeal, you will need to wait a few days to do so, to ensure that you have thought about the administrator's reply. + You can still view it by going to the following link and entering your appealkey: $baseURL In case you forgot your appealkey, it is: $appeal->appealsecretkey Thanks, - the UTRS team + $user->username EOF; $result = MediaWikiRepository::getApiForTarget($appeal->wiki)->getMediaWikiExtras()->sendEmail($appeal->getWikiEmailUsername(), $title, $message); } diff --git a/app/Models/Appeal.php b/app/Models/Appeal.php index bb5e1c45..2efb22d1 100644 --- a/app/Models/Appeal.php +++ b/app/Models/Appeal.php @@ -20,6 +20,12 @@ class Appeal extends Model self::STATUS_EXPIRE => self::STATUS_EXPIRE, ]; + const APPEAL_CLOSED = [ + self::STATUS_ACCEPT => self::STATUS_ACCEPT, + self::STATUS_DECLINE => self::STATUS_DECLINE, + self::STATUS_EXPIRE => self::STATUS_EXPIRE, + ]; + const REGULAR_NO_VIEW_STATUS = [ self::STATUS_INVALID, self::STATUS_NOTFOUND, diff --git a/routes/web.php b/routes/web.php index 36ba6e93..dd7a800c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -64,7 +64,7 @@ Route::post('/appeal/template/{appeal}/{template}', 'AppealController@respond')->name('appeal.template.submit'); Route::get('/appeal/custom/{appeal}', 'AppealController@respondCustom')->name('appeal.customresponse'); - Route::post('/appeal/custom/{appeal}', 'AppealController@respondCustomSubmit')->name('appeal.customresponse.submit'); + Route::post('/appeal/custom/{appeal}', 'AppealController@respond')->name('appeal.customresponse.submit'); Route::get('/publicappeal', 'Appeal\PublicAppealController@redirectLegacy');