Don't allow cancels from certain states (#396)
* Don't allow cancels from certain states * Unused imports * Don't reset the state doubly * Move SetUserActive into listener; code cleanup * Unused imports * Add missing files into htaccess * Move Command contract to correct folder
This commit is contained in:
@@ -15,9 +15,6 @@ use League\Geotools\Geotools;
|
||||
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
|
||||
/**
|
||||
* Class AnalyticsService
|
||||
*/
|
||||
class AirportService extends Service
|
||||
{
|
||||
private $airportRepo;
|
||||
|
||||
@@ -4,14 +4,11 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Models\Enums\AnalyticsDimensions;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Irazasyed\LaravelGAMP\Facades\GAMP;
|
||||
use Log;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Class AnalyticsService
|
||||
*/
|
||||
class AnalyticsService extends Service
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -4,11 +4,8 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Support\ClassLoader;
|
||||
use Module;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
/**
|
||||
* Class AwardService
|
||||
*/
|
||||
class AwardService extends Service
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -7,9 +7,6 @@ use App\Support\Database;
|
||||
use Carbon\Carbon;
|
||||
use Webpatser\Uuid\Uuid;
|
||||
|
||||
/**
|
||||
* Class DatabaseService
|
||||
*/
|
||||
class DatabaseService extends Service
|
||||
{
|
||||
protected $time_fields = [
|
||||
|
||||
@@ -11,14 +11,11 @@ use App\Services\ImportExport\FareExporter;
|
||||
use App\Services\ImportExport\FlightExporter;
|
||||
use App\Services\ImportExport\SubfleetExporter;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Csv\CharsetConverter;
|
||||
use League\Csv\Writer;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ExportService
|
||||
*/
|
||||
class ExportService extends Service
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,9 +11,6 @@ use App\Models\Subfleet;
|
||||
use App\Support\Math;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class FareService
|
||||
*/
|
||||
class FareService extends Service
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -15,9 +15,6 @@ use App\Repositories\NavdataRepository;
|
||||
use App\Support\Units\Time;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class FlightService
|
||||
*/
|
||||
class FlightService extends Service
|
||||
{
|
||||
private $airportSvc;
|
||||
|
||||
@@ -16,9 +16,6 @@ use Illuminate\Support\Facades\Log;
|
||||
use League\Geotools\Coordinate\Coordinate;
|
||||
use League\Geotools\Geotools;
|
||||
|
||||
/**
|
||||
* Class GeoService
|
||||
*/
|
||||
class GeoService extends Service
|
||||
{
|
||||
private $acarsRepo;
|
||||
|
||||
@@ -19,9 +19,6 @@ use Illuminate\Validation\ValidationException;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\Reader;
|
||||
|
||||
/**
|
||||
* Class ImportService
|
||||
*/
|
||||
class ImportService extends Service
|
||||
{
|
||||
protected $flightRepo;
|
||||
|
||||
@@ -4,9 +4,6 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
|
||||
/**
|
||||
* Class ModuleService
|
||||
*/
|
||||
class ModuleService extends Service
|
||||
{
|
||||
protected static $adminLinks = [];
|
||||
|
||||
@@ -6,20 +6,19 @@ use App\Contracts\Service;
|
||||
use App\Events\PirepAccepted;
|
||||
use App\Events\PirepFiled;
|
||||
use App\Events\PirepRejected;
|
||||
use App\Events\UserStateChanged;
|
||||
use App\Events\UserStatsChanged;
|
||||
use App\Exceptions\PirepCancelNotAllowed;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Bid;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Enums\PirepSource;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Enums\PirepStatus;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\Navdata;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\PirepFieldValue;
|
||||
use App\Models\User;
|
||||
use App\Repositories\PirepRepository;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -31,19 +30,23 @@ class PirepService extends Service
|
||||
{
|
||||
private $geoSvc;
|
||||
private $pilotSvc;
|
||||
private $pirepRepo;
|
||||
|
||||
/**
|
||||
* PirepService constructor.
|
||||
*
|
||||
* @param GeoService $geoSvc
|
||||
* @param UserService $pilotSvc
|
||||
* @param GeoService $geoSvc
|
||||
* @param PirepRepository $pirepRepo
|
||||
* @param UserService $pilotSvc
|
||||
*/
|
||||
public function __construct(
|
||||
GeoService $geoSvc,
|
||||
PirepRepository $pirepRepo,
|
||||
UserService $pilotSvc
|
||||
) {
|
||||
$this->geoSvc = $geoSvc;
|
||||
$this->pilotSvc = $pilotSvc;
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +210,11 @@ class PirepService extends Service
|
||||
// behavior from the rank that the pilot is assigned to
|
||||
$default_state = PirepState::PENDING;
|
||||
if ($pirep->source === PirepSource::ACARS) {
|
||||
if ($pirep->pilot->rank->auto_approve_acars) {
|
||||
if ($pirep->user->rank->auto_approve_acars) {
|
||||
$default_state = PirepState::ACCEPTED;
|
||||
}
|
||||
} else {
|
||||
if ($pirep->pilot->rank->auto_approve_manual) {
|
||||
if ($pirep->user->rank->auto_approve_manual) {
|
||||
$default_state = PirepState::ACCEPTED;
|
||||
}
|
||||
}
|
||||
@@ -222,21 +225,36 @@ class PirepService extends Service
|
||||
// only update the pilot last state if they are accepted
|
||||
if ($default_state === PirepState::ACCEPTED) {
|
||||
$pirep = $this->accept($pirep);
|
||||
$this->setPilotState($pirep->pilot, $pirep);
|
||||
} else {
|
||||
$pirep->state = $default_state;
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
}
|
||||
|
||||
// Check the user state, set them to ACTIVE if on leave
|
||||
if ($pirep->user->state !== UserState::ACTIVE) {
|
||||
$old_state = $pirep->user->state;
|
||||
$pirep->user->state = UserState::ACTIVE;
|
||||
$pirep->user->save();
|
||||
/**
|
||||
* Cancel a PIREP
|
||||
*
|
||||
* @param Pirep $pirep
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*
|
||||
* @return Pirep
|
||||
*/
|
||||
public function cancel(Pirep $pirep): Pirep
|
||||
{
|
||||
if (in_array($pirep->state, Pirep::$cancel_states, true)) {
|
||||
Log::info('PIREP '.$pirep->id.' can\'t be cancelled, state='.$pirep->state);
|
||||
|
||||
event(new UserStateChanged($pirep->user, $old_state));
|
||||
throw new PirepCancelNotAllowed($pirep);
|
||||
}
|
||||
|
||||
$pirep = $this->pirepRepo->update([
|
||||
'state' => PirepState::CANCELLED,
|
||||
'status' => PirepStatus::CANCELLED,
|
||||
], $pirep->id);
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,12 +342,12 @@ class PirepService extends Service
|
||||
}
|
||||
|
||||
$ft = $pirep->flight_time;
|
||||
$pilot = $pirep->pilot;
|
||||
$pilot = $pirep->user;
|
||||
|
||||
$this->pilotSvc->adjustFlightTime($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightCount($pilot, +1);
|
||||
$this->pilotSvc->calculatePilotRank($pilot);
|
||||
$pirep->pilot->refresh();
|
||||
$pirep->user->refresh();
|
||||
|
||||
// Change the status
|
||||
$pirep->state = PirepState::ACCEPTED;
|
||||
@@ -362,13 +380,13 @@ class PirepService extends Service
|
||||
// If this was previously ACCEPTED, then reconcile the flight hours
|
||||
// that have already been counted, etc
|
||||
if ($pirep->state === PirepState::ACCEPTED) {
|
||||
$pilot = $pirep->pilot;
|
||||
$user = $pirep->user;
|
||||
$ft = $pirep->flight_time * -1;
|
||||
|
||||
$this->pilotSvc->adjustFlightTime($pilot, $ft);
|
||||
$this->pilotSvc->adjustFlightCount($pilot, -1);
|
||||
$this->pilotSvc->calculatePilotRank($pilot);
|
||||
$pirep->pilot->refresh();
|
||||
$this->pilotSvc->adjustFlightTime($user, $ft);
|
||||
$this->pilotSvc->adjustFlightCount($user, -1);
|
||||
$this->pilotSvc->calculatePilotRank($user);
|
||||
$pirep->user->refresh();
|
||||
}
|
||||
|
||||
// Change the status
|
||||
@@ -387,6 +405,7 @@ class PirepService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $pilot
|
||||
* @param Pirep $pirep
|
||||
*/
|
||||
public function setPilotState(User $pilot, Pirep $pirep)
|
||||
|
||||
@@ -21,9 +21,6 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* Class UserService
|
||||
*/
|
||||
class UserService extends Service
|
||||
{
|
||||
private $aircraftRepo;
|
||||
|
||||
Reference in New Issue
Block a user