Add prune & event blacklist (#682)
* Add prune & event blacklist * Pinted 3times with --dirty bruh * Add to Settings * Fix prune & description * Prune Logs not Configuration
This commit is contained in:
parent
bc2df22d78
commit
3f9c1dbc3c
@ -9,6 +9,7 @@ use App\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
|
||||
use App\Console\Commands\Schedule\ProcessRunnableCommand;
|
||||
use App\Jobs\NodeStatistics;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Webhook;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Database\Console\PruneCommand;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
@ -48,5 +49,9 @@ class Kernel extends ConsoleKernel
|
||||
if (config('activity.prune_days')) {
|
||||
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
|
||||
}
|
||||
|
||||
if (config('panel.webhook.prune_days')) {
|
||||
$schedule->command(PruneCommand::class, ['--model' => [Webhook::class]])->daily();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -540,7 +540,21 @@ class Settings extends Page implements HasForms
|
||||
->afterStateUpdated(fn ($state, Set $set) => $set('PANEL_EDITABLE_SERVER_DESCRIPTIONS', (bool) $state))
|
||||
->default(env('PANEL_EDITABLE_SERVER_DESCRIPTIONS', config('panel.editable_server_descriptions'))),
|
||||
]),
|
||||
|
||||
Section::make('Webhook')
|
||||
->description('Configure how often old webhook logs should be pruned.')
|
||||
->columns()
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->schema([
|
||||
TextInput::make('APP_WEBHOOK_PRUNE_DAYS')
|
||||
->label('Prune age')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->maxValue(365)
|
||||
->suffix('Days')
|
||||
->default(env('APP_WEBHOOK_PRUNE_DAYS', config('panel.webhook.prune_days'))),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\MassPrunable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Webhook extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, MassPrunable;
|
||||
|
||||
protected $fillable = ['payload', 'successful_at', 'event', 'endpoint'];
|
||||
|
||||
@ -18,4 +21,9 @@ class Webhook extends Model
|
||||
'successful_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function prunable(): Builder
|
||||
{
|
||||
return static::where('created_at', '<=', Carbon::now()->subDays(config('panel.webhook.prune_days')));
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,13 @@ class WebhookConfiguration extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
/**
|
||||
* Blacklisted events.
|
||||
*/
|
||||
protected static array $eventBlacklist = [
|
||||
'eloquent.created: App\Models\Webhook',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'endpoint',
|
||||
'description',
|
||||
@ -48,7 +55,11 @@ class WebhookConfiguration extends Model
|
||||
|
||||
public static function allPossibleEvents(): array
|
||||
{
|
||||
return static::discoverCustomEvents() + static::allModelEvents();
|
||||
return collect(static::discoverCustomEvents())
|
||||
->merge(static::allModelEvents())
|
||||
->unique()
|
||||
->filter(fn ($event) => !in_array($event, static::$eventBlacklist))
|
||||
->all();
|
||||
}
|
||||
|
||||
public static function filamentCheckboxList(): array
|
||||
|
@ -168,8 +168,28 @@ return [
|
||||
|
||||
'editable_server_descriptions' => env('PANEL_EDITABLE_SERVER_DESCRIPTIONS', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This section controls Api Key configurations
|
||||
*/
|
||||
|
||||
'api' => [
|
||||
'key_limit' => env('API_KEYS_LIMIT', 25),
|
||||
'key_expire_time' => env('API_KEYS_EXPIRE_TIME', 720),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Webhook Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This section controls Webhook configurations
|
||||
*/
|
||||
|
||||
'webhook' => [
|
||||
'prune_days' => env('APP_WEBHOOK_PRUNE_DAYS', 30),
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user