Merge pull request #720 from nabeelio/719-Login-On-Leave

Allow on-leave user to login
This commit is contained in:
Nabeel S 2020-05-23 07:47:10 -04:00 committed by GitHub
commit 4cd7eef937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 2 deletions

View File

@ -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));

View File

@ -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
*

View File

@ -5,6 +5,16 @@
<div class="row">
<div class="col-sm-8">
@if(Auth::user()->state === \App\Models\Enums\UserState::ON_LEAVE)
<div class="row">
<div class="col-sm-12">
<div class="alert alert-warning" role="alert">
You are on leave! File a PIREP to set your status to active!
</div>
</div>
</div>
@endif
{{-- TOP BAR WITH BOXES --}}
<div class="row">
<div class="col-sm-3">

View File

@ -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
*/