Send a webhook for every change a person makes to a record
Events are {resource}.created, .updated, .deleted and .restored for content,
the inbox, redirects, repositories and media, taken from the audit log so the
two agree on what happened. Subscriptions take wildcards. Users, tokens,
webhooks and settings are never sent, nor what the application does by
itself; the inbox's own words only with personal data enabled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
@@ -96,16 +96,13 @@ class WebhookResource extends Resource
|
||||
->maxLength(2048)
|
||||
->rule(new PublicHttpsUrl),
|
||||
|
||||
CheckboxList::make('events')
|
||||
Select::make('events')
|
||||
->label(__('panel.webhooks.fields.events'))
|
||||
->options(fn () => collect(['*', ...Webhook::EVENTS])
|
||||
->mapWithKeys(fn (string $event) => [$event => self::eventLabel($event)])
|
||||
->all())
|
||||
->descriptions(fn () => collect(['*', ...Webhook::EVENTS])
|
||||
->mapWithKeys(fn (string $event) => [$event => $event])
|
||||
->all())
|
||||
->helperText(__('panel.webhooks.events_hint'))
|
||||
->multiple()
|
||||
->searchable()
|
||||
->options(fn () => self::eventOptions())
|
||||
->required()
|
||||
->columns(2)
|
||||
->columnSpanFull(),
|
||||
|
||||
Toggle::make('include_personal_data')
|
||||
@@ -162,6 +159,43 @@ class WebhookResource extends Resource
|
||||
return __("panel.webhooks.events.{$key}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Grouped for the select: everything, the events with a meaning of their
|
||||
* own, any record by action, then each kind of record.
|
||||
*
|
||||
* @return array<string, array<string, string>>
|
||||
*/
|
||||
public static function eventOptions(): array
|
||||
{
|
||||
$groups = [
|
||||
__('panel.webhooks.groups.everything') => [
|
||||
'*' => __('panel.webhooks.events.*'),
|
||||
...collect(Webhook::ACTIONS)->mapWithKeys(fn (string $action) => [
|
||||
"*.{$action}" => __('panel.webhooks.any_record', ['action' => self::actionLabel($action)]),
|
||||
])->all(),
|
||||
],
|
||||
__('panel.webhooks.groups.notices') => collect(Webhook::EVENTS)
|
||||
->mapWithKeys(fn (string $event) => [$event => self::eventLabel($event)])
|
||||
->all(),
|
||||
];
|
||||
|
||||
foreach (Webhook::RESOURCES as $resource) {
|
||||
$groups[__("panel.webhooks.resources.{$resource}")] = [
|
||||
"{$resource}.*" => __('panel.webhooks.all_of', ['resource' => __("panel.webhooks.resources.{$resource}")]),
|
||||
...collect(Webhook::ACTIONS)->mapWithKeys(fn (string $action) => [
|
||||
"{$resource}.{$action}" => __("panel.webhooks.resources.{$resource}").' · '.self::actionLabel($action),
|
||||
])->all(),
|
||||
];
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
protected static function actionLabel(string $action): string
|
||||
{
|
||||
return __("panel.webhooks.actions_on.{$action}");
|
||||
}
|
||||
|
||||
public static function pingAction(): Action
|
||||
{
|
||||
return Action::make('ping')
|
||||
|
||||
Reference in New Issue
Block a user