Allow on-leave user to login; show alert message and ensure status is updated #719
This commit is contained in:
parent
5f8053226e
commit
f17cd15b01
@ -109,8 +109,7 @@ class LoginController extends Controller
|
|||||||
$user->last_ip = $request->ip();
|
$user->last_ip = $request->ip();
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
// TODO: How to handle ON_LEAVE?
|
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
|
||||||
if ($user->state !== UserState::ACTIVE) {
|
|
||||||
Log::info('Trying to login '.$user->ident.', state '
|
Log::info('Trying to login '.$user->ident.', state '
|
||||||
.UserState::label($user->state));
|
.UserState::label($user->state));
|
||||||
|
|
||||||
|
@ -263,6 +263,18 @@ class PirepService extends Service
|
|||||||
return $pirep;
|
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
|
* Submit the PIREP. Figure out its default state
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,16 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-8">
|
<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 --}}
|
{{-- TOP BAR WITH BOXES --}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
|
@ -5,6 +5,7 @@ use App\Models\Aircraft;
|
|||||||
use App\Models\Bid;
|
use App\Models\Bid;
|
||||||
use App\Models\Enums\AcarsType;
|
use App\Models\Enums\AcarsType;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\Messages\PirepAccepted;
|
use App\Notifications\Messages\PirepAccepted;
|
||||||
@ -18,7 +19,10 @@ use Illuminate\Support\Facades\Notification;
|
|||||||
|
|
||||||
class PIREPTest extends TestCase
|
class PIREPTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/** @var PirepService */
|
||||||
protected $pirepSvc;
|
protected $pirepSvc;
|
||||||
|
|
||||||
|
/** @var SettingRepository */
|
||||||
protected $settingsRepo;
|
protected $settingsRepo;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
@ -62,6 +66,7 @@ class PIREPTest extends TestCase
|
|||||||
public function testAddPirep()
|
public function testAddPirep()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$user = factory(App\Models\User::class)->create();
|
||||||
|
|
||||||
$route = $this->createNewRoute();
|
$route = $this->createNewRoute();
|
||||||
$pirep = factory(App\Models\Pirep::class)->create([
|
$pirep = factory(App\Models\Pirep::class)->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
@ -325,6 +330,31 @@ class PIREPTest extends TestCase
|
|||||||
$this->assertEquals(120, $aircraft->flight_time);
|
$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
|
* Find and check for any duplicate PIREPs by a user
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user