trypost/app/Actions/Webhook/UpdateWebhook.php
Paulo Castellano a932c51bbb
Expose workspace webhooks through the API and MCP (#330)
* Expose workspace webhooks through the API and MCP.

The same create/update/test/rotate/replay/delete flow now lives in Actions so the web UI, REST API, and MCP tools stay in lockstep.

* Keep webhook validation local to each web, API, and MCP entry point.

* Extract MCP webhook rules into request classes and close remaining API/MCP review gaps.

* Tighten webhook updates to a field whitelist and reset failures only on re-enable.

* Treat a mismatched webhook replay as not found and mark secret rotation destructive.
2026-09-04 12:00:32 -03:00

35 lines
946 B
PHP

<?php
declare(strict_types=1);
namespace App\Actions\Webhook;
use App\Enums\Webhook\Status;
use App\Models\Webhook;
use App\Services\WebhookService;
use Illuminate\Support\Arr;
class UpdateWebhook
{
/**
* @param array<string, mixed> $data
*/
public static function execute(Webhook $webhook, array $data, WebhookService $webhooks): Webhook
{
$attributes = Arr::only($data, ['endpoint', 'events', 'status']);
$endpoint = data_get($attributes, 'endpoint');
if (is_string($endpoint) && $endpoint !== $webhook->endpoint) {
$webhooks->assertEndpointAllowed($endpoint);
}
if (data_get($attributes, 'status') === Status::Enabled->value && $webhook->status !== Status::Enabled) {
$attributes['consecutive_failures'] = 0;
$attributes['paused_at'] = null;
}
$webhook->update($attributes);
return $webhook->refresh();
}
}