Skip to content

Commit

Permalink
Merge branch 'dev' into removeLaravelHtmlFromFrontend
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored May 8, 2024
2 parents eabe6c9 + 2040c99 commit 238b762
Show file tree
Hide file tree
Showing 61 changed files with 905 additions and 110 deletions.
2 changes: 2 additions & 0 deletions app/Console/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Console;

use App\Console\Cron\ActivityLogClean;
use App\Console\Cron\Backups\BackupClean;
use App\Console\Cron\Backups\BackupMonitor;
use App\Console\Cron\Backups\BackupRun;
Expand Down Expand Up @@ -39,6 +40,7 @@ class Cron
BackupRun::class,
BackupClean::class,
BackupMonitor::class,
ActivityLogClean::class,
];

/**
Expand Down
28 changes: 28 additions & 0 deletions app/Console/Cron/ActivityLogClean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Console\Cron;

use App\Contracts\CronCommand;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class ActivityLogClean extends CronCommand
{
protected $signature = 'cron:activitylog-clean';
protected $description = 'Clean up old activity logs';

public function handle(): void
{
$this->callEvent();
}

public function callEvent(): void
{
Artisan::call('activitylog:clean --force');

$output = trim(Artisan::output());
if (!empty($output)) {
Log::info($output);
}
}
}
5 changes: 5 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console;

use App\Console\Cron\ActivityLogClean;
use App\Console\Cron\Backups\BackupClean;
use App\Console\Cron\Backups\BackupMonitor;
use App\Console\Cron\Backups\BackupRun;
Expand Down Expand Up @@ -60,6 +61,10 @@ protected function schedule(Schedule $schedule): void
$schedule->command(BackupMonitor::class)->dailyAt('01:45');
}

if (config('activitylog.enabled', false) === true) {
$schedule->command(ActivityLogClean::class)->dailyAt('01:00');
}

// Update the last time the cron was run
/** @var CronService $cronSvc */
$cronSvc = app(CronService::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

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

return new class() extends Migration {
public function up(): void
{
Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('log_name')->nullable();
$table->text('description');
$table->nullableUuidMorphs('subject', 'subject');
$table->nullableMorphs('causer', 'causer');
$table->json('properties')->nullable();
$table->timestamps();
$table->index('log_name');
});
}

public function down(): void
{
Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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

return new class() extends Migration {
public function up(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->string('event')->nullable()->after('subject_type');
});
}

public function down(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('event');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

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

return new class() extends Migration {
public function up(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->uuid('batch_uuid')->nullable()->after('properties');
});
}

public function down(): void
{
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
$table->dropColumn('batch_uuid');
});
}
};
35 changes: 35 additions & 0 deletions app/Http/Controllers/Admin/ActivityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Contracts\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Spatie\Activitylog\Models\Activity;

class ActivityController extends Controller
{
public function index(Request $request): View
{
$activities = Activity::with('causer')->orderBy('created_at', 'desc')->paginate();

return view('admin.activities.index', [
'activities' => $activities,
]);
}

public function show(Request $request, int $id): RedirectResponse|View
{
$activity = Activity::with('causer', 'subject')->find($id);

if (!$activity) {
flash()->error('Activity not found');
return redirect()->route('admin.activities.index');
}

return view('admin.activities.show', [
'activity' => $activity,
]);
}
}
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
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
21 changes: 21 additions & 0 deletions app/Http/Middleware/EnableActivityLogging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnableActivityLogging
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
activity()->enableLogging();
return $next($request);
}
}
11 changes: 11 additions & 0 deletions app/Models/Aircraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kyslik\ColumnSortable\Sortable;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Znck\Eloquent\Relations\BelongsToThrough as ZnckBelongsToThrough;
use Znck\Eloquent\Traits\BelongsToThrough;

Expand Down Expand Up @@ -54,6 +56,7 @@ class Aircraft extends Model
use HasFactory;
use SoftDeletes;
use Sortable;
use LogsActivity;

public $table = 'aircraft';

Expand Down Expand Up @@ -182,6 +185,14 @@ public function landingTime(): Attribute
);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly($this->fillable)
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

/**
* Relationships
*/
Expand Down
11 changes: 11 additions & 0 deletions app/Models/Airline.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Kyslik\ColumnSortable\Sortable;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

/**
* @property mixed id
Expand All @@ -32,6 +34,7 @@ class Airline extends Model
use JournalTrait;
use SoftDeletes;
use Sortable;
use LogsActivity;

public $table = 'airlines';

Expand Down Expand Up @@ -149,4 +152,12 @@ public function users(): HasMany
{
return $this->hasMany(User::class, 'airline_id', 'id');
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly($this->fillable)
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
}
11 changes: 11 additions & 0 deletions app/Models/Airport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kyslik\ColumnSortable\Sortable;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

/**
* Class Airport
Expand Down Expand Up @@ -41,6 +43,7 @@ class Airport extends Model
use HasFactory;
use SoftDeletes;
use Sortable;
use LogsActivity;

public $table = 'airports';

Expand Down Expand Up @@ -180,6 +183,14 @@ public function tz(): Attribute
);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly($this->fillable)
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

/**
* Relationships
*/
Expand Down
11 changes: 11 additions & 0 deletions app/Models/Fare.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

/**
* @property string name
Expand All @@ -22,6 +24,7 @@ class Fare extends Model
{
use HasFactory;
use SoftDeletes;
use LogsActivity;

public $table = 'fares';

Expand Down Expand Up @@ -53,6 +56,14 @@ class Fare extends Model
'type' => 'required',
];

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly($this->fillable)
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

/**
* Relationships
*/
Expand Down
7 changes: 7 additions & 0 deletions app/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@ public function url(): Attribute
}
);
}

public function isExternalFile(): Attribute
{
return Attribute::make(
get: fn ($value, array $attrs): bool => is_null($attrs['disk']) && !str_contains($this->url, config('app.url')),
);
}
}
12 changes: 12 additions & 0 deletions app/Models/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Kyslik\ColumnSortable\Sortable;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

/**
* @property string id
Expand Down Expand Up @@ -64,6 +66,7 @@ class Flight extends Model
use HasFactory;
use SoftDeletes;
use Sortable;
use LogsActivity;

public $table = 'flights';

Expand Down Expand Up @@ -275,6 +278,15 @@ public function days(): Attribute
);
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly($this->fillable)
->logExcept(['visible'])
->logOnlyDirty()
->dontSubmitEmptyLogs();
}

/*
* Relationships
*/
Expand Down
Loading

0 comments on commit 238b762

Please sign in to comment.