Files
ladill-frontdesk/app/Http/Controllers/Frontdesk/IntegrationController.php
T
isaaccladandCursor 9e2d79936c
Deploy Ladill Frontdesk / deploy (push) Failing after 35s
Test / test (push) Failing after 2m45s
Initial Ladill Frontdesk release with deploy pipeline.
Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 20:37:15 +00:00

85 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers\Frontdesk;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
use App\Models\WebhookEndpoint;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class IntegrationController extends Controller
{
use ScopesToAccount;
public function edit(Request $request): View
{
$this->authorizeAbility($request, 'settings.view');
$organization = $this->organization($request);
$canManage = app(\App\Services\Frontdesk\FrontdeskPermissions::class)
->isAdmin($this->member($request));
$webhook = WebhookEndpoint::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->first();
return view('frontdesk.integrations.edit', [
'organization' => $organization,
'canManage' => $canManage,
'webhook' => $webhook,
'webhookEvents' => config('frontdesk.webhook_events', []),
'integrations' => config('frontdesk.integrations', []),
'icalUrl' => $this->signedIcalUrl($organization->id, $this->ownerRef($request)),
]);
}
public function update(Request $request): RedirectResponse
{
$this->authorizeAbility($request, 'settings.manage');
$organization = $this->organization($request);
$validated = $request->validate([
'webhook_url' => ['nullable', 'url', 'max:500'],
'webhook_secret' => ['nullable', 'string', 'max:128'],
'webhook_events' => ['nullable', 'array'],
'webhook_events.*' => ['string'],
'webhook_active' => ['boolean'],
]);
if (empty($validated['webhook_url'])) {
WebhookEndpoint::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->delete();
return back()->with('success', 'Integration settings saved.');
}
WebhookEndpoint::updateOrCreate(
[
'owner_ref' => $this->ownerRef($request),
'organization_id' => $organization->id,
],
[
'url' => $validated['webhook_url'],
'secret' => $validated['webhook_secret'] ?? null,
'events' => array_values($validated['webhook_events'] ?? config('frontdesk.webhook_events')),
'is_active' => $request->boolean('webhook_active', true),
],
);
return back()->with('success', 'Integration settings saved.');
}
protected function signedIcalUrl(int $organizationId, string $ownerRef): string
{
$token = hash_hmac('sha256', "{$organizationId}:{$ownerRef}", (string) config('app.key'));
return route('frontdesk.integrations.ical', [
'organization' => $organizationId,
'owner' => $ownerRef,
'token' => $token,
]);
}
}