From f17cd15b017e1586861cf486aa8ab1a97d9fd51d Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 23 May 2020 07:18:28 -0400 Subject: [PATCH] Allow on-leave user to login; show alert message and ensure status is updated #719 --- app/Http/Controllers/Auth/LoginController.php | 3 +- app/Services/PirepService.php | 12 ++++++++ .../layouts/default/dashboard/index.blade.php | 10 +++++++ tests/PIREPTest.php | 30 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 11970d43..2d196151 100755 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -109,8 +109,7 @@ class LoginController extends Controller $user->last_ip = $request->ip(); $user->save(); - // TODO: How to handle ON_LEAVE? - if ($user->state !== UserState::ACTIVE) { + if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) { Log::info('Trying to login '.$user->ident.', state ' .UserState::label($user->state)); diff --git a/app/Services/PirepService.php b/app/Services/PirepService.php index e59685dd..461c034d 100644 --- a/app/Services/PirepService.php +++ b/app/Services/PirepService.php @@ -263,6 +263,18 @@ class PirepService extends Service return $pirep; } + /** + * Alias to submit() + * + * @param \App\Models\Pirep $pirep + * + * @throws \Exception + */ + public function file(Pirep $pirep) + { + return $this->submit($pirep); + } + /** * Submit the PIREP. Figure out its default state * diff --git a/resources/views/layouts/default/dashboard/index.blade.php b/resources/views/layouts/default/dashboard/index.blade.php index 8ab2b3ac..09012f37 100644 --- a/resources/views/layouts/default/dashboard/index.blade.php +++ b/resources/views/layouts/default/dashboard/index.blade.php @@ -5,6 +5,16 @@
+ @if(Auth::user()->state === \App\Models\Enums\UserState::ON_LEAVE) +
+
+ +
+
+ @endif + {{-- TOP BAR WITH BOXES --}}
diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index dd379803..2da8f7d9 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -5,6 +5,7 @@ use App\Models\Aircraft; use App\Models\Bid; use App\Models\Enums\AcarsType; use App\Models\Enums\PirepState; +use App\Models\Enums\UserState; use App\Models\Pirep; use App\Models\User; use App\Notifications\Messages\PirepAccepted; @@ -18,7 +19,10 @@ use Illuminate\Support\Facades\Notification; class PIREPTest extends TestCase { + /** @var PirepService */ protected $pirepSvc; + + /** @var SettingRepository */ protected $settingsRepo; public function setUp(): void @@ -62,6 +66,7 @@ class PIREPTest extends TestCase public function testAddPirep() { $user = factory(App\Models\User::class)->create(); + $route = $this->createNewRoute(); $pirep = factory(App\Models\Pirep::class)->create([ 'user_id' => $user->id, @@ -325,6 +330,31 @@ class PIREPTest extends TestCase $this->assertEquals(120, $aircraft->flight_time); } + /** + * When a PIREP is filed by a user on leave, make sure they flip from leave to active + * It doesn't matter if the PIREP is accepted or rejected + */ + public function testPilotStatusChange() + { + /** @var \App\Models\User $user */ + $user = factory(User::class)->create([ + 'state' => UserState::ON_LEAVE, + ]); + + // Submit two PIREPs + // 1 hour flight times, but the rank should bump up because of the transfer hours + $pirep = factory(Pirep::class)->create([ + 'airline_id' => $user->airline_id, + 'user_id' => $user->id, + ]); + + $this->pirepSvc->create($pirep); + $this->pirepSvc->file($pirep); + + $user = User::find($user->id); + $this->assertEquals(UserState::ACTIVE, $user->state); + } + /** * Find and check for any duplicate PIREPs by a user */