Refuse pirep prefile is user not allowed to use aircraft #170

This commit is contained in:
Nabeel Shahzad
2018-02-20 12:59:49 -06:00
parent 8393ae2851
commit 4e43223f3a
8 changed files with 137 additions and 42 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Services;
use App\Repositories\AircraftRepository;
use App\Repositories\SubfleetRepository;
use Illuminate\Support\Collection;
use Log;
@@ -16,15 +17,17 @@ use App\Models\Enums\UserState;
class UserService extends BaseService
{
protected $subfleetRepo;
protected $aircraftRepo, $subfleetRepo;
/**
* UserService constructor.
* @param SubfleetRepository $subfleetRepo
*/
public function __construct(
AircraftRepository $aircraftRepo,
SubfleetRepository $subfleetRepo
) {
$this->aircraftRepo = $aircraftRepo;
$this->subfleetRepo = $subfleetRepo;
}
@@ -83,6 +86,21 @@ class UserService extends BaseService
return $subfleets->with('aircraft')->get();
}
/**
* Return a bool if a user is allowed to fly the current aircraft
* @param $user
* @param $aircraft_id
* @return bool
*/
public function aircraftAllowed($user, $aircraft_id)
{
$aircraft = $this->aircraftRepo->find($aircraft_id, ['subfleet_id']);
$subfleets = $this->getAllowableSubfleets($user);
$subfleet_ids = $subfleets->pluck('id')->toArray();
return \in_array($aircraft->subfleet_id, $subfleet_ids, true);
}
/**
* Change the user's state. PENDING to ACCEPTED, etc
* Send out an email