Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow cancels from certain states #396

Merged
merged 7 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RedirectMatch 403 ^/storage/.*?$
RedirectMatch 403 ^/tests/.*?$
RedirectMatch 403 ^/vendor/.*?$
RedirectMatch 403 ^/.bowerrc$
RedirectMatch 403 ^/.env
RedirectMatch 403 ^/artisan$
RedirectMatch 403 ^/composer.json
RedirectMatch 403 ^/composer.lock
Expand All @@ -32,6 +33,7 @@ RedirectMatch 403 ^/package.json
RedirectMatch 403 ^/package-lock.json
RedirectMatch 403 ^/phpunit.xml
RedirectMatch 403 ^/webpack.mix.js
RedirectMatch 403 ^/yarn.lock

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AcarsReplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Facades\Utils;
use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Collection;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use Illuminate\Support\Facades\Artisan;

class ComposerCommand extends Command
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use Illuminate\Support\Facades\Log;
use Tivie\OS\Detector;

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/DevCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Models\Acars;
use App\Models\Airline;
use App\Models\Pirep;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/DevInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use Modules\Installer\Services\ConfigService;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ImportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Services\ImportService;

class ImportCsv extends Command
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ImportFromClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;

class ImportFromClassic extends Command
{
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/NavdataImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Models\Enums\NavaidType;
use App\Models\Navdata;

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/TestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use GuzzleHttp\Client;

class TestApi extends Command
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Services\VersionService;
use Symfony\Component\Yaml\Yaml;

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/YamlExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use DB;
use Symfony\Component\Yaml\Yaml;

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/YamlImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Commands;

use App\Console\Command;
use App\Contracts\Command;
use App\Services\DatabaseService;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Cron/Hourly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Cron;

use App\Console\Command;
use App\Contracts\Command;
use App\Events\CronHourly;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Cron/Monthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Cron;

use App\Console\Command;
use App\Contracts\Command;
use App\Events\CronMonthly;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Cron/Nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Cron;

use App\Console\Command;
use App\Contracts\Command;
use App\Events\CronNightly;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Cron/Weekly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Console\Cron;

use App\Console\Command;
use App\Contracts\Command;
use App\Events\CronWeekly;

/**
Expand Down
15 changes: 9 additions & 6 deletions app/Console/Command.php → app/Contracts/Command.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Console;
namespace App\Contracts;

use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Process;
Expand All @@ -10,6 +10,14 @@
*/
abstract class Command extends \Illuminate\Console\Command
{
/**
* @return mixed
*/
abstract public function handle();

/**
* Adjust the logging depending on where we're running from
*/
public function __construct()
{
parent::__construct();
Expand All @@ -20,11 +28,6 @@ public function __construct()
}
}

/**
* @return mixed
*/
abstract public function handle();

/**
* Splice the logger and replace the active handlers with the handlers from the
* a stack in config/logging.php
Expand Down
2 changes: 2 additions & 0 deletions app/Contracts/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*
* @property mixed $id
* @property bool $skip_mutator
*
* @method static where(array $array)
*/
abstract class Model extends \Illuminate\Database\Eloquent\Model
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use App\Models\Enums\PirepState;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class PirepsChangeStateType extends Migration
{
/**
* Change the PIREP state column to be a TINYINT
*
* @return void
*/
public function up()
{
// Migrate the old rejected state
DB::update('UPDATE `pireps` SET `state`='.PirepState::REJECTED
.' WHERE state=-1');

// Change the column type to an unsigned small int (tinyint not supported on all)
Schema::table('pireps', function (Blueprint $table) {
$table->unsignedSmallInteger('state')->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
40 changes: 40 additions & 0 deletions app/Exceptions/PirepCancelNotAllowed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Exceptions;

use App\Models\Pirep;

class PirepCancelNotAllowed extends HttpException
{
private $pirep;

public function __construct(Pirep $pirep)
{
$this->pirep = $pirep;
parent::__construct(
400,
'This PIREP can\'t be cancelled'
);
}

/**
* Return the RFC 7807 error type (without the URL root)
*/
public function getErrorType(): string
{
return 'pirep-cancel-not-allowed';
}

public function getErrorDetails(): string
{
return $this->getMessage();
}

public function getErrorMetadata(): array
{
return [
'pirep_id' => $this->pirep->id,
'state' => $this->pirep->state,
];
}
}
6 changes: 2 additions & 4 deletions app/Http/Controllers/Api/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,8 @@ public function cancel($pirep_id, Request $request)
{
Log::info('PIREP Cancel, user '.Auth::id(), $request->post());

$pirep = $this->pirepRepo->update([
'state' => PirepState::CANCELLED,
'status' => PirepStatus::CANCELLED,
], $pirep_id);
$pirep = Pirep::find($pirep_id);
$this->pirepSvc->cancel($pirep);

return new PirepResource($pirep);
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Route::post('pireps/{pirep_id}/update', 'PirepController@update');
Route::post('pireps/{pirep_id}/file', 'PirepController@file');
Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post');
Route::put('pireps/{pirep_id}/cancel', 'PirepController@cancel');
Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel');

Route::get('pireps/{pirep_id}/fields', 'PirepController@fields_get');
Expand Down
23 changes: 23 additions & 0 deletions app/Listeners/SetUserActive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Listeners;

use App\Contracts\Listener;
use App\Events\PirepFiled;
use App\Events\UserStateChanged;
use App\Models\Enums\UserState;

class SetUserActive extends Listener
{
public function handle(PirepFiled $event): void
{
// Check the user state, set them to ACTIVE if on leave
if ($event->pirep->user->state !== UserState::ACTIVE) {
$old_state = $event->pirep->user->state;
$event->pirep->user->state = UserState::ACTIVE;
$event->pirep->user->save();

event(new UserStateChanged($event->pirep->user, $old_state));
}
}
}
3 changes: 3 additions & 0 deletions app/Models/Aircraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
/**
* @property int id
* @property mixed subfleet_id
* @property string airport_id The apt where the aircraft is
* @property string name
* @property string icao
* @property string registration
* @property int flight_time
* @property string hex_code
* @property Airport airport
* @property Subfleet subfleet
* @property int status
* @property int state
* @property Carbon landing_time
*/
class Aircraft extends Model
{
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Enums/AcarsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Contracts\Enum;

/**
* Class AcarsType
*/
class AcarsType extends Enum
{
public const FLIGHT_PATH = 0;
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Enums/ActiveState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Contracts\Enum;

/**
* Class ActiveState
*/
class ActiveState extends Enum
{
public const INACTIVE = 0;
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Enums/AircraftState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Contracts\Enum;

/**
* Class AircraftState
*/
class AircraftState extends Enum
{
public const PARKED = 0;
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Enums/AircraftStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Contracts\Enum;

/**
* Class AircraftState
*/
class AircraftStatus extends Enum
{
public const ACTIVE = 'A';
Expand Down
3 changes: 0 additions & 3 deletions app/Models/Enums/AnalyticsDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Contracts\Enum;

/**
* Class AnalyticsDimensions
*/
class AnalyticsDimensions extends Enum
{
public const PHP_VERSION = 1;
Expand Down
Loading