Skip to content

Commit

Permalink
Merge pull request #480 from Vatsim-Scandinavia/version/v3.3.1
Browse files Browse the repository at this point in the history
Version/v3.3.1
  • Loading branch information
blt950 authored Jan 15, 2023
2 parents c095114 + fefbcf3 commit 7cdb8cd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
5 changes: 3 additions & 2 deletions app/Console/Commands/CheckOnlineControllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)){
Expand Down
68 changes: 44 additions & 24 deletions app/Http/Controllers/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 persists.');
}

$vatsim_booking = json_decode($response->getBody()->getContents());

$booking->vatsim_booking = $vatsim_booking->id;
Expand Down Expand Up @@ -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 persists.');
}

$vatsim_booking = json_decode($response->getBody()->getContents());

Expand Down Expand Up @@ -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 persists.');
}

$vatsim_booking = json_decode($response->getBody()->getContents());

$booking->vatsim_booking = $vatsim_booking->id;
Expand Down Expand Up @@ -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 persists.');
}

}

$booking->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/EndorsementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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.');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Policies/TrainingPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|
*/

'version' => "3.3.0",
'version' => "3.3.1",

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 7cdb8cd

Please sign in to comment.