-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop'
- Loading branch information
Showing
26 changed files
with
533 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace App\Http\Middleware; | ||
|
||
use App\Services\DependencyService; | ||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class UpdateDependency | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @param array $dependencies | ||
* @return mixed | ||
*/ | ||
public function handle(Request $request, Closure $next, ...$dependencies) | ||
{ | ||
foreach ($dependencies as $dependency) { | ||
DependencyService::touchDependencyByKey($dependency, Auth::user()); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Models\Dependency\Dependency; | ||
use App\Models\User\User; | ||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Log; | ||
use LogicException; | ||
|
||
class DependencyService | ||
{ | ||
public static function touchDependencyByKey(string $key, ?User $user): void | ||
{ | ||
$dependency = Dependency::where('key', $key)->first(); | ||
|
||
if (!$dependency) { | ||
Log::error(sprintf('Dependency %s not found to update', $key)); | ||
return; | ||
} | ||
|
||
if ($dependency->per_user && $user === null) { | ||
Log::error(sprintf('Dependency %s is per user but user was not specifieid', $key)); | ||
return; | ||
} | ||
|
||
if ($dependency->per_user) { | ||
self::touchUserDependency($dependency, $user); | ||
} else { | ||
self::touchGlobalDependency($dependency); | ||
} | ||
} | ||
|
||
public static function touchGlobalDependency(Dependency $dependency): void | ||
{ | ||
$dependency->touch(); | ||
} | ||
|
||
public static function touchUserDependency(Dependency $dependency, User $user): void | ||
{ | ||
if (!$dependency->per_user) { | ||
throw new LogicException(sprintf('Dependency %s is not a per-user dependency', $dependency->key)); | ||
} | ||
|
||
$user->dependencies()->updateExistingPivot($dependency->id, ['updated_at' => Carbon::now()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Config for downloading METARs in the context of MSL and RPS | ||
return [ | ||
'vatsim_url' => env('VATSIM_METAR_URL', 'metar.vatsim.net'), | ||
'regional_url' => env('APP_REGIONAL_PRESSURES_URL', 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requesttype=retrieve&format=xml&hoursBeforeNow=3&mostRecentForEachStation=constraint&stationString=~gb&fields=raw_text,station_id'), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'allocation_min' => env('APP_SQUAWK_ALLOCATION_MIN', 45), | ||
]; |
35 changes: 35 additions & 0 deletions
35
database/migrations/2020_04_03_160614_add_user_dependency_column.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddUserDependencyColumn extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('dependencies', function (Blueprint $table) { | ||
$table->boolean('per_user') | ||
->default(false) | ||
->after('local_file') | ||
->comment('If the dependency is per-user'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('dependencies', function (Blueprint $table) { | ||
$table->dropColumn('per_user'); | ||
}); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
database/migrations/2020_04_03_161131_add_per_user_dependencies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use App\Models\Dependency\Dependency; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class AddPerUserDependencies extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Dependency::where('key', 'DEPENDENCY_HOLD_PROFILE') | ||
->update(['per_user' => 1]); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Dependency::where('key', 'DEPENDENCY_HOLD_PROFILE') | ||
->update(['per_user' => 0]); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
database/migrations/2020_04_03_161652_add_dependency_user_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddDependencyUserTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('dependency_user', function (Blueprint $table) { | ||
$table->unsignedMediumInteger('dependency_id')->comment('The dependency'); | ||
$table->unsignedInteger('user_id')->comment('The user the dependency belongs to'); | ||
$table->timestamps(); | ||
|
||
$table->primary(['dependency_id', 'user_id']); | ||
$table->foreign('dependency_id')->references('id')->on('dependencies')->onDelete('cascade'); | ||
$table->foreign('user_id')->references('id')->on('user')->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('dependency_user'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.