Check for airline being active; fix tests for L7 #718
This commit is contained in:
@@ -6,10 +6,10 @@ $factory->define(App\Models\Aircraft::class, function (Faker $faker) {
|
||||
return [
|
||||
'id' => null,
|
||||
'subfleet_id' => function () {
|
||||
return factory(App\Models\Subfleet::class)->create()->id;
|
||||
return factory(\App\Models\Subfleet::class)->create()->id;
|
||||
},
|
||||
'airport_id' => function () {
|
||||
return factory(App\Models\Airport::class)->create()->id;
|
||||
return factory(\App\Models\Airport::class)->create()->id;
|
||||
},
|
||||
'iata' => $faker->unique()->text(5),
|
||||
'icao' => $faker->unique()->text(5),
|
||||
|
||||
@@ -8,19 +8,19 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) {
|
||||
return [
|
||||
'id' => $faker->unique()->numberBetween(10, 10000000),
|
||||
'airline_id' => function () {
|
||||
return factory(App\Models\Airline::class)->create()->id;
|
||||
return factory(\App\Models\Airline::class)->create()->id;
|
||||
},
|
||||
'flight_number' => $faker->unique()->numberBetween(10, 1000000),
|
||||
'route_code' => $faker->randomElement(['', $faker->text(5)]),
|
||||
'route_leg' => $faker->randomElement(['', $faker->numberBetween(0, 1000)]),
|
||||
'dpt_airport_id' => function () {
|
||||
return factory(App\Models\Airport::class)->create()->id;
|
||||
return factory(\App\Models\Airport::class)->create()->id;
|
||||
},
|
||||
'arr_airport_id' => function () {
|
||||
return factory(App\Models\Airport::class)->create()->id;
|
||||
return factory(\App\Models\Airport::class)->create()->id;
|
||||
},
|
||||
'alt_airport_id' => function () {
|
||||
return factory(App\Models\Airport::class)->create()->id;
|
||||
return factory(\App\Models\Airport::class)->create()->id;
|
||||
},
|
||||
'distance' => $faker->numberBetween(1, 1000),
|
||||
'route' => null,
|
||||
|
||||
@@ -6,7 +6,7 @@ $factory->define(App\Models\JournalTransactions::class, function (Faker $faker)
|
||||
return [
|
||||
'transaction_group' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
|
||||
'journal_id' => function () {
|
||||
return factory(App\Models\Journal::class)->create()->id;
|
||||
return factory(\App\Models\Journal::class)->create()->id;
|
||||
},
|
||||
'credit' => $faker->numberBetween(100, 10000),
|
||||
'debit' => $faker->numberBetween(100, 10000),
|
||||
|
||||
@@ -6,7 +6,7 @@ $factory->define(App\Models\News::class, function (Faker $faker) {
|
||||
return [
|
||||
'id' => null,
|
||||
'user_id' => function () {
|
||||
return factory(App\Models\User::class)->create()->id;
|
||||
return factory(\App\Models\User::class)->create()->id;
|
||||
},
|
||||
'subject' => $faker->text(),
|
||||
'body' => $faker->sentence,
|
||||
|
||||
@@ -10,8 +10,8 @@ use Faker\Generator as Faker;
|
||||
* Create a new PIREP
|
||||
*/
|
||||
$factory->define(App\Models\Pirep::class, function (Faker $faker) {
|
||||
$airline = factory(App\Models\Airline::class)->create();
|
||||
$flight = factory(App\Models\Flight::class)->create([
|
||||
$airline = factory(\App\Models\Airline::class)->create();
|
||||
$flight = factory(\App\Models\Flight::class)->create([
|
||||
'airline_id' => $airline->id,
|
||||
]);
|
||||
|
||||
@@ -21,10 +21,10 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) {
|
||||
return $airline->id;
|
||||
},
|
||||
'user_id' => function () {
|
||||
return factory(App\Models\User::class)->create()->id;
|
||||
return factory(\App\Models\User::class)->create()->id;
|
||||
},
|
||||
'aircraft_id' => function () {
|
||||
return factory(App\Models\Aircraft::class)->create()->id;
|
||||
return factory(\App\Models\Aircraft::class)->create()->id;
|
||||
},
|
||||
'flight_id' => function () use ($flight) {
|
||||
return $flight->id;
|
||||
|
||||
@@ -6,7 +6,7 @@ $factory->define(App\Models\Subfleet::class, function (Faker $faker) {
|
||||
return [
|
||||
'id' => null,
|
||||
'airline_id' => function () {
|
||||
return factory(App\Models\Airline::class)->create()->id;
|
||||
return factory(\App\Models\Airline::class)->create()->id;
|
||||
},
|
||||
'name' => $faker->unique()->text(50),
|
||||
'type' => $faker->unique()->text(7),
|
||||
|
||||
@@ -14,7 +14,7 @@ $factory->define(App\Models\User::class, function (Faker $faker) {
|
||||
'password' => $password ?: $password = Hash::make('secret'),
|
||||
'api_key' => $faker->sha1,
|
||||
'airline_id' => function () {
|
||||
return factory(App\Models\Airline::class)->create()->id;
|
||||
return factory(\App\Models\Airline::class)->create()->id;
|
||||
},
|
||||
'rank_id' => 1,
|
||||
'flights' => $faker->numberBetween(0, 1000),
|
||||
|
||||
@@ -12,3 +12,11 @@ airlines:
|
||||
active: 1
|
||||
created_at: now
|
||||
updated_at: now
|
||||
- id: 2
|
||||
icao: XXX
|
||||
iata: XX
|
||||
name: inactive airline
|
||||
country: us
|
||||
active: 0
|
||||
created_at: now
|
||||
updated_at: now
|
||||
|
||||
@@ -6,8 +6,6 @@ use App\Exceptions\Converters\GenericExceptionAbstract;
|
||||
use App\Exceptions\Converters\SymfonyException;
|
||||
use App\Exceptions\Converters\ValidationException;
|
||||
use App\Http\Middleware\SetActiveTheme;
|
||||
use Exception;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
@@ -16,7 +14,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException as IlluminateValidationException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
|
||||
@@ -78,29 +78,32 @@ class FlightController extends Controller
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
$where = [
|
||||
'active' => true,
|
||||
'visible' => true,
|
||||
];
|
||||
|
||||
// Allow the option to bypass some of these restrictions for the searches
|
||||
if (!$request->filled('ignore_restrictions')
|
||||
|| $request->get('ignore_restrictions') === '0'
|
||||
) {
|
||||
if (!$request->filled('ignore_restrictions') || $request->get('ignore_restrictions') === '0') {
|
||||
if (setting('pilots.restrict_to_company')) {
|
||||
$where['airline_id'] = Auth::user()->airline_id;
|
||||
$where['airline_id'] = $user->airline_id;
|
||||
}
|
||||
|
||||
if (setting('pilots.only_flights_from_current')) {
|
||||
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
|
||||
$where['dpt_airport_id'] = $user->curr_airport_id;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$this->flightRepo->resetCriteria();
|
||||
$this->flightRepo->searchCriteria($request);
|
||||
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where, [
|
||||
'airline' => ['active' => true],
|
||||
]));
|
||||
|
||||
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
||||
|
||||
$flights = $this->flightRepo
|
||||
|
||||
@@ -75,8 +75,9 @@ class FlightController extends Controller
|
||||
public function search(Request $request)
|
||||
{
|
||||
$where = [
|
||||
'active' => true,
|
||||
'visible' => true,
|
||||
'active' => true,
|
||||
'visible' => true,
|
||||
'airlines.active' => true,
|
||||
];
|
||||
|
||||
if (setting('pilots.restrict_to_company')) {
|
||||
|
||||
@@ -27,14 +27,19 @@ class AirlineRepository extends Repository implements CacheableInterface
|
||||
/**
|
||||
* Return the list of airline formatted for a select box
|
||||
*
|
||||
* @param mixed $add_blank
|
||||
* @param bool $add_blank
|
||||
* @param bool $only_active
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList($add_blank = false): array
|
||||
public function selectBoxList($add_blank = false, $only_active = true): array
|
||||
{
|
||||
$retval = [];
|
||||
$items = $this->all();
|
||||
$where = [
|
||||
'active' => $only_active,
|
||||
];
|
||||
|
||||
$items = $this->findWhere($where);
|
||||
|
||||
if ($add_blank) {
|
||||
$retval[''] = '';
|
||||
|
||||
Reference in New Issue
Block a user