## Summary - move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling - update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location - add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation` - integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404` ## Remaining Rollout Checks - validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout - confirm web, queue, and scheduler processes all start from the expected working directory in staging/production - verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #213
97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Alerts;
|
|
|
|
use App\Models\AlertDelivery;
|
|
use App\Models\AlertDestination;
|
|
use App\Notifications\Alerts\EmailAlertNotification;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use RuntimeException;
|
|
use Throwable;
|
|
|
|
class AlertSender
|
|
{
|
|
public function __construct(
|
|
private readonly TeamsWebhookSender $teamsWebhookSender,
|
|
) {}
|
|
|
|
public function send(AlertDelivery $delivery): void
|
|
{
|
|
$destination = $delivery->destination;
|
|
|
|
if (! $destination instanceof AlertDestination) {
|
|
throw new RuntimeException('Alert destination is missing.');
|
|
}
|
|
|
|
if (! (bool) $destination->is_enabled) {
|
|
throw new RuntimeException('Alert destination is disabled.');
|
|
}
|
|
|
|
$payload = is_array($delivery->payload) ? $delivery->payload : [];
|
|
|
|
try {
|
|
if ($destination->type === AlertDestination::TYPE_TEAMS_WEBHOOK) {
|
|
$this->deliverTeams($destination, $payload);
|
|
|
|
return;
|
|
}
|
|
|
|
if ($destination->type === AlertDestination::TYPE_EMAIL) {
|
|
$this->deliverEmail($delivery, $destination, $payload);
|
|
|
|
return;
|
|
}
|
|
} catch (Throwable $exception) {
|
|
throw new RuntimeException($this->channelFailureMessage((string) $destination->type), previous: $exception);
|
|
}
|
|
|
|
throw new RuntimeException('Alert destination type is not supported.');
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
private function deliverTeams(AlertDestination $destination, array $payload): void
|
|
{
|
|
$config = is_array($destination->config) ? $destination->config : [];
|
|
$webhookUrl = trim((string) Arr::get($config, 'webhook_url', ''));
|
|
|
|
if ($webhookUrl === '') {
|
|
throw new RuntimeException('Teams webhook destination is not configured.');
|
|
}
|
|
|
|
$this->teamsWebhookSender->send($webhookUrl, $payload);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
private function deliverEmail(AlertDelivery $delivery, AlertDestination $destination, array $payload): void
|
|
{
|
|
$config = is_array($destination->config) ? $destination->config : [];
|
|
$recipients = Arr::get($config, 'recipients', []);
|
|
$recipients = is_array($recipients)
|
|
? array_values(array_unique(array_filter(array_map(static fn (mixed $value): string => trim((string) $value), $recipients))))
|
|
: [];
|
|
|
|
if ($recipients === []) {
|
|
throw new RuntimeException('Email destination has no recipients.');
|
|
}
|
|
|
|
Notification::route('mail', $recipients)
|
|
->notify(new EmailAlertNotification($delivery, $payload));
|
|
}
|
|
|
|
private function channelFailureMessage(string $type): string
|
|
{
|
|
return match ($type) {
|
|
AlertDestination::TYPE_TEAMS_WEBHOOK => 'Teams delivery failed.',
|
|
AlertDestination::TYPE_EMAIL => 'Email delivery failed.',
|
|
default => 'Alert delivery failed.',
|
|
};
|
|
}
|
|
}
|