diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8367ad097..2abaa5073 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,7 +2,7 @@ namespace App\Console; -use App\FeatureToggle; +use App\Enums\FeatureToggles; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -44,7 +44,7 @@ protected function schedule(Schedule $schedule): void { $schedule->command('OnlineControllers:GetControllers')->everyMinute()->monitorName('Get Online Controllers'); $schedule->command('RosterUpdate:UpdateAcademyExams')->cron('17 */2 * * *')->monitorName('Active Controller Exam Update'); $schedule->command('Events:UpdateSupportEvents')->dailyAt('05:09')->monitorName('Sync Support Events')->when(function () { - return FeatureToggle::isEnabled('auto_support_events'); + return toggleEnabled(FeatureToggles::AUTO_SUPPORT_EVENTS); }); $schedule->command('PilotPassport:ActivityUpdate')->everyFiveMinutes()->monitorName('Update Pilot Passport Activity'); } diff --git a/app/Enums/FeatureToggles.php b/app/Enums/FeatureToggles.php new file mode 100644 index 000000000..75e563349 --- /dev/null +++ b/app/Enums/FeatureToggles.php @@ -0,0 +1,13 @@ +is_enabled = ! $toggle_value; $toggle->save(); } - Cache::put(FeatureToggle::generateToggleCacheName($toggle_name), $toggle->is_enabled); + Cache::put(FeatureToggle::generateToggleCacheName($toggle_enum), $toggle->is_enabled); } - private static function generateToggleCacheName($toggle_name) { - return 'FeatureToggle_' . $toggle_name; + private static function generateToggleCacheName($toggle_enum) { + return 'FeatureToggle_' . $toggle_enum->value; } - private static function getToggleValue($toggle_name) { - return Cache::rememberForever(FeatureToggle::generateToggleCacheName($toggle_name), function () use ($toggle_name) { - $toggle = FeatureToggle::find($toggle_name); + private static function getToggleValue($toggle_enum) { + return Cache::rememberForever(FeatureToggle::generateToggleCacheName($toggle_enum), function () use ($toggle_enum) { + $toggle = FeatureToggle::find($toggle_enum->value); return $toggle != null && $toggle->is_enabled; }); } diff --git a/app/Helpers/FeatureToggleHelper.php b/app/Helpers/FeatureToggleHelper.php index 8c43e5d5a..9ab2190fa 100644 --- a/app/Helpers/FeatureToggleHelper.php +++ b/app/Helpers/FeatureToggleHelper.php @@ -2,6 +2,6 @@ use App\FeatureToggle; -function toggleEnabled($toggle_name) { - return FeatureToggle::isEnabled($toggle_name); +function toggleEnabled($toggle_enum) { + return FeatureToggle::isEnabled($toggle_enum); } diff --git a/app/Http/Controllers/AdminDash.php b/app/Http/Controllers/AdminDash.php index ba182662f..ab09147a8 100644 --- a/app/Http/Controllers/AdminDash.php +++ b/app/Http/Controllers/AdminDash.php @@ -8,6 +8,7 @@ use App\Bronze; use App\Calendar; use App\ControllerLog; +use App\Enums\SessionVariables; use App\Event; use App\EventDenylist; use App\EventPosition; @@ -97,7 +98,7 @@ public function storeScenery(Request $request) { $audit->what = Auth::user()->full_name.' added new scenery.'; $audit->save(); - return redirect('/dashboard/admin/scenery')->with('success', 'Scenery added successfully.'); + return redirect('/dashboard/admin/scenery')->with(SessionVariables::SUCCESS->value, 'Scenery added successfully.'); } public function editScenery(Request $request, $id) { @@ -134,7 +135,7 @@ public function saveScenery(Request $request, $id) { $audit->what = Auth::user()->full_name.' updated a scenery.'; $audit->save(); - return redirect('/dashboard/admin/scenery')->with('success', 'Scenery edited successfully.'); + return redirect('/dashboard/admin/scenery')->with(SessionVariables::SUCCESS->value, 'Scenery edited successfully.'); } public function deleteScenery($id) { @@ -147,7 +148,7 @@ public function deleteScenery($id) { $audit->what = Auth::user()->full_name.' removed a scenery.'; $audit->save(); - return redirect('/dashboard/admin/scenery')->with('success', 'Scenery deleted successfully.'); + return redirect('/dashboard/admin/scenery')->with(SessionVariables::SUCCESS->value, 'Scenery deleted successfully.'); } public function showAirports() { @@ -179,7 +180,7 @@ public function storeAirport(Request $request) { Artisan::call('Weather:UpdateWeather'); - return redirect('/dashboard/admin/airports')->with('success', 'The airport was added successfully.'); + return redirect('/dashboard/admin/airports')->with(SessionVariables::SUCCESS->value, 'The airport was added successfully.'); } public function addAirportToHome($id) { @@ -187,7 +188,7 @@ public function addAirportToHome($id) { $airport->front_pg = 1; $airport->save(); - return redirect()->back()->with('success', 'You have successfully added this airport to the home page.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have successfully added this airport to the home page.'); } public function removeAirportFromHome($id) { @@ -195,14 +196,14 @@ public function removeAirportFromHome($id) { $airport->front_pg = 0; $airport->save(); - return redirect()->back()->with('success', 'You have successfully removed this airport from the home page.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have successfully removed this airport from the home page.'); } public function deleteAirport($id) { $airport = Airport::find($id); $airport->delete(); - return redirect('/dashboard/admin/airports')->with('success', 'The airport has been deleted successfully.'); + return redirect('/dashboard/admin/airports')->with(SessionVariables::SUCCESS->value, 'The airport has been deleted successfully.'); } public function showRoster() { @@ -458,7 +459,7 @@ public function updateController(Request $request, $id) { $audit->what = Auth::user()->full_name.' made changes to '.$user->full_name.'.'; $audit->save(); - return redirect('/dashboard/controllers/roster')->with('success', 'Controller updated successfully.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::SUCCESS->value, 'Controller updated successfully.'); } public function disallowVisitReq($id) { @@ -477,7 +478,7 @@ public function disallowVisitReq($id) { $audit->what = Auth::user()->full_name.' removed '.$name.' from the visitor agreement.'; $audit->save(); - return redirect('/dashboard/controllers/roster')->with('success', 'Controller removed from the visitor agreement.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::SUCCESS->value, 'Controller removed from the visitor agreement.'); } public function allowVisitReq(Request $request) { @@ -489,7 +490,7 @@ public function allowVisitReq(Request $request) { $visitrej = VisitRej::where('cid', $id)->first(); if ($visitrej == null) { - return redirect('/dashboard/controllers/roster')->with('error', 'Controller not found.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::ERROR->value, 'Controller not found.'); } $visitrej->delete(); @@ -499,7 +500,7 @@ public function allowVisitReq(Request $request) { $audit->what = Auth::user()->full_name.' readded '.$name.' to the visitor agreement.'; $audit->save(); - return redirect('/dashboard/controllers/roster')->with('success', 'Controller allowed to visit.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::SUCCESS->value, 'Controller allowed to visit.'); } public function showVisitRequests() { @@ -570,7 +571,7 @@ public function rejectVisitRequest(Request $request, $id) { $audit->what = Auth::user()->full_name.' rejected the visit request for '.$visitor->name.'.'; $audit->save(); - return redirect('/dashboard/admin/roster/visit/requests')->with('success', 'The visit request has been rejected successfully.'); + return redirect('/dashboard/admin/roster/visit/requests')->with(SessionVariables::SUCCESS->value, 'The visit request has been rejected successfully.'); } public function storeVisitor(Request $request) { @@ -627,14 +628,14 @@ public function storeVisitor(Request $request) { $client = new Client(); $res = $client->request('POST', Config::get('vatusa.base').'/v2/facility/'.Config::get('vatusa.facility').'/roster/manageVisitor/'.$request->input('cid').'?apikey='.Config::get('vatusa.api_key'), ['http_errors' => false]); - return redirect('/dashboard/admin/roster/visit/requests')->with('success', 'The visitor has been successfully added to the roster.'); + return redirect('/dashboard/admin/roster/visit/requests')->with(SessionVariables::SUCCESS->value, 'The visitor has been successfully added to the roster.'); } public function removeVisitor($id) { $user = User::find($id); $name = $user->full_name; if ($user->visitor == 0) { - return redirect()->back()->with('error', 'You can only remove visitors this way. If you are trying to remove a home controller, please do this from the VATUSA website.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only remove visitors this way. If you are trying to remove a home controller, please do this from the VATUSA website.'); } else { $event_requests = EventRegistration::where('controller_id', $user->id)->get(); foreach ($event_requests as $e) { @@ -661,7 +662,7 @@ public function removeVisitor($id) { ]; $res = $client->request('DELETE', Config::get('vatusa.base').'/v2/facility/'.Config::get('vatusa.facility').'/roster/manageVisitor/'.$id.'?apikey='.Config::get('vatusa.api_key'), $req_params); - return redirect('/dashboard/controllers/roster')->with('success', 'The visitor has been removed successfully.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::SUCCESS->value, 'The visitor has been removed successfully.'); } } @@ -709,7 +710,7 @@ public function storeCalendarEvent(Request $request) { $audit->what = Auth::user()->full_name.' added a new calendar or news event.'; $audit->save(); - return redirect('/dashboard/admin/calendar')->with('success', 'The calendar event or news posting has been created.'); + return redirect('/dashboard/admin/calendar')->with(SessionVariables::SUCCESS->value, 'The calendar event or news posting has been created.'); } public function editCalendarEvent($id) { @@ -741,7 +742,7 @@ public function saveCalendarEvent(Request $request, $id) { $audit->what = Auth::user()->full_name.' edited the calendar event '.$calendar->title.'.'; $audit->save(); - return redirect('/dashboard/admin/calendar')->with('success', 'The calendar event or news posting has been edited.'); + return redirect('/dashboard/admin/calendar')->with(SessionVariables::SUCCESS->value, 'The calendar event or news posting has been edited.'); } public function deleteCalendarEvent($id) { @@ -755,7 +756,7 @@ public function deleteCalendarEvent($id) { $audit->what = Auth::user()->full_name.' removed the calendar event '.$title.'.'; $audit->save(); - return redirect('/dashboard/admin/calendar')->with('success', 'The calendar event or news posting has been deleted.'); + return redirect('/dashboard/admin/calendar')->with(SessionVariables::SUCCESS->value, 'The calendar event or news posting has been deleted.'); } public function toggleCalendarEventVisibility($id) { @@ -778,7 +779,7 @@ public function toggleCalendarEventVisibility($id) { $audit->what = Auth::user()->full_name . ' made ' . $calendar->title . ' ' . $type . '.'; $audit->save(); - return redirect('/dashboard/admin/calendar')->with('success', 'Changed ' . $calendar->title . ' to be ' . $type . '!'); + return redirect('/dashboard/admin/calendar')->with(SessionVariables::SUCCESS->value, 'Changed ' . $calendar->title . ' to be ' . $type . '!'); } public function uploadFile() { @@ -844,7 +845,7 @@ public function storeFile(Request $request) { $audit->what = Auth::user()->full_name.' created the file '.$file->name.'.'; $audit->save(); - return redirect('/dashboard/controllers/files')->with('success', 'The file has been successfully added.'); + return redirect('/dashboard/controllers/files')->with(SessionVariables::SUCCESS->value, 'The file has been successfully added.'); } public function fileSeparator(Request $request) { @@ -866,7 +867,7 @@ public function fileSeparator(Request $request) { $audit->what = Auth::user()->full_name.' created the file separator '.$file->name.'.'; $audit->save(); - return redirect('/dashboard/controllers/files')->with('success', 'The file separator has been successfully added.'); + return redirect('/dashboard/controllers/files')->with(SessionVariables::SUCCESS->value, 'The file separator has been successfully added.'); } public function editFile($id) { @@ -898,7 +899,7 @@ public function saveFile(Request $request, $id) { $audit->what = Auth::user()->full_name.' updated the file '.$file->name.'.'; $audit->save(); - return redirect('/dashboard/controllers/files')->with('success', 'The file has been edited successfully.'); + return redirect('/dashboard/controllers/files')->with(SessionVariables::SUCCESS->value, 'The file has been edited successfully.'); } public function updateFileDispOrder(Request $request) { @@ -966,7 +967,7 @@ public function deleteFile($id) { $audit->what = Auth::user()->full_name.' deleted the file '.$file->name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The file has been deleted successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The file has been deleted successfully.'); } public function showFeedback() { @@ -1010,7 +1011,7 @@ public function saveFeedback(Request $request, $id) { if (isset($controller)) { Mail::to($controller->email)->send(new NewFeedback($feedback, $controller)); } - return redirect()->back()->with('success', 'The feedback has been saved.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The feedback has been saved.'); } public function hideFeedback(Request $request, $id) { @@ -1028,7 +1029,7 @@ public function hideFeedback(Request $request, $id) { $audit->what = Auth::user()->full_name.' archived feedback '.$feedback->id.' for '.$feedback->controller_name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The feedback has been hidden.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The feedback has been hidden.'); } public function updateFeedback(Request $request, $id) { @@ -1046,7 +1047,7 @@ public function updateFeedback(Request $request, $id) { $audit->what = Auth::user()->full_name.' updated feedback '.$feedback->id.' for '.$feedback->controller_name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The feedback has been updated.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The feedback has been updated.'); } public function emailFeedback(Request $request, $id) { @@ -1072,7 +1073,7 @@ public function emailFeedback(Request $request, $id) { Mail::to($feedback->pilot_email)->send(new PilotFeedback($feedback, $subject, $body, $sender, $replyToAddress, $replyToName)); - return redirect()->back()->with('success', 'The email has been sent to the pilot successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The email has been sent to the pilot successfully.'); } public function showTrainerFeedback() { @@ -1108,7 +1109,7 @@ public function saveTrainerFeedback(Request $request, $id) { Mail::to($trainer->email)->send(new NewTrainerFeedback($feedback, $trainer)); } - return redirect()->back()->with('success', 'The trainer feedback has been saved.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The trainer feedback has been saved.'); } public function hideTrainerFeedback(Request $request, $id) { @@ -1133,7 +1134,7 @@ public function hideTrainerFeedback(Request $request, $id) { $audit->what = Auth::user()->full_name.' archived treainer feedback '.$feedback->id.' for '.$feedback->controller_name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The trainer feedback has been hidden.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The trainer feedback has been hidden.'); } public function updateTrainerFeedback(Request $request, $id) { @@ -1158,7 +1159,7 @@ public function updateTrainerFeedback(Request $request, $id) { $audit->what = Auth::user()->full_name.' updated trainer feedback '.$feedback->id.' for '.$feedback->controller_name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The trainer feedback has been updated.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The trainer feedback has been updated.'); } public function emailTrainerFeedback(Request $request, $id) { @@ -1184,7 +1185,7 @@ public function emailTrainerFeedback(Request $request, $id) { Mail::to($feedback->student_email)->send(new PilotFeedback($feedback, $subject, $body, $sender, $replyToAddress, $replyToName)); - return redirect()->back()->with('success', 'The email has been sent to the student successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The email has been sent to the student successfully.'); } public function sendNewEmail() { @@ -1251,7 +1252,7 @@ public function sendEmail(Request $request) { } elseif ($bulk == 10) { $emails = $c1; } else { - return redirect()->back()->with('error', 'Please select either a controller or a group to send an email to.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Please select either a controller or a group to send an email to.'); } foreach ($emails as $e) { @@ -1268,7 +1269,7 @@ public function sendEmail(Request $request) { $audit->what = Auth::user()->full_name.' sent an email from the send email page.'; $audit->save(); - return redirect('/dashboard/admin/email/send')->with('success', 'The email has been sent successfully and a copy has been sent to you as well.'); + return redirect('/dashboard/admin/email/send')->with(SessionVariables::SUCCESS->value, 'The email has been sent successfully and a copy has been sent to you as well.'); } public function setAnnouncement() { @@ -1288,7 +1289,7 @@ public function saveAnnouncement(Request $request) { $audit->what = Auth::user()->full_name.' updated the announcement.'; $audit->save(); - return redirect('/dashboard/admin/announcement')->with('success', 'The announcement has been updated successfully.'); + return redirect('/dashboard/admin/announcement')->with(SessionVariables::SUCCESS->value, 'The announcement has been updated successfully.'); } public function showBronzeMic($sort = 'bronzesort', $year = null, $month = null) { @@ -1354,7 +1355,7 @@ public function setLocalHeroWinner($year, $month, $hours, $id) { $audit->what = Auth::user()->full_name.' set the local hero winner for '.$month.'/'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/bronze-mic/localsort/'.$year.'/'.$month)->with('success', 'The controller has been set as the local hero winner successfully.'); + return redirect('/dashboard/admin/bronze-mic/localsort/'.$year.'/'.$month)->with(SessionVariables::SUCCESS->value, 'The controller has been set as the local hero winner successfully.'); } public function removeLocalHeroWinner($id, $year, $month) { @@ -1367,7 +1368,7 @@ public function removeLocalHeroWinner($id, $year, $month) { $audit->what = Auth::user()->full_name.' removed the local hero winner for '.$month.'/'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/bronze-mic/localsort/'.$year.'/'.$month)->with('success', 'The local hero winner has been removed successfully.'); + return redirect('/dashboard/admin/bronze-mic/localsort/'.$year.'/'.$month)->with(SessionVariables::SUCCESS->value, 'The local hero winner has been removed successfully.'); } public function updateLocalHeroChallenge(Request $request, $id) { @@ -1409,7 +1410,7 @@ public function updateLocalHeroChallenge(Request $request, $id) { $audit->what = Auth::user()->full_name.' updated the local hero configuration for '.$request->month.'/'.$request->year.'.'; $audit->save(); - return redirect('/dashboard/admin/bronze-mic/localsort/'.$request->year.'/'.$request->month)->with('success', 'Local hero configuration settings were saved.'); + return redirect('/dashboard/admin/bronze-mic/localsort/'.$request->year.'/'.$request->month)->with(SessionVariables::SUCCESS->value, 'Local hero configuration settings were saved.'); } public function setBronzeWinner(Request $request, $year, $month, $hours, $id) { @@ -1426,7 +1427,7 @@ public function setBronzeWinner(Request $request, $year, $month, $hours, $id) { $audit->what = Auth::user()->full_name.' set the bronze mic winner for '.$month.'/'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/bronze-mic/bronzesort/'.$year.'/'.$month)->with('success', 'The controller has been set as the bronze mic winner successfully.'); + return redirect('/dashboard/admin/bronze-mic/bronzesort/'.$year.'/'.$month)->with(SessionVariables::SUCCESS->value, 'The controller has been set as the bronze mic winner successfully.'); } public function removeBronzeWinner($id, $year, $month) { @@ -1439,7 +1440,7 @@ public function removeBronzeWinner($id, $year, $month) { $audit->what = Auth::user()->full_name.' removed the bronze mic winner for '.$month.'/'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/bronze-mic/bronzesort/'.$year.'/'.$month)->with('success', 'The bronze mic winner has been removed successfully.'); + return redirect('/dashboard/admin/bronze-mic/bronzesort/'.$year.'/'.$month)->with(SessionVariables::SUCCESS->value, 'The bronze mic winner has been removed successfully.'); } public function showPyriteMic($year = null) { @@ -1474,7 +1475,7 @@ public function setPyriteWinner(Request $request, $year, $hours, $id) { $audit->what = Auth::user()->full_name.' set the pyrite mic winner for 20'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/pyrite-mic/'.$year)->with('success', 'The controller has been set as the pyrite mic winner successfully.'); + return redirect('/dashboard/admin/pyrite-mic/'.$year)->with(SessionVariables::SUCCESS->value, 'The controller has been set as the pyrite mic winner successfully.'); } public function removePyriteWinner($id, $year) { @@ -1487,7 +1488,7 @@ public function removePyriteWinner($id, $year) { $audit->what = Auth::user()->full_name.' removed the pyrite mic winner for 20'.$year.'.'; $audit->save(); - return redirect('/dashboard/admin/pyrite-mic/'.$year)->with('success', 'The winner has been removed successfully.'); + return redirect('/dashboard/admin/pyrite-mic/'.$year)->with(SessionVariables::SUCCESS->value, 'The winner has been removed successfully.'); } public function newEvent() { @@ -1553,7 +1554,7 @@ public function saveNewEvent(Request $request) { $event->reduceEventBanner(); $event->save(); } catch (\Exception $e) { - return redirect('/dashboard/controllers/events/view/'.$event->id)->with('error', 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); + return redirect('/dashboard/controllers/events/view/'.$event->id)->with(SessionVariables::ERROR->value, 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); } $audit = new Audit; @@ -1562,7 +1563,7 @@ public function saveNewEvent(Request $request) { $audit->what = Auth::user()->full_name.' created the event '.$event->name.'.'; $audit->save(); - return redirect('/dashboard/controllers/events/view/'.$event->id)->with('success', 'The event has been created successfully.'); + return redirect('/dashboard/controllers/events/view/'.$event->id)->with(SessionVariables::SUCCESS->value, 'The event has been created successfully.'); } public function editEvent($id) { @@ -1592,7 +1593,7 @@ public function saveEvent(Request $request, $id) { try { $event->reduceEventBanner(); } catch (\Exception $e) { - return redirect('/dashboard/controllers/events/view/'.$event->id)->with('error', 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); + return redirect('/dashboard/controllers/events/view/'.$event->id)->with(SessionVariables::ERROR->value, 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); } $event->banner_path = '/storage'.$public_url; } @@ -1642,7 +1643,7 @@ public function saveEvent(Request $request, $id) { $event->reduceEventBanner(); $event->save(); } catch (\Exception $e) { - return redirect('/dashboard/controllers/events/view/'.$event->id)->with('error', 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); + return redirect('/dashboard/controllers/events/view/'.$event->id)->with(SessionVariables::ERROR->value, 'The event has been created successfully, but the banner image appears to be corrupt. Please re-save the image and ensure that it is not an animated image.'); } $audit = new Audit; @@ -1651,7 +1652,7 @@ public function saveEvent(Request $request, $id) { $audit->what = Auth::user()->full_name.' edited the event '.$event->name.'.'; $audit->save(); - return redirect('/dashboard/controllers/events/view/'.$event->id)->with('success', 'The event has been edited successfully.'); + return redirect('/dashboard/controllers/events/view/'.$event->id)->with(SessionVariables::SUCCESS->value, 'The event has been edited successfully.'); } public function deleteEvent($id, Request $request) { @@ -1682,7 +1683,7 @@ public function deleteEvent($id, Request $request) { $audit->what = Auth::user()->full_name.' deleted the event '.$name.'.'; $audit->save(); - return redirect('/dashboard/controllers/events')->with('success', 'The event has been deleted successfully.'); + return redirect('/dashboard/controllers/events')->with(SessionVariables::SUCCESS->value, 'The event has been deleted successfully.'); } public function denylistEvent($event) { @@ -1714,7 +1715,7 @@ public function deleteEventDenylist($id) { $audit->what = Auth::user()->full_name.' deleted the event denylist with id '.$vatsim_id.'.'; $audit->save(); - return redirect('/dashboard/admin/events/denylist')->with('success', 'The event denylist has been removed successfully.'); + return redirect('/dashboard/admin/events/denylist')->with(SessionVariables::SUCCESS->value, 'The event denylist has been removed successfully.'); } public function addPosition(Request $request, $id) { @@ -1725,7 +1726,7 @@ public function addPosition(Request $request, $id) { $position->name = $request->name; $position->save(); - return redirect()->back()->with('success', 'The position was added successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position was added successfully.'); } public function removePosition($id) { @@ -1737,30 +1738,30 @@ public function removePosition($id) { $r->delete(); } - return redirect()->back()->with('success', 'The position has been removed successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position has been removed successfully.'); } public function toggleRegistration($id): RedirectResponse { $event = Event::find($id); if (! $event) { - return redirect()->back()->with('error', 'That event does not exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That event does not exist'); } $event->toggleRegistration(); - return redirect()->back()->with('success', 'The registration has been toggled successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The registration has been toggled successfully.'); } public function toggleShowAssignments($id): RedirectResponse { $event = Event::find($id); if (! $event) { - return redirect()->back()->with('error', 'That event does not exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That event does not exist'); } $event->toggleShowAssignments(); - return redirect()->back()->with('success', 'The assignment visibility has been toggled successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The assignment visibility has been toggled successfully.'); } public function assignPosition(Request $request, $id) { @@ -1772,7 +1773,7 @@ public function assignPosition(Request $request, $id) { $reg->status = EventRegistration::STATUSES['ASSIGNED']; $reg->save(); - return redirect()->back()->with('success', 'The position has been assigned successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position has been assigned successfully.'); } public function unassignPosition($id) { @@ -1780,7 +1781,7 @@ public function unassignPosition($id) { $position->status = EventRegistration::STATUSES['UNASSIGNED']; $position->save(); - return redirect()->back()->with('success', 'The position assignment has been removed successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position assignment has been removed successfully.'); } public function eventMarkNoShow($id) { @@ -1788,7 +1789,7 @@ public function eventMarkNoShow($id) { $position->no_show = 1; $position->save(); - return redirect()->back()->with('success', 'Controller was marked as a no-show.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Controller was marked as a no-show.'); } public function eventUnMarkNoShow($id) { @@ -1796,7 +1797,7 @@ public function eventUnMarkNoShow($id) { $position->no_show = 0; $position->save(); - return redirect()->back()->with('success', 'Controller was unmarked as a no-show.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Controller was unmarked as a no-show.'); } public function manualAssign(Request $request, $id) { @@ -1817,7 +1818,7 @@ public function manualAssign(Request $request, $id) { $reg->choice_number = 0; $reg->save(); - return redirect()->back()->with('success', 'The position has been assigned successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position has been assigned successfully.'); } public function setEventActive($id) { @@ -1831,7 +1832,7 @@ public function setEventActive($id) { $audit->what = Auth::user()->full_name.' set the event '.$event->name.' as active.'; $audit->save(); - return redirect()->back()->with('success', 'The event has been unhidden successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The event has been unhidden successfully.'); } public function hideEvent($id) { @@ -1845,7 +1846,7 @@ public function hideEvent($id) { $audit->what = Auth::user()->full_name.' hid the event '.$event->name.'.'; $audit->save(); - return redirect()->back()->with('success', 'The event has been hidden successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The event has been hidden successfully.'); } public function setEventPositionPreset(Request $request, $id) { @@ -1866,12 +1867,12 @@ public function setEventPositionPreset(Request $request, $id) { $preset->save(); } - return redirect()->back()->with('success', 'The position preset has been added successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position preset has been added successfully'); } public function sendEventReminder($id) { Artisan::call('Event:SendEventReminder ' . $id); - return redirect()->back()->with('success', 'Event reminder sent'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Event reminder sent'); } public function updateTrackingAirports(Request $request, $id) { @@ -1887,7 +1888,7 @@ public function updateTrackingAirports(Request $request, $id) { $event->tracking_airports = rtrim($event->tracking_airports, ','); $event->save(); - return redirect()->back()->with('success', 'Airports for event statistics report updated successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Airports for event statistics report updated successfully'); } public function viewEventStats($id) { @@ -1895,7 +1896,7 @@ public function viewEventStats($id) { $event_stat = $event->eventStat; if (is_null($event_stat)) { - return redirect()->back()->with('error', 'That event does not yet have a report generated'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That event does not yet have a report generated'); } $event_stat_controllers_by_rating = $event_stat->controllers_by_rating; @@ -1918,12 +1919,12 @@ public function rerunEventStats($id) { $event_stat = $event->eventStat; if (is_null($event_stat)) { - return redirect()->back()->with('error', 'That event does not yet have a report generated'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That event does not yet have a report generated'); } $event_stat->delete(); - return redirect()->back()->with('success', 'The report for this event has been deleted and a new report will be available within 24 hours'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The report for this event has been deleted and a new report will be available within 24 hours'); } @@ -1943,14 +1944,14 @@ public function retrievePositionPreset(Request $request, $id) { $position->save(); } - return redirect('/dashboard/controllers/events/view/'.$id)->with('success', 'The position preset has been loaded successfully.'); + return redirect('/dashboard/controllers/events/view/'.$id)->with(SessionVariables::SUCCESS->value, 'The position preset has been loaded successfully.'); } public function deletePositionPreset(Request $request) { $preset = PositionPreset::find($request->p_id); $preset->delete(); - return redirect()->back()->with('success', 'The position preset has been removed successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The position preset has been removed successfully.'); } public function incidentReportIndex() { @@ -1979,7 +1980,7 @@ public function archiveIncident($id) { $audit->what = Auth::user()->full_name.' archived incident report '.$id.'.'; $audit->save(); - return redirect()->back()->with('success', 'The incident has been reported successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The incident has been reported successfully.'); } public function deleteIncident($id) { @@ -1992,7 +1993,7 @@ public function deleteIncident($id) { $audit->what = Auth::user()->full_name.' deleted incident report '.$id.'.'; $audit->save(); - return redirect()->back()->with('success', 'The incident has been deleted successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The incident has been deleted successfully.'); } public function showAudits() { @@ -2022,7 +2023,7 @@ public function createFeatureToggle(Request $request) { $toggle->toggle_description = $request->input('toggle_description'); $toggle->save(); - return redirect('/dashboard/admin/toggles')->with('success', 'The toggle `' . $toggle->toggle_name . '` has been created'); + return redirect('/dashboard/admin/toggles')->with(SessionVariables::SUCCESS->value, 'The toggle `' . $toggle->toggle_name . '` has been created'); } public function showEditFeatureToggle($toggle_name) { @@ -2037,7 +2038,7 @@ public function editFeatureToggle(Request $request) { } FeatureToggle::updateToggle($request->input('toggle_name_orig'), $request->input('toggle_name'), $request->input('toggle_description')); - return redirect('/dashboard/admin/toggles')->with('success', 'The toggle `' . $request->input('toggle_name') . '` has been updated'); + return redirect('/dashboard/admin/toggles')->with(SessionVariables::SUCCESS->value, 'The toggle `' . $request->input('toggle_name') . '` has been updated'); } public function toggleFeatureToggle($toggle_name) { @@ -2049,9 +2050,9 @@ public function toggleFeatureToggle($toggle_name) { public function deleteFeatureToggle($toggle_name) { $result = FeatureToggle::deleteToggle($toggle_name); if ($result) { - return redirect('/dashboard/admin/toggles')->with('success', 'The toggle `' . $toggle_name . '` has been deleted'); + return redirect('/dashboard/admin/toggles')->with(SessionVariables::SUCCESS->value, 'The toggle `' . $toggle_name . '` has been deleted'); } else { - return redirect('/dashboard/admin/toggles')->with('error', 'The toggle `' . $toggle_name . '` could not be deleted'); + return redirect('/dashboard/admin/toggles')->with(SessionVariables::ERROR->value, 'The toggle `' . $toggle_name . '` could not be deleted'); } } @@ -2081,12 +2082,12 @@ public function saveLiveEventInfo(Request $request) { $audit->what = Auth::user()->full_name.' updated the live event info.'; $audit->save(); - return redirect('/dashboard/admin/live')->with('success', 'The live event info has been updated successfully.'); + return redirect('/dashboard/admin/live')->with(SessionVariables::SUCCESS->value, 'The live event info has been updated successfully.'); } public function removeSoloCertifications(Request $request) { if (!Auth::user()->isAbleTo('roster')) { - return redirect('/dashboard/controllers/roster')->with('error', 'Insufficient permissions.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::ERROR->value, 'Insufficient permissions.'); } $user = User::find($request->id); $user->twr_solo_fields = ''; @@ -2122,6 +2123,6 @@ public function removeSoloCertifications(Request $request) { $audit->ip = $_SERVER['REMOTE_ADDR']; $audit->what = Auth::user()->full_name.' revoked solo certs for '.$user->full_name.'.'; - return redirect('/dashboard/controllers/roster')->with('success', 'Solo certifications removed.'); + return redirect('/dashboard/controllers/roster')->with(SessionVariables::SUCCESS->value, 'Solo certifications removed.'); } } diff --git a/app/Http/Controllers/AtcBookingController.php b/app/Http/Controllers/AtcBookingController.php index 88e38c91c..07bc0fb27 100644 --- a/app/Http/Controllers/AtcBookingController.php +++ b/app/Http/Controllers/AtcBookingController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\AtcBooking; +use App\Enums\SessionVariables; use Auth; use Carbon\Carbon; use Illuminate\Http\Request; @@ -65,20 +66,20 @@ public function createBooking(Request $request) { })->count() > 0; if ($existing) { - return redirect()->back()->with('error', 'A booking already exists for ' . $callsign . ' at this time')->withInput(); + return redirect()->back()->with(SessionVariables::ERROR->value, 'A booking already exists for ' . $callsign . ' at this time')->withInput(); } $type = $request->type; if ($type == AtcBooking::TYPES["EVENT"] && ! (Auth::user()->isAbleTo('events') || Auth::user()->hasRole('events-team'))) { - return redirect()->back()->with('error', 'Only the EC and events team can create event bookings')->withInput(); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only the EC and events team can create event bookings')->withInput(); } if ($type == AtcBooking::TYPES["EXAM"] && ! (Auth::user()->hasRole('ins') || Auth::user()->isAbleTo('snrStaff'))) { - return redirect()->back()->with('error', 'Only instructors can create exam bookings')->withInput(); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only instructors can create exam bookings')->withInput(); } if ($type == AtcBooking::TYPES["MONITORING"] && ! (Auth::user()->isAbleTo('train') || Auth::user()->isAbleTo('snrStaff'))) { - return redirect()->back()->with('error', 'Only mentors and instructors can create monitoring bookings')->withInput(); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only mentors and instructors can create monitoring bookings')->withInput(); } $booking = new AtcBooking; @@ -89,18 +90,18 @@ public function createBooking(Request $request) { $booking->end = $end; $booking->save(); - return redirect('/dashboard/controllers/bookings')->with('success', 'Your booking has been created successfully'); + return redirect('/dashboard/controllers/bookings')->with(SessionVariables::SUCCESS->value, 'Your booking has been created successfully'); } public function deleteBooking($id) { $booking = AtcBooking::find($id); if (! ($booking->cid == Auth::id() || Auth::user()->isAbleTo('snrStaff'))) { - return redirect()->back()->with('error', 'You can only delete your own bookings'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only delete your own bookings'); } $booking->delete(); - return redirect()->back()->with('success', 'Your booking has been deleted successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your booking has been deleted successfully'); } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index a3311b52a..e9fdb49a3 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Enums\SessionVariables; use App\Http\Controllers\Controller; use App\Http\Controllers\VatsimOAuthController; use App\Opt; @@ -36,9 +37,9 @@ public function __construct() { public function login(Request $request) { if (!$request->has('code') || !$request->has('state')) { // User has clicked "login", redirect to Connect $authorizationUrl = $this->provider->getAuthorizationUrl(); // Generates state - $request->session()->put('vatsimauthstate', $this->provider->getState()); + $request->session()->put(SessionVariables::VATSIM_AUTH_STATE->value, $this->provider->getState()); return redirect()->away($authorizationUrl); - } elseif ($request->input('state') !== session()->pull('vatsimauthstate')) { // State mismatch, error + } elseif ($request->input('state') !== session()->pull(SessionVariables::VATSIM_AUTH_STATE->value)) { // State mismatch, error return redirect('/')->withError("Something went wrong, please try again."); } else { // Callback (user has just logged in Connect) return $this->verifyLogin($request); @@ -63,7 +64,7 @@ protected function verifyLogin(Request $request) { ) { return redirect('/')->withError("We need you to grant us all marked permissions"); } - if (session('pilot_redirect')) { + if (session(SessionVariables::REALOPS_PILOT_REDIRECT->value)) { return $this->externalPilotLogin( $resourceOwner->data->cid, $resourceOwner->data->personal->name_first, @@ -95,14 +96,14 @@ protected function vatusaAuth($resourceOwner, $accessToken) { } if (!App::environment('local')) { - return redirect('/')->with('error', 'We are unable to verify your access at this time. Please try again in a few minutes.'); + return redirect('/')->with(SessionVariables::ERROR->value, 'We are unable to verify your access at this time. Please try again in a few minutes.'); } } $resu = json_decode($result->getBody()->__toString(), true); if (! isset($resu['data'])) { - return redirect('/')->with('error', 'We are unable to verify your access at this time. Please try again in a few minutes.'); + return redirect('/')->with(SessionVariables::ERROR->value, 'We are unable to verify your access at this time. Please try again in a few minutes.'); } $res = $resu['data']; @@ -129,13 +130,13 @@ protected function vatusaAuth($resourceOwner, $accessToken) { $message = 'You have been logged in successfully via the dev mode login. A webmaster role has been automatically attached.'; - return redirect()->intended('/dashboard')->with('success', $message); + return redirect()->intended('/dashboard')->with(SessionVariables::SUCCESS->value, $message); } else { $userstatuscheck = User::find($res['cid']); } if (! $userstatuscheck || $userstatuscheck->status == 2) { - return redirect('/')->with('error', 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.'); + return redirect('/')->with(SessionVariables::ERROR->value, 'You have not been found on the roster. If you have recently joined, please allow up to an hour for the roster to update.'); } $userstatuscheck->fname = $res['fname']; @@ -179,7 +180,7 @@ protected function vatusaAuth($resourceOwner, $accessToken) { $message = 'You have been logged in successfully. Please note that you are on an LOA and should not control until off the LOA. If this is an error, please let the DATM know.'; } - return redirect()->intended('/dashboard')->with('success', $message); + return redirect()->intended('/dashboard')->with(SessionVariables::SUCCESS->value, $message); } public function logout() { @@ -190,9 +191,9 @@ public function logout() { } public function realopsLogin() { - session(['pilot_redirect_path' => '/realops']); + session()->put(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value, '/realops'); if (! auth()->check()) { - session(['pilot_redirect' => true]); + session()->put(SessionVariables::REALOPS_PILOT_REDIRECT->value, true); return redirect('/login'); } @@ -213,9 +214,9 @@ public function realopsLogin() { } public function pilotPassportLogin() { - session(['pilot_redirect_path' => '/pilot_passport']); + session()->put(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value, '/pilot_passport'); if (! auth()->check()) { - session(['pilot_redirect' => true]); + session()->put(SessionVariables::REALOPS_PILOT_REDIRECT->value, true); return redirect('/login'); } @@ -253,9 +254,9 @@ private function externalPilotLogin($cid, $fname, $lname, $email) { private function completePilotLogin($pilot) { auth()->guard('realops')->login($pilot); - $redirect_path = session('pilot_redirect_path'); - session()->forget('pilot_redirect'); - session()->forget('pilot_redirect_path'); + $redirect_path = session(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value); + session()->forget(SessionVariables::REALOPS_PILOT_REDIRECT->value); + session()->forget(SessionVariables::REALOPS_PILOT_REDIRECT_PATH->value); return redirect($redirect_path); } } diff --git a/app/Http/Controllers/ControllerDash.php b/app/Http/Controllers/ControllerDash.php index 51acf6e9b..be9427419 100644 --- a/app/Http/Controllers/ControllerDash.php +++ b/app/Http/Controllers/ControllerDash.php @@ -8,6 +8,7 @@ use App\Bronze; use App\Calendar; use App\ControllerLog; +use App\Enums\SessionVariables; use App\Event; use App\EventPosition; use App\EventRegistration; @@ -201,7 +202,7 @@ public function showTicket($id) { if (Auth::id() == $ticket->controller_id) { return view('dashboard.controllers.ticket')->with('ticket', $ticket); } else { - return redirect()->back()->with('error', 'You can only view your own tickets. If you are a trainer trying to view a ticket, please do that from the training section.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only view your own tickets. If you are a trainer trying to view a ticket, please do that from the training section.'); } } @@ -311,7 +312,7 @@ public function showCalendarEvent($id) { public function showFeedbackDetails($id) { $feedback = Feedback::find($id); if ($feedback->controller_id != Auth::id()) { - return redirect('dashboard/controllers/profile')->with('error', 'You\'re not allowed to see this!'); + return redirect('dashboard/controllers/profile')->with(SessionVariables::ERROR->value, 'You\'re not allowed to see this!'); } return view('dashboard.controllers.feedback')->with('feedback', $feedback); @@ -320,7 +321,7 @@ public function showFeedbackDetails($id) { public function showTrainerFeedbackDetails($id) { $feedback = TrainerFeedback::find($id); if ($feedback->trainer_id != Auth::id()) { - return redirect('dashboard/controllers/profile')->with('error', 'You\'re not allowed to see this!'); + return redirect('dashboard/controllers/profile')->with(SessionVariables::ERROR->value, 'You\'re not allowed to see this!'); } return view('dashboard.controllers.trainer_feedback')->with('feedback', $feedback); @@ -382,10 +383,10 @@ public function signupForEvent(Request $request) { } if (!preg_match($valid_time_expr, $request->start_time1)) { - return redirect()->back()->with('error', 'Invalid signup start time. Must be in the format HH:MM, and only contain numbers and `:`.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Invalid signup start time. Must be in the format HH:MM, and only contain numbers and `:`.'); } if (!preg_match($valid_time_expr, $request->end_time1)) { - return redirect()->back()->with('error', 'Invalid signup end time. Must be in the format HH:MM, and only contain numbers and `:`.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Invalid signup end time. Must be in the format HH:MM, and only contain numbers and `:`.'); } if ($request->timezone == '1') { // Local: 1 @@ -394,7 +395,7 @@ public function signupForEvent(Request $request) { } if ($request->num1 == null && $request->yr1 == null) { - return redirect()->back()->with('error', 'You need to select a position to sign up for.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You need to select a position to sign up for.'); } if ($request->num1 != null) { @@ -415,7 +416,7 @@ public function signupForEvent(Request $request) { } } - return redirect('/dashboard/controllers/events/view/'.$id)->with('success', 'Your event registration has been saved successfully.'); + return redirect('/dashboard/controllers/events/view/'.$id)->with(SessionVariables::SUCCESS->value, 'Your event registration has been saved successfully.'); } public function unsignupForEvent($id) { @@ -426,7 +427,7 @@ public function unsignupForEvent($id) { $request->delete(); // Go back - return redirect()->back()->with('success', 'Your registration has been removed successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your registration has been removed successfully.'); } public function sceneryIndex(Request $request) { @@ -465,7 +466,7 @@ public function searchAirportResult(Request $request) { } elseif (strlen($apt) == 4) { $apt_s = strtolower($apt); } else { - return redirect()->back()->with('error', 'You either did not search for an airport or the airport ID is too long.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You either did not search for an airport or the airport ID is too long.'); } $apt_r = strtoupper($apt_s); @@ -474,7 +475,7 @@ public function searchAirportResult(Request $request) { $response = $client->request('GET', 'https://aviationweather.gov/api/data/metar?format=json&taf=true&ids=' . $apt_r); if ($response->getStatusCode() == 404) { - return redirect()->back()->with('error', 'The airport code you entered is invalid.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'The airport code you entered is invalid.'); } $metar = null; @@ -533,7 +534,7 @@ public function searchAirportResult(Request $request) { public function optIn(Request $request) { if ($request->opt != 1 || $request->privacy != 1) { - return redirect()->back()->with('error', 'You have not been opted in. You must select both checkboxes if you would like to continue.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You have not been opted in. You must select both checkboxes if you would like to continue.'); } $opt = new Opt; @@ -547,7 +548,7 @@ public function optIn(Request $request) { $user->opt = 1; $user->save(); - return redirect()->back()->with('success', 'You have been opted in successfully and will now receive broadcast emails from the vZTL ARTCC.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have been opted in successfully and will now receive broadcast emails from the vZTL ARTCC.'); } public function optOut() { @@ -562,7 +563,7 @@ public function optOut() { $user->opt = 0; $user->save(); - return redirect()->back()->with('success', 'You have been opted out successfully and will no longer receive broadcast emails from the vZTL ARTCC.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have been opted out successfully and will no longer receive broadcast emails from the vZTL ARTCC.'); } public function incidentReport() { @@ -592,7 +593,7 @@ public function submitIncidentReport(Request $request) { $incident->status = 0; $incident->save(); - return redirect('/dashboard')->with('success', 'Your report has been submitted successfully.'); + return redirect('/dashboard')->with(SessionVariables::SUCCESS->value, 'Your report has been submitted successfully.'); } public function reportBug(Request $request) { @@ -606,7 +607,7 @@ public function reportBug(Request $request) { Mail::to('wm@ztlartcc.org')->send(new BugReport($reporter, $url, $error, $desc)); - return redirect()->back()->with('success', 'Your bug has been reported successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your bug has been reported successfully.'); } public function updateInfo(Request $request) { @@ -614,7 +615,7 @@ public function updateInfo(Request $request) { $user->ts3 = $request->ts3; $user->timezone = $request->timezone; $user->save(); - return redirect()->back()->with('success', 'Your profile has been updated successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your profile has been updated successfully.'); } public function updateDiscordRoles(Request $request) { @@ -622,7 +623,7 @@ public function updateDiscordRoles(Request $request) { $user_id = $user->discord; if (!$user_id) { - return redirect()->back()->with('error', 'You must have a Discord UID set in order to update your roles.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You must have a Discord UID set in order to update your roles.'); } $response = Http::get('http://bot.ztlartcc.org:3000/assignRoles', [ @@ -630,12 +631,12 @@ public function updateDiscordRoles(Request $request) { ]); if ($response->notFound()) { - return redirect()->back()->with('error', 'You have not been found in the Discord server. Please make sure you are in the server and your id is correct.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You have not been found in the Discord server. Please make sure you are in the server and your id is correct.'); } elseif (!$response->successful()) { - return redirect()->back()->with('error', 'An error occurred while updating your roles. Please try again later.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'An error occurred while updating your roles. Please try again later.'); } - return redirect()->back()->with('success', 'Your roles have been updated successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Your roles have been updated successfully.'); } public function showLiveEventInfo() { diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php index 24019d206..869cfc519 100644 --- a/app/Http/Controllers/CronController.php +++ b/app/Http/Controllers/CronController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Enums\SessionVariables; use Artisan; use Config; use Illuminate\Http\Request; @@ -19,7 +20,7 @@ function command_exists($name) { if ($job != null) { if (command_exists($job)) { Artisan::call($job); - return 'success'; + return SessionVariables::SUCCESS->value; } else { return 'error: That command does not exist.'; } diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index a0d950cee..14eaa0237 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -7,6 +7,7 @@ use App\AtcBooking; use App\Calendar; use App\ControllerLog; +use App\Enums\SessionVariables; use App\Event; use App\Feedback; use App\File; @@ -242,14 +243,14 @@ public function storeVisit(Request $request) { ]); $r = json_decode($response->getBody())->success; if ($r != true && Config::get('app.env') != 'local') { - return redirect()->back()->with('error', 'You must complete the ReCaptcha to continue.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You must complete the ReCaptcha to continue.'); } // Check to see if CID is already active in database (prevents account takeover) if (User::find($request->cid) !== null) { $user = User::find($request->cid); if ($user->status == 1) { - return redirect()->back()->with('error', 'Unable to apply as a visitor - you are already listed as a controller on our roster. If you believe this is in error, contact the ZTL DATM at datm@ztlartcc.org'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Unable to apply as a visitor - you are already listed as a controller on our roster. If you believe this is in error, contact the ZTL DATM at datm@ztlartcc.org'); } } @@ -283,9 +284,9 @@ public function storeVisit(Request $request) { Mail::to($visit->email)->cc('datm@ztlartcc.org')->send(new VisitorMail('new', $visit)); - return redirect('/')->with('success', 'Thank you for your interest in the ZTL ARTCC! Your visit request has been submitted.'); + return redirect('/')->with(SessionVariables::SUCCESS->value, 'Thank you for your interest in the ZTL ARTCC! Your visit request has been submitted.'); } else { - return redirect('/')->with('error', 'You need to be a S1 rated controller or greater'); + return redirect('/')->with(SessionVariables::ERROR->value, 'You need to be a S1 rated controller or greater'); } } @@ -338,7 +339,7 @@ public function saveNewFeedback(Request $request) { ]); $r = json_decode($response->getBody())->success; if ($r != true && Config::get('app.env') != 'local') { - return redirect()->back()->with('error', 'You must complete the ReCaptcha to continue.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You must complete the ReCaptcha to continue.'); } //Continue Request @@ -354,7 +355,7 @@ public function saveNewFeedback(Request $request) { $feedback->status = 0; $feedback->save(); - return redirect('/')->with('success', 'Thank you for the feedback! It has been received successfully.'); + return redirect('/')->with(SessionVariables::SUCCESS->value, 'Thank you for the feedback! It has been received successfully.'); } public function newTrainerFeedback() { @@ -374,7 +375,7 @@ public function showPermalink($slug) { if (!is_null($file)) { return redirect($file->path); } else { - return redirect('/')->with('error', 'The requested resource is not available.'); + return redirect('/')->with(SessionVariables::ERROR->value, 'The requested resource is not available.'); } } @@ -401,7 +402,7 @@ public function staffRequest(Request $request) { ]); $r = json_decode($response->getBody())->success; if ($r != true && Config::get('app.env') != 'local') { - return redirect()->back()->with('error', 'You must complete the ReCaptcha to continue.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You must complete the ReCaptcha to continue.'); } //Continue Request @@ -414,7 +415,7 @@ public function staffRequest(Request $request) { Mail::to('ec@ztlartcc.org')->send(new ReqStaffing($name, $email, $org, $date, $time, $exp)); - return redirect('/')->with('success', 'The staffing request has been delivered to the appropiate parties successfully. You should expect to hear back soon.'); + return redirect('/')->with(SessionVariables::SUCCESS->value, 'The staffing request has been delivered to the appropiate parties successfully. You should expect to hear back soon.'); } public function showAtlRamp() { diff --git a/app/Http/Controllers/MerchStore.php b/app/Http/Controllers/MerchStore.php index d9dc5bdeb..db9bd12ca 100644 --- a/app/Http/Controllers/MerchStore.php +++ b/app/Http/Controllers/MerchStore.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Audit; +use App\Enums\SessionVariables; use App\Merch; use Auth; use Carbon\Carbon; @@ -66,7 +67,7 @@ public function saveItem(Request $request, $id = null) { $audit->what = Auth::user()->full_name.' modified a store item.'; $audit->save(); - return redirect('/dashboard/admin/store')->with('success', 'Store item modified successfully.'); + return redirect('/dashboard/admin/store')->with(SessionVariables::SUCCESS->value, 'Store item modified successfully.'); } public function deleteItem($id) { @@ -79,6 +80,6 @@ public function deleteItem($id) { $audit->what = Auth::user()->full_name.' removed a store item.'; $audit->save(); - return redirect('/dashboard/admin/store')->with('success', 'Store item deleted successfully.'); + return redirect('/dashboard/admin/store')->with(SessionVariables::SUCCESS->value, 'Store item deleted successfully.'); } } diff --git a/app/Http/Controllers/PilotPassportController.php b/app/Http/Controllers/PilotPassportController.php index bf2bd3344..d3f8d0318 100644 --- a/app/Http/Controllers/PilotPassportController.php +++ b/app/Http/Controllers/PilotPassportController.php @@ -4,6 +4,7 @@ ini_set('memory_limit', '512M'); +use App\Enums\SessionVariables; use App\Mail\PilotPassportMail; use App\PilotPassport; use App\PilotPassportAward; @@ -55,7 +56,7 @@ public function enroll(Request $request) { $valid_enrollment = false; } if (!$valid_enrollment) { - return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with('error', 'Enrollment data invalid. Please contact wm@ztlartcc.org for assistance.'); + return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with(SessionVariables::ERROR->value, 'Enrollment data invalid. Please contact wm@ztlartcc.org for assistance.'); } $enrollment = PilotPassportEnrollment::where('cid', $pilot->id)->where('challenge_id', $request->challenge_id)->get(); if ($enrollment->isEmpty()) { @@ -64,24 +65,24 @@ public function enroll(Request $request) { $enrollment->challenge_id = $challenge->id; $enrollment->save(); Mail::to($pilot->email)->send(new PilotPassportMail('enroll', $pilot, $challenge)); - return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with('success', 'You are now enrolled in the ZTL Pilot Passport program!'); + return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with(SessionVariables::SUCCESS->value, 'You are now enrolled in the ZTL Pilot Passport program!'); } - return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with('error', 'You are already enrolled in this challenge.'); + return redirect(route('pilotPassportIndex'))->with(['tab' => 'enrollments'])->with(SessionVariables::ERROR->value, 'You are already enrolled in this challenge.'); } public function setPrivacy(Request $request) { $pilot = auth()->guard('realops')->user(); if (is_null($pilot)) { - return redirect(route('pilotPassportIndex'))->with(['tab' => 'settings'])->with('error', 'Unable to adjust privacy settings - Invalid CID.'); + return redirect(route('pilotPassportIndex'))->with(['tab' => 'settings'])->with(SessionVariables::ERROR->value, 'Unable to adjust privacy settings - Invalid CID.'); } $pilot->privacy = $request->privacy; $pilot->save(); - return redirect(route('pilotPassportIndex'))->with(['tab' => 'settings'])->with('success', 'Your privacy preferences have been saved.'); + return redirect(route('pilotPassportIndex'))->with(['tab' => 'settings'])->with(SessionVariables::SUCCESS->value, 'Your privacy preferences have been saved.'); } public function purgeData(Request $request) { if (strtolower($request->input('confirm_text')) != "confirm - purge all") { - return redirect()->back()->with('error', 'Data not purged. Please type in the required message to continue'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Data not purged. Please type in the required message to continue'); } $pilot = auth()->guard('realops')->user(); PilotPassportEnrollment::where('cid', $pilot->id)->delete(); diff --git a/app/Http/Controllers/RealopsController.php b/app/Http/Controllers/RealopsController.php index 988a68f05..d34fe00e1 100644 --- a/app/Http/Controllers/RealopsController.php +++ b/app/Http/Controllers/RealopsController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Enums\SessionVariables; use App\Exports\RealopsExport; use App\Importers\RealopsFlightImporter; use App\Mail\Realops; @@ -45,11 +46,11 @@ public function bid($id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'That flight doesn\'t exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight doesn\'t exist'); } if ($flight->assigned_pilot_id) { - return redirect()->back()->with('error', 'That flight already has a pilot assigned'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight already has a pilot assigned'); } $pilot = auth()->guard('realops')->user(); @@ -57,24 +58,24 @@ public function bid($id) { Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'bid')); - return redirect()->back()->with('success', 'You have bid for that flight successfully. You should receive a confirmation email soon and will receive email updates regarding your flight'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have bid for that flight successfully. You should receive a confirmation email soon and will receive email updates regarding your flight'); } public function cancelBid($id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'That flight doesn\'t exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight doesn\'t exist'); } $pilot = auth()->guard('realops')->user(); if ($pilot->id != $flight->assigned_pilot_id) { - return redirect()->back()->with('error', 'That flight isn\'t assigned to you'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight isn\'t assigned to you'); } $flight->removeAssignedPilot(); Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'cancel_bid')); - return redirect()->back()->with('success', 'You have removed your bid successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have removed your bid successfully'); } public function adminIndex() { @@ -97,7 +98,7 @@ public function assignPilotToFlight(Request $request, $id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'Unable to assign the pilot to that flight'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Unable to assign the pilot to that flight'); } $pilot = RealopsPilot::find($request->input('pilot')); @@ -105,14 +106,14 @@ public function assignPilotToFlight(Request $request, $id) { Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'assigned_flight')); - return redirect()->back()->with('success', 'That pilot was assigned successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'That pilot was assigned successfully'); } public function removePilotFromFlight($id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'Unable to remove the assigned pilot from that flight'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Unable to remove the assigned pilot from that flight'); } $pilot = $flight->assigned_pilot; @@ -122,7 +123,7 @@ public function removePilotFromFlight($id) { Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'removed_from_flight')); - return redirect()->back()->with('success', 'Pilot unassigned successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'Pilot unassigned successfully'); } public function showCreateFlight() { @@ -150,14 +151,14 @@ public function createFlight(Request $request) { $flight->gate = $request->input('gate'); $flight->save(); - return redirect('/dashboard/admin/realops')->with('success', 'That flight was created successfully'); + return redirect('/dashboard/admin/realops')->with(SessionVariables::SUCCESS->value, 'That flight was created successfully'); } public function showEditFlight($id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'That flight does not exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight does not exist'); } return view('dashboard.admin.realops.edit')->with('flight', $flight); @@ -167,7 +168,7 @@ public function editFlight(Request $request, $id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'That flight does not exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight does not exist'); } $request->validate([ @@ -195,7 +196,7 @@ public function editFlight(Request $request, $id) { Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'flight_updated')); } - return redirect('/dashboard/admin/realops')->with('success', 'That flight was edited successfully'); + return redirect('/dashboard/admin/realops')->with(SessionVariables::SUCCESS->value, 'That flight was edited successfully'); } public function bulkUploadFlights(Request $request) { @@ -218,19 +219,19 @@ public function bulkUploadFlights(Request $request) { Log::info($failure); $errors = $errors.' L'.$failure->row().'#'.$failure->attribute().': '.join(',', $failure->errors()).' ('.$failure->values()[$failure->attribute()].')'; } - return redirect('/dashboard/admin/realops')->with('error', 'Upload failed. Errors: ' . $errors); + return redirect('/dashboard/admin/realops')->with(SessionVariables::ERROR->value, 'Upload failed. Errors: ' . $errors); } catch (\Exception $e) { - return redirect('/dashboard/admin/realops')->with('error', 'Upload failed. Check your formatting: ' . $e->getMessage()); + return redirect('/dashboard/admin/realops')->with(SessionVariables::ERROR->value, 'Upload failed. Check your formatting: ' . $e->getMessage()); } - return redirect('/dashboard/admin/realops')->with('success', 'Upload succeeded'); + return redirect('/dashboard/admin/realops')->with(SessionVariables::SUCCESS->value, 'Upload succeeded'); } public function deleteFlight($id) { $flight = RealopsFlight::find($id); if (! $flight) { - return redirect()->back()->with('error', 'That flight does not exist'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'That flight does not exist'); } $pilot = $flight->assigned_pilot; @@ -240,12 +241,12 @@ public function deleteFlight($id) { Mail::to($pilot->email)->send(new Realops($flight, $pilot, 'flight_cancelled')); } - return redirect()->back()->with('success', 'That flight has been deleted successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'That flight has been deleted successfully'); } public function dumpData(Request $request) { if (strtolower($request->input('confirm_text')) != "confirm - dump all") { - return redirect()->back()->with('error', 'Data not dumped. Please type in the required message to continue'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Data not dumped. Please type in the required message to continue'); } foreach (RealopsFlight::get() as $f) { @@ -256,7 +257,7 @@ public function dumpData(Request $request) { $p->delete(); } - return redirect()->back()->with('success', 'The realops data has been dumped successfully'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The realops data has been dumped successfully'); } public function exportData() { diff --git a/app/Http/Controllers/TrainingDash.php b/app/Http/Controllers/TrainingDash.php index 16fe1d46a..e3103ddcf 100644 --- a/app/Http/Controllers/TrainingDash.php +++ b/app/Http/Controllers/TrainingDash.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Audit; +use App\Enums\SessionVariables; use App\Mail\OtsAssignment; use App\Mail\StudentComment; use App\Mail\TrainingTicketMail; @@ -78,7 +79,7 @@ public function addInfo(Request $request, $section) { $info->section = $request->section; $info->info = $request->info; $info->save(); - return redirect()->back()->with('success', 'The information has been added successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The information has been added successfully.'); } public function deleteInfo($id) { @@ -89,7 +90,7 @@ public function deleteInfo($id) { $o->save(); } $info->delete(); - return redirect()->back()->with('success', 'The information has been removed successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The information has been removed successfully.'); } public function newPublicInfoSection(Request $request) { @@ -111,7 +112,7 @@ public function newPublicInfoSection(Request $request) { $info->order = $request->order; $info->save(); - return redirect('/dashboard/training/info')->with('success', 'The section was added successfully.'); + return redirect('/dashboard/training/info')->with(SessionVariables::SUCCESS->value, 'The section was added successfully.'); } public function editPublicSection(Request $request, $id) { @@ -123,7 +124,7 @@ public function editPublicSection(Request $request, $id) { $section->name = $request->name; $section->save(); - return redirect('/dashboard/training/info')->with('success', 'The section was updated successfully.'); + return redirect('/dashboard/training/info')->with(SessionVariables::SUCCESS->value, 'The section was updated successfully.'); } public function saveSession() { @@ -162,7 +163,7 @@ public function removePublicInfoSection($id) { $p->delete(); } - return redirect('/dashboard/training/info')->with('success', 'The section was removed successfully.'); + return redirect('/dashboard/training/info')->with(SessionVariables::SUCCESS->value, 'The section was removed successfully.'); } public function addPublicPdf(Request $request, $section_id) { @@ -183,14 +184,14 @@ public function addPublicPdf(Request $request, $section_id) { $pdf->pdf_path = $public_url; $pdf->save(); - return redirect('/dashboard/training/info')->with('success', 'The PDF was added successfully.'); + return redirect('/dashboard/training/info')->with(SessionVariables::SUCCESS->value, 'The PDF was added successfully.'); } public function removePublicPdf($id) { $pdf = PublicTrainingInfoPdf::find($id); $pdf->delete(); - return redirect('/dashboard/training/info')->with('success', 'The PDF was removed successfully.'); + return redirect('/dashboard/training/info')->with(SessionVariables::SUCCESS->value, 'The PDF was removed successfully.'); } public function ticketsIndex(Request $request) { @@ -224,7 +225,7 @@ public function ticketsIndex(Request $request) { $t->sort_category = $this->getTicketSortCategory($t->position, $t->draft); } if ($tickets_sort->isEmpty() && ($search_result->status != 1)) { - return redirect()->back()->with('error', 'There is no controller that exists with that CID.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'There is no controller that exists with that CID.'); } $is_trainer_search = true; $exams = null; @@ -242,7 +243,7 @@ public function ticketsIndex(Request $request) { } } else { if ($search_result->status != 1) { - return redirect()->back()->with('error', 'There is no controller that exists with that CID.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'There is no controller that exists with that CID.'); } } @@ -302,7 +303,7 @@ public function searchTickets(Request $request) { } } else { - return redirect()->back()->with('error', 'There is no controller that exists with that CID.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'There is no controller that exists with that CID.'); } } @@ -326,7 +327,7 @@ public function imageUpload(Request $request) { return response()->json([ 'uploaded' => 0, - 'error' => ['message' => 'No file uploaded.'] + SessionVariables::ERROR->value => ['message' => 'No file uploaded.'] ], 400); } @@ -405,7 +406,7 @@ public function handleSaveTicket(Request $request, $id = null) { return $this->draftNewTicket($request, $id); } - return redirect()->back()->with('error', 'Invalid way to save training tickets. Please report this to the webmaster.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Invalid way to save training tickets. Please report this to the webmaster.'); } public function addStudentComments(Request $request, $id) { @@ -416,7 +417,7 @@ public function addStudentComments(Request $request, $id) { $ticket = TrainingTicket::find($id); if (Auth::id() != $ticket->controller_id) { - return redirect()->back()->with('error', 'Not your training ticket'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Not your training ticket'); } $ticket->student_comments = $request->student_comments; @@ -430,7 +431,7 @@ public function addStudentComments(Request $request, $id) { } } $mailer->send(new StudentComment($trainer->full_name, $ticket->id)); - return redirect()->back()->with('success', 'You have successfully added your comments to your training ticket. Please reach out to your mentor or instructor if you have any further questions or concerns'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have successfully added your comments to your training ticket. Please reach out to your mentor or instructor if you have any further questions or concerns'); } public function viewTicket($id) { @@ -458,7 +459,7 @@ public function editTicket($id) { ->with('progress_types', $ticket->getProgressSelectAttribute()) ->with('student_rating', $student->rating_id); } else { - return redirect()->back()->with('error', 'You can only edit tickets that you have submitted unless you are the TA.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only edit tickets that you have submitted unless you are the TA.'); } } @@ -477,9 +478,9 @@ public function deleteTicket($id) { $audit->save(); } - return redirect('/dashboard/training/tickets?id=' . $controller_id)->with('success', 'The ticket has been deleted successfully.'); + return redirect('/dashboard/training/tickets?id=' . $controller_id)->with(SessionVariables::SUCCESS->value, 'The ticket has been deleted successfully.'); } else { - return redirect()->back()->with('error', 'Only the TA can delete non-draft training tickets.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only the TA can delete non-draft training tickets.'); } } @@ -505,23 +506,23 @@ public function acceptRecommendation($id) { $audit->what = Auth::user()->full_name . ' accepted an OTS for ' . User::find($ots->controller_id)->full_name . '.'; $audit->save(); - return redirect()->back()->with('success', 'You have sucessfully accepted this OTS. Please email the controller at ' . User::find($ots->controller_id)->email . ' in order to schedule the OTS.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'You have sucessfully accepted this OTS. Please email the controller at ' . User::find($ots->controller_id)->email . ' in order to schedule the OTS.'); } public function rejectRecommendation($id) { if (!Auth::user()->isAbleTo('snrStaff')) { - return redirect()->back()->with('error', 'Only the TA can reject OTS recommendations.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only the TA can reject OTS recommendations.'); } else { $ots = Ots::find($id); $ots->delete(); - return redirect()->back()->with('success', 'The OTS recommendation has been rejected successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The OTS recommendation has been rejected successfully.'); } } public function assignRecommendation(Request $request, $id) { if (!Auth::user()->isAbleTo('snrStaff')) { - return redirect()->back()->with('error', 'Only the TA can assign OTS recommendations to instructors.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Only the TA can assign OTS recommendations to instructors.'); } else { $ots = Ots::find($id); $ots->status = 1; @@ -539,7 +540,7 @@ public function assignRecommendation(Request $request, $id) { $audit->what = Auth::user()->full_name . ' assigned an OTS for ' . User::find($ots->controller_id)->full_name . ' to ' . User::find($ots->ins_id)->full_name . '.'; $audit->save(); - return redirect()->back()->with('success', 'The OTS has been assigned successfully and the instructor has been notified.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The OTS has been assigned successfully and the instructor has been notified.'); } } @@ -560,9 +561,9 @@ public function completeOTS(Request $request, $id) { $audit->what = Auth::user()->full_name . ' updated an OTS for ' . User::find($ots->controller_id)->full_name . '.'; $audit->save(); - return redirect()->back()->with('success', 'The OTS has been updated successfully!'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The OTS has been updated successfully!'); } else { - return redirect()->back()->with('error', 'This OTS has not been assigned to you.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'This OTS has not been assigned to you.'); } } @@ -578,7 +579,7 @@ public function otsCancel($id) { $audit->what = Auth::user()->full_name . ' cancelled an OTS for ' . User::find($ots->controller_id)->full_name . '.'; $audit->save(); - return redirect()->back()->with('success', 'The OTS has been unassigned from you and cancelled successfully.'); + return redirect()->back()->with(SessionVariables::SUCCESS->value, 'The OTS has been unassigned from you and cancelled successfully.'); } public function getTicketSortCategory($position, $draft) { @@ -847,7 +848,7 @@ public function saveNewTrainerFeedback(Request $request) { $r = json_decode($response->getBody())->success; if ($r != true && Config::get('app.env') != 'local' && $request->input('internal') != 1 && app('router')->getRoutes()->match(app('request')->create(url()->previous()))->getName() != 'internalTrainerFeedback') { - return redirect()->back()->with('error', 'You must complete the ReCaptcha to continue.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You must complete the ReCaptcha to continue.'); } //Continue Request @@ -866,14 +867,14 @@ public function saveNewTrainerFeedback(Request $request) { $feedback->save(); $redirect = ($request->input('redirect_to') == 'internal') ? '/dashboard' : '/'; - return redirect($redirect)->with('success', 'Thank you for the feedback! It has been received successfully.'); + return redirect($redirect)->with(SessionVariables::SUCCESS->value, 'Thank you for the feedback! It has been received successfully.'); } public function handleSchedule() { $user = Auth::user(); if ($user->rating_id == 1 && !$user->onboarding_complete) { - return redirect()->back()->with('error', 'Onboarding must be complete before scheduling a training session. Please refer to the ZTL onboarding course on the VATUSA Academy. Contact the TA with questions or concerns.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'Onboarding must be complete before scheduling a training session. Please refer to the ZTL onboarding course on the VATUSA Academy. Contact the TA with questions or concerns.'); } return redirect("https://scheddy.ztlartcc.org/"); @@ -952,7 +953,7 @@ private function saveNewTicket(Request $request, $id) { } $audit->save(); - return redirect('/dashboard/training/tickets?id=' . $ticket->controller_id)->with('success', 'The training ticket has been submitted successfully' . $extra . '.'); + return redirect('/dashboard/training/tickets?id=' . $ticket->controller_id)->with(SessionVariables::SUCCESS->value, 'The training ticket has been submitted successfully' . $extra . '.'); } private function draftNewTicket(Request $request, $id) { @@ -973,7 +974,7 @@ private function draftNewTicket(Request $request, $id) { $ticket->scheddy_id = $request->scheddy_id; } else { if (!$ticket->draft) { - return redirect()->back()->with('error', 'This ticket has already been finalized and cannot be saved as a draft.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'This ticket has already been finalized and cannot be saved as a draft.'); } } @@ -1000,7 +1001,7 @@ private function draftNewTicket(Request $request, $id) { return response(url('/dashboard/training/tickets/edit/' . $ticket->id)); } - return redirect('/dashboard/training/tickets/edit/' . $ticket->id)->with('success', 'The training ticket has been saved successfully, but not finalized. Please finalize all changes once you are ready.'); + return redirect('/dashboard/training/tickets/edit/' . $ticket->id)->with(SessionVariables::SUCCESS->value, 'The training ticket has been saved successfully, but not finalized. Please finalize all changes once you are ready.'); } private function saveTicket(Request $request, $id) { @@ -1054,9 +1055,9 @@ private function saveTicket(Request $request, $id) { } $audit->save(); - return redirect('/dashboard/training/tickets/view/' . $ticket->id)->with('success', 'The ticket has been updated successfully' . $extra . '.'); + return redirect('/dashboard/training/tickets/view/' . $ticket->id)->with(SessionVariables::SUCCESS->value, 'The ticket has been updated successfully' . $extra . '.'); } else { - return redirect()->back()->with('error', 'You can only edit tickets that you have submitted unless you are the TA.'); + return redirect()->back()->with(SessionVariables::ERROR->value, 'You can only edit tickets that you have submitted unless you are the TA.'); } } diff --git a/app/Http/Middleware/FeatureToggles.php b/app/Http/Middleware/FeatureToggles.php index 9ad1a795d..8efe849ea 100644 --- a/app/Http/Middleware/FeatureToggles.php +++ b/app/Http/Middleware/FeatureToggles.php @@ -2,6 +2,7 @@ namespace App\Http\Middleware; +use App\Enums\FeatureToggles as EnumsFeatureToggles; use App\FeatureToggle; use Closure; use Illuminate\Http\Request; @@ -14,8 +15,8 @@ class FeatureToggles { * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ - public function handle(Request $request, Closure $next, String $toggle_name) { - if (! FeatureToggle::isEnabled($toggle_name)) { + public function handle(Request $request, Closure $next, string $toggle_enum_case) { + if (! FeatureToggle::isEnabled(EnumsFeatureToggles::from($toggle_enum_case))) { abort(404, 'Not found'); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 01e6b2750..c7df652b2 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,11 +2,14 @@ namespace App\Providers; +use App\Enums\FeatureToggles; +use App\Enums\SessionVariables; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\Paginator; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Vite; use Illuminate\Support\ServiceProvider; @@ -20,10 +23,13 @@ public function boot(): void { Schema::defaultStringLength(191); Paginator::useBootstrap(); - Blade::if('toggle', function ($toggle_name) { - return toggleEnabled($toggle_name); + Blade::if('toggle', function ($toggle_enum) { + return toggleEnabled($toggle_enum); }); + View::share('FeatureToggles', FeatureToggles::class); + View::share('SessionVariables', SessionVariables::class); + /** * Paginate a standard Laravel Collection. * diff --git a/resources/views/dashboard/admin/bronze-mic.blade.php b/resources/views/dashboard/admin/bronze-mic.blade.php index 2c2057d03..64bb2573f 100644 --- a/resources/views/dashboard/admin/bronze-mic.blade.php +++ b/resources/views/dashboard/admin/bronze-mic.blade.php @@ -97,7 +97,7 @@
Items below are offered at cost to ZTL members. ZTL ARTCC is sales tax exempt thanks to VATUSA's status as an IRS-recognized 501(c)(3) entity. Please email your order to {{ $merch_email }} with the item name(s) and quantity. We will reply with a confirmation diff --git a/resources/views/dashboard/dashboard.blade.php b/resources/views/dashboard/dashboard.blade.php index c755ef5f9..13fd81a8f 100644 --- a/resources/views/dashboard/dashboard.blade.php +++ b/resources/views/dashboard/dashboard.blade.php @@ -210,7 +210,7 @@
\ No newline at end of file
+
diff --git a/resources/views/inc/messages.blade.php b/resources/views/inc/messages.blade.php
index 35a72786d..5b696ce7d 100644
--- a/resources/views/inc/messages.blade.php
+++ b/resources/views/inc/messages.blade.php
@@ -1,26 +1,24 @@
-Assigned to You - @unlesstoggle('realops_bidding') + @unlesstoggle($FeatureToggles::REALOPS_BIDDING) Cancel Bid @endtoggle
@elseAssigned
@endif - @elseif(toggleEnabled('realops_bidding')) + @elseif(toggleEnabled($FeatureToggles::REALOPS_BIDDING))Open For Bidding
@elseBidding Closed, No Assignment
@endif