Skip to content

Commit

Permalink
Merge branch 'dev' into vatsimOAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 authored Jun 9, 2024
2 parents 489819e + 287b3bf commit 52ec513
Show file tree
Hide file tree
Showing 37 changed files with 683 additions and 350 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('user_fields', function (Blueprint $table) {
$table->boolean('internal')->after('private')->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('user_fields', function (Blueprint $table) {
$table->dropColumn('internal');
});
}
};
14 changes: 14 additions & 0 deletions app/Events/NewsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Events;

use App\Contracts\Event;
use App\Models\News;

class NewsUpdated extends Event
{
public function __construct(
public News $news
) {
}
}
5 changes: 5 additions & 0 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function news(Request $request): View
$attrs['user_id'] = Auth::user()->id;

$this->newsSvc->addNews($attrs);
} elseif ($request->isMethod('patch')) {
$attrs = $request->post();
$attrs['user_id'] = Auth::user()->id;

$this->newsSvc->updateNews($attrs);
} elseif ($request->isMethod('delete')) {
$id = $request->input('news_id');
$this->newsSvc->deleteNews($id);
Expand Down
17 changes: 16 additions & 1 deletion app/Http/Controllers/Admin/UserFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
public function index(Request $request): View
{
$this->userFieldRepo->pushCriteria(new RequestCriteria($request));
$fields = $this->userFieldRepo->all();
$fields = $this->userFieldRepo->where('internal', false)->get();

return view('admin.userfields.index', ['fields' => $fields]);
}
Expand Down Expand Up @@ -99,6 +99,11 @@ public function edit(int $id): RedirectResponse|View
return redirect(route('admin.userfields.index'));
}

if ($field->internal) {
Flash::error('You cannot edit an internal user field');
return redirect(route('admin.userfields.index'));
}

return view('admin.userfields.edit', ['field' => $field]);
}

Expand All @@ -121,6 +126,11 @@ public function update(int $id, Request $request): RedirectResponse
return redirect(route('admin.userfields.index'));
}

if ($field->internal) {
Flash::error('You cannot edit an internal user field');
return redirect(route('admin.userfields.index'));
}

$this->userFieldRepo->update($request->all(), $id);

Flash::success('Field updated successfully.');
Expand All @@ -142,6 +152,11 @@ public function destroy(int $id): RedirectResponse
return redirect(route('admin.userfields.index'));
}

if ($field->internal) {
Flash::error('You cannot delete an internal user field');
return redirect(route('admin.userfields.index'));
}

if ($this->userFieldRepo->isInUse($id)) {
Flash::error('This field cannot be deleted, it is in use. Deactivate it instead');
return redirect(route('admin.userfields.index'));
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/Api/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;

use App\Console\Cron;
use App\Console\Kernel;
use App\Contracts\Controller;
use App\Exceptions\CronInvalid;
use Illuminate\Http\JsonResponse;
Expand All @@ -25,6 +26,15 @@ public function cron(Request $request, string $id): JsonResponse
throw new CronInvalid();
}

// Create a console kernel instance
$consoleKernel = app()->make(Kernel::class);

// Run a null artisan thing just so Laravel internals can be setup properly
$status = $consoleKernel->handle(
new \Symfony\Component\Console\Input\ArgvInput(),
new \Symfony\Component\Console\Output\NullOutput()
);

$cron = app(Cron::class);
$run = $cron->run();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function validateLogin(Request $request): void
$user = $this->userSvc->findUserByPilotId($value);
} catch (PilotIdNotFound $ex) {
Log::warning('Error logging in, pilot_id not found, id='.$value);
$fail('Pilot not found');
$fail(__('auth.failed'));
return;
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function showRegistrationForm(Request $request): View
}

$airlines = $this->airlineRepo->selectBoxList();
$userFields = UserField::where(['show_on_registration' => true, 'active' => true])->get();
$userFields = UserField::where(['show_on_registration' => true, 'active' => true, 'internal' => false])->get();

return view('auth.register', [
'airports' => [],
Expand Down Expand Up @@ -124,6 +124,7 @@ protected function validator(array $data): Validator
$userFields = UserField::where([
'show_on_registration' => true,
'required' => true,
'internal' => false,
'active' => true,
])->get();

Expand Down Expand Up @@ -215,7 +216,7 @@ protected function create(Request $request): User

Log::info('User registered: ', $user->toArray());

$userFields = UserField::where(['show_on_registration' => true, 'active' => true])->get();
$userFields = UserField::where(['show_on_registration' => true, 'active' => true, 'internal' => false])->get();
foreach ($userFields as $field) {
$field_name = 'field_'.$field->slug;
UserFieldValue::updateOrCreate([
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Frontend/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function index(): View
$downloadUrl = DB::table('vmsacars_config')->where(['id' => 'download_url'])->first();
if (!empty($downloadUrl) && !empty($downloadUrl->value)) {
$regrouped_files['ACARS'] = collect([
new File(['id' => 'vmsacars', 'name' => 'ACARS Client']),
new File(['id' => 'vmsacars', 'name' => 'ACARS Client', 'disk' => null, 'path' => $downloadUrl->value]),
]);
}
} catch (ModuleNotFoundException) {
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Frontend/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ public function edit(string $id): RedirectResponse|View
}

$airports = [
['' => ''],
[$pirep->arr_airport->id => $pirep->arr_airport->full_name],
[$pirep->dpt_airport->id => $pirep->dpt_airport->full_name],
'' => '',
$pirep->arr_airport->id => $pirep->arr_airport->full_name,
$pirep->dpt_airport->id => $pirep->dpt_airport->full_name,
];

if ($pirep->alt_airport) {
$airports[] = [$pirep->alt_airport->id => $pirep->alt_airport->full_name];
$airports[$pirep->alt_airport->id] = $pirep->alt_airport->full_name;
}

return view('pireps.edit', [
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Frontend/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ public function show(int $id): RedirectResponse|View
public function edit(Request $request): RedirectResponse|View
{
/** @var \App\Models\User $user */
$user = User::with('fields.field', 'location')->where('id', Auth::id())->first();
$user = User::with('fields.field', 'home_airport')->where('id', Auth::id())->first();

if (empty($user)) {
Flash::error('User not found!');

return redirect(route('frontend.dashboard.index'));
}

if ($user->location) {
$airports = [$user->location->id => $user->location->description];
if ($user->home_airport) {
$airports = [$user->home_airport->id => $user->home_airport->description];
} else {
$airports = ['' => ''];
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public function update(Request $request): RedirectResponse
'avatar' => 'nullable|mimes:jpeg,png,jpg',
];

$userFields = UserField::where(['show_on_registration' => true, 'required' => true])->get();
$userFields = UserField::where(['show_on_registration' => true, 'required' => true, 'internal' => false])->get();
foreach ($userFields as $field) {
$rules['field_'.$field->slug] = 'required';
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function update(Request $request): RedirectResponse
}

// Save all of the user fields
$userFields = UserField::all();
$userFields = UserField::where('internal', false)->get();
foreach ($userFields as $field) {
$field_name = 'field_'.$field->slug;
UserFieldValue::updateOrCreate([
Expand Down
2 changes: 2 additions & 0 deletions app/Models/UserField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class UserField extends Model
'show_on_registration', // Show on the registration form?
'required', // Required to be filled out in registration?
'private', // Whether this is shown on the user's public profile
'internal', // Whether this field is for internal use only (e.g. modules)
'active',
];

protected $casts = [
'show_on_registration' => 'boolean',
'required' => 'boolean',
'private' => 'boolean',
'internal' => 'boolean',
'active' => 'boolean',
];

Expand Down
20 changes: 20 additions & 0 deletions app/Notifications/NotificationEventsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Listener;
use App\Events\AwardAwarded;
use App\Events\NewsAdded;
use App\Events\NewsUpdated;
use App\Events\PirepAccepted;
use App\Events\PirepFiled;
use App\Events\PirepPrefiled;
Expand Down Expand Up @@ -33,6 +34,7 @@ class NotificationEventsHandler extends Listener
public static $callbacks = [
AwardAwarded::class => 'onAwardAwarded',
NewsAdded::class => 'onNewsAdded',
NewsUpdated::class => 'onNewsUpdated',
PirepPrefiled::class => 'onPirepPrefile',
PirepStatusChange::class => 'onPirepStatusChange',
PirepAccepted::class => 'onPirepAccepted',
Expand Down Expand Up @@ -268,6 +270,24 @@ public function onNewsAdded(NewsAdded $event): void
Notification::send([$event->news], new Messages\Broadcast\NewsAdded($event->news));
}

/**
* Notify all users of a news event, but only the users which have opted in
*
* @param \App\Events\NewsUpdated $event
*/
public function onNewsUpdated(NewsUpdated $event): void
{
Log::info('NotificationEvents::onNewsAdded');
if (setting('notifications.mail_news', true)) {
$this->notifyAllUsers(new Messages\NewsAdded($event->news));
}

/*
* Broadcast notifications
*/
Notification::send([$event->news], new Messages\Broadcast\NewsAdded($event->news));
}

/**
* Notify all users that user has awarded a new award
*
Expand Down
1 change: 1 addition & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ private function mapAdminRoutes()

Route::match([
'get',
'patch',
'post',
'delete',
], 'dashboard/news', ['uses' => 'DashboardController@news'])
Expand Down
17 changes: 11 additions & 6 deletions app/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ public function model()
/**
* Get all of the fields which has the mapped values
*
* @param User $user
* @param bool $only_public_fields Only include the user's public fields
* @param User $user
* @param bool $only_public_fields Only include the user's public fields
* @param mixed $with_internal_fields
*
* @return \App\Models\UserField[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
*/
public function getUserFields(User $user, $only_public_fields = null): Collection
public function getUserFields(User $user, $only_public_fields = null, $with_internal_fields = false): Collection
{
$fields = UserField::when(!$with_internal_fields, function ($query) {
return $query->where('internal', false);
});

if (is_bool($only_public_fields)) {
$fields = UserField::where(['private' => !$only_public_fields])->get();
} else {
$fields = UserField::get();
$fields = $fields->where(['private' => !$only_public_fields]);
}

$fields = $fields->get();

return $fields->map(function ($field, $_) use ($user) {
foreach ($user->fields as $userFieldValue) {
if ($userFieldValue->field->slug === $field->slug) {
Expand Down
1 change: 1 addition & 0 deletions app/Services/ImportExport/FareImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FareImporter extends ImportExport
public static $columns = [
'code' => 'required',
'name' => 'required',
'type' => 'required',
'price' => 'nullable|numeric',
'cost' => 'nullable|numeric',
'capacity' => 'required|integer',
Expand Down
Loading

0 comments on commit 52ec513

Please sign in to comment.