From be590113fdef312eb3def2a643c4ec14f7e0b19a Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Jan 2023 20:45:22 +0100 Subject: [PATCH 1/6] #477 Catch booking errors --- app/Http/Controllers/BookingController.php | 68 ++++++++++++++-------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 3cb592f78..95fb0c571 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -13,6 +13,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use anlutro\LaravelSettings\Facade as Setting; +use App\Exceptions\VatsimAPIException; /** * Controller for handling bookings. @@ -167,16 +168,20 @@ public function store(Request $request) if(App::environment('production')) { $client = new \GuzzleHttp\Client(); - $url = $this->getVatsimBookingUrl('post'); - $response = $this->makeHttpRequest($client, $url, 'post', [ - 'callsign' => (string)$booking->callsign, - 'cid' => $booking->user_id, - 'type' => $type, - 'start' => $booking->time_start->format('Y-m-d H:i:s'), - 'end' => $booking->time_end->format('Y-m-d H:i:s'), - ]); + try{ + $response = $this->makeHttpRequest($client, $url, 'post', [ + 'callsign' => (string)$booking->callsign, + 'cid' => $booking->user_id, + 'type' => $type, + 'start' => $booking->time_start->format('Y-m-d H:i:s'), + 'end' => $booking->time_end->format('Y-m-d H:i:s'), + ]); + } catch(VatsimAPIException $e){ + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + } + $vatsim_booking = json_decode($response->getBody()->getContents()); $booking->vatsim_booking = $vatsim_booking->id; @@ -287,15 +292,19 @@ public function storeBulk(Request $request) if(App::environment('production')) { $client = new \GuzzleHttp\Client(); - $url = $this->getVatsimBookingUrl('post'); - $response = $this->makeHttpRequest($client, $url, 'post', [ - 'callsign' => (string)$booking->callsign, - 'cid' => $booking->user_id, - 'type' => $type, - 'start' => $booking->time_start->format('Y-m-d H:i:s'), - 'end' => $booking->time_end->format('Y-m-d H:i:s'), - ]); + + try{ + $response = $this->makeHttpRequest($client, $url, 'post', [ + 'callsign' => (string)$booking->callsign, + 'cid' => $booking->user_id, + 'type' => $type, + 'start' => $booking->time_start->format('Y-m-d H:i:s'), + 'end' => $booking->time_end->format('Y-m-d H:i:s'), + ]); + } catch(VatsimAPIException $e){ + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + } $vatsim_booking = json_decode($response->getBody()->getContents()); @@ -410,14 +419,19 @@ public function update(Request $request) if(App::environment('production')) { $client = new \GuzzleHttp\Client(); $url = $this->getVatsimBookingUrl('put', $booking->vatsim_booking); - $response = $this->makeHttpRequest($client, $url, 'put', [ - 'callsign' => (string)$booking->callsign, - 'cid' => $booking->user_id, - 'type' => $type, - 'start' => $booking->time_start->format('Y-m-d H:i:s'), - 'end' => $booking->time_end->format('Y-m-d H:i:s'), - ]); + try{ + $response = $this->makeHttpRequest($client, $url, 'put', [ + 'callsign' => (string)$booking->callsign, + 'cid' => $booking->user_id, + 'type' => $type, + 'start' => $booking->time_start->format('Y-m-d H:i:s'), + 'end' => $booking->time_end->format('Y-m-d H:i:s'), + ]); + } catch(VatsimAPIException $e){ + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + } + $vatsim_booking = json_decode($response->getBody()->getContents()); $booking->vatsim_booking = $vatsim_booking->id; @@ -453,7 +467,13 @@ public function delete($id) if(App::environment('production')) { $client = new \GuzzleHttp\Client(); $url = $this->getVatsimBookingUrl('delete', $booking->vatsim_booking); - $response = $this->makeHttpRequest($client, $url, 'delete'); + + try{ + $response = $this->makeHttpRequest($client, $url, 'delete'); + } catch(VatsimAPIException $e){ + return redirect(route('booking'))->withErrors('Booking deletion failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + } + } $booking->save(); From 1fceb9eebb4f8b14da2fe3d7de493b2c1d85459f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Jan 2023 20:57:01 +0100 Subject: [PATCH 2/6] Fixed #479 --- app/Http/Controllers/EndorsementController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/EndorsementController.php b/app/Http/Controllers/EndorsementController.php index 02de8498b..a3f627282 100644 --- a/app/Http/Controllers/EndorsementController.php +++ b/app/Http/Controllers/EndorsementController.php @@ -177,6 +177,7 @@ public function store(Request $request) $user = User::find($data['user']); $trainingType = $data['trainingType']; $expireInfinite = isset($data['expireInf']) ? true : false; + $linkedToTraining = true; // Let's validate the expire date if(!$expireInfinite){ @@ -191,16 +192,15 @@ public function store(Request $request) } } else { $expireDate = null; + $linkedToTraining = false; } // Validate that this user has other endrosement of this type from before if($user->hasActiveEndorsement($trainingType)) return back()->withInput()->withErrors($user->name.' has already an active '.$trainingType.' training endorsement. Revoke it first, to create a new one.'); - // if its not a infinite endorsement, make sure it's tried an actual training - $linkedToTraining = false; + // If it's not a infinite endorsement, it has to be tied to an existing training if(!$expireInfinite && $user->trainings->where('status', '>=', 0)->count() == 0){ - $linkedToTraining = true; return back()->withInput()->withErrors($user->name.' has no active training to link this endorsement to.'); } From c0637f44698a838617206ac32caef81f55f9f5e8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Jan 2023 20:58:17 +0100 Subject: [PATCH 3/6] Typo --- app/Http/Controllers/BookingController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 95fb0c571..090d068bf 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -179,7 +179,7 @@ public function store(Request $request) 'end' => $booking->time_end->format('Y-m-d H:i:s'), ]); } catch(VatsimAPIException $e){ - return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue persists.'); } $vatsim_booking = json_decode($response->getBody()->getContents()); @@ -303,7 +303,7 @@ public function storeBulk(Request $request) 'end' => $booking->time_end->format('Y-m-d H:i:s'), ]); } catch(VatsimAPIException $e){ - return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue persists.'); } $vatsim_booking = json_decode($response->getBody()->getContents()); @@ -429,7 +429,7 @@ public function update(Request $request) 'end' => $booking->time_end->format('Y-m-d H:i:s'), ]); } catch(VatsimAPIException $e){ - return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + return redirect(route('booking'))->withErrors('Booking failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue persists.'); } $vatsim_booking = json_decode($response->getBody()->getContents()); @@ -471,7 +471,7 @@ public function delete($id) try{ $response = $this->makeHttpRequest($client, $url, 'delete'); } catch(VatsimAPIException $e){ - return redirect(route('booking'))->withErrors('Booking deletion failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue proceeds.'); + return redirect(route('booking'))->withErrors('Booking deletion failed with error '.$e->code.': '.$e->message.'. Please contact staff if this issue persists.'); } } From 540b35fec3849346578dc02b17a160af1dc44edc Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 4 Jan 2023 20:58:29 +0100 Subject: [PATCH 4/6] Version bump --- config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/app.php b/config/app.php index 869c7eae8..27d208b45 100755 --- a/config/app.php +++ b/config/app.php @@ -25,7 +25,7 @@ | */ - 'version' => "3.3.0", + 'version' => "3.3.1", /* |-------------------------------------------------------------------------- From 5b7d6d88294fa91c18e7cd5b51ced40302e46b34 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Jan 2023 10:18:39 +0100 Subject: [PATCH 5/6] Disallowed S1 applying for S2 #478 --- app/Http/Controllers/DashboardController.php | 2 +- app/Policies/TrainingPolicy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 862beab73..e74909c78 100755 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -57,7 +57,7 @@ public function index() // If the user belongs to our subdivision, doesn't have any training requests, has S2+ rating and is marked as inactive -> show notice $allowedSubDivisions = explode(',', Setting::get('trainingSubDivisions')); - $atcInactiveMessage = ((in_array($user->handover->subdivision, $allowedSubDivisions) && $allowedSubDivisions != null) && (!$user->hasActiveTrainings(true) && $user->rating > 2 && !$user->active) && !$user->hasRecentlyCompletedTraining()); + $atcInactiveMessage = ((in_array($user->handover->subdivision, $allowedSubDivisions) && $allowedSubDivisions != null) && (!$user->hasActiveTrainings(true) && $user->rating > 1 && !$user->active) && !$user->hasRecentlyCompletedTraining()); $completedTrainingMessage = $user->hasRecentlyCompletedTraining(); $workmailRenewal = (isset($user->setting_workmail_expire)) ? (Carbon::parse($user->setting_workmail_expire)->diffInDays(Carbon::now(), false) > -7) : false; diff --git a/app/Policies/TrainingPolicy.php b/app/Policies/TrainingPolicy.php index b295f2cec..6cf27a873 100644 --- a/app/Policies/TrainingPolicy.php +++ b/app/Policies/TrainingPolicy.php @@ -97,7 +97,7 @@ public function apply(User $user) } // Not active users are forced to ask for a manual creation of refresh - if(!$user->hasActiveTrainings(true) && $user->rating > 2 && !$user->active){ + if(!$user->hasActiveTrainings(true) && $user->rating > 1 && !$user->active){ return Response::deny("Your ATC rating is inactive in {$divisionName}"); } From fefbcf349f2737a80e2a90c30626f34645d03ca2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Jan 2023 11:26:19 +0100 Subject: [PATCH 6/6] Fixed array error in CheckOnlineControler --- app/Console/Commands/CheckOnlineControllers.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/CheckOnlineControllers.php b/app/Console/Commands/CheckOnlineControllers.php index 51b072451..d2639965c 100644 --- a/app/Console/Commands/CheckOnlineControllers.php +++ b/app/Console/Commands/CheckOnlineControllers.php @@ -10,6 +10,7 @@ use App\Notifications\InactiveOnlineStaffNotification; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Http; use Carbon\Carbon; use anlutro\LaravelSettings\Facade as Setting; @@ -59,8 +60,8 @@ public function handle() $this->info("Collecting online controllers..."); // Fetch the latest URI to data feed - $dataUri = json_decode(file_get_contents('https://status.vatsim.net/status.json'))->data->v3[0]; - $vatsimData = json_decode(file_get_contents($dataUri))->controllers; + $dataUri = Http::get('https://status.vatsim.net/status.json')['data']['v3'][0]; + $vatsimData = Http::get($dataUri)['controllers']; foreach($vatsimData as $d){ if(preg_match($areasRegex, $d->callsign)){