Merge pull request 'codex/v0.5-webhook-notification/02-project-notification-settings-ui' (#48) from codex/v0.5-webhook-notification/02-project-notification-settings-ui into main
tests / ci (8.4) (push) Has been cancelled
linter / quality (push) Has been cancelled

Reviewed-on: OpenSource/KanbanGit#48
This commit was merged in pull request #48.
This commit is contained in:
2026-04-24 16:38:43 +00:00
39 changed files with 2421 additions and 0 deletions
@@ -0,0 +1,94 @@
<?php
namespace App\Http\Controllers;
use App\Actions\Notifications\BuildProjectNotificationSettingsPayload;
use App\Actions\Notifications\DeleteProjectNotificationAction;
use App\Actions\Notifications\StoreProjectNotificationAction;
use App\Actions\Notifications\UpdateProjectNotificationAction;
use App\Actions\Permissions\PermissionService;
use App\Enums\Permission;
use App\Http\Requests\StoreProjectNotificationActionRequest;
use App\Http\Requests\UpdateProjectNotificationActionRequest;
use App\Models\NotificationAction;
use App\Models\Project;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class ProjectNotificationSettingsController extends Controller
{
public function __construct(
private readonly BuildProjectNotificationSettingsPayload $buildProjectNotificationSettingsPayload,
private readonly DeleteProjectNotificationAction $deleteProjectNotificationAction,
private readonly PermissionService $permissionService,
private readonly StoreProjectNotificationAction $storeProjectNotificationAction,
private readonly UpdateProjectNotificationAction $updateProjectNotificationAction,
) {}
public function show(Request $request, Project $project): Response
{
$this->abortUnlessCanManage($request, $project);
return Inertia::render(
'projects/settings/Notifications',
$this->buildProjectNotificationSettingsPayload->handle($project, session('status')),
);
}
public function store(
StoreProjectNotificationActionRequest $request,
Project $project,
): RedirectResponse {
$this->abortUnlessCanManage($request, $project);
$notificationAction = $this->storeProjectNotificationAction->handle($project, $request->validated());
return to_route('projects.settings.notifications', $project)
->with('status', "{$notificationAction->name} notification was added.");
}
public function update(
UpdateProjectNotificationActionRequest $request,
Project $project,
NotificationAction $notificationAction,
): RedirectResponse {
$this->abortUnlessCanManage($request, $project);
$notificationAction = $this->updateProjectNotificationAction->handle(
$project,
$notificationAction,
$request->validated(),
);
return to_route('projects.settings.notifications', $project)
->with('status', "{$notificationAction->name} notification was updated.");
}
public function destroy(
Request $request,
Project $project,
NotificationAction $notificationAction,
): RedirectResponse {
$this->abortUnlessCanManage($request, $project);
$notificationAction = $project->notificationActions()
->whereKey($notificationAction->id)
->firstOrFail();
$deletedName = $notificationAction->name;
$this->deleteProjectNotificationAction->handle($project, $notificationAction);
return to_route('projects.settings.notifications', $project)
->with('status', "{$deletedName} notification was deleted.");
}
private function abortUnlessCanManage(Request $request, Project $project): void
{
abort_unless(
$this->permissionService->allows($request->user(), Permission::ProjectAdmin, $project),
403,
);
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Http\Requests;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreProjectNotificationActionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'event_type' => ['required', 'string', Rule::in($this->eventTypes())],
'channel' => ['required', 'string', Rule::in($this->channels())],
'enabled' => ['required', 'boolean'],
'delivery_url' => ['required', 'string', 'max:2048', 'url'],
'message_template' => $this->messageTemplateRules(),
];
}
/**
* @return array<int, string>
*/
private function channels(): array
{
return array_map(
static fn (NotificationChannel $channel): string => $channel->value,
NotificationChannel::cases(),
);
}
/**
* @return array<int, string>
*/
private function eventTypes(): array
{
return array_map(
static fn (NotificationEventType $eventType): string => $eventType->value,
NotificationEventType::cases(),
);
}
/**
* @return array<int, ValidationRule|string>
*/
private function messageTemplateRules(): array
{
if ($this->input('channel') === NotificationChannel::Discord->value) {
return ['required', 'string', 'max:2000'];
}
return ['nullable', 'string', 'max:2000'];
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Http\Requests;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateProjectNotificationActionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'event_type' => ['required', 'string', Rule::in($this->eventTypes())],
'channel' => ['required', 'string', Rule::in($this->channels())],
'enabled' => ['required', 'boolean'],
'delivery_url' => ['nullable', 'string', 'max:2048', 'url'],
'message_template' => $this->messageTemplateRules(),
];
}
/**
* @return array<int, string>
*/
private function channels(): array
{
return array_map(
static fn (NotificationChannel $channel): string => $channel->value,
NotificationChannel::cases(),
);
}
/**
* @return array<int, string>
*/
private function eventTypes(): array
{
return array_map(
static fn (NotificationEventType $eventType): string => $eventType->value,
NotificationEventType::cases(),
);
}
/**
* @return array<int, ValidationRule|string>
*/
private function messageTemplateRules(): array
{
if ($this->input('channel') === NotificationChannel::Discord->value) {
return ['required', 'string', 'max:2000'];
}
return ['nullable', 'string', 'max:2000'];
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use App\Models\NotificationAction;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class NotificationActionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'project_id' => $this->project_id,
'name' => $this->name,
'enabled' => $this->enabled,
'event_type' => $this->event_type->value,
'event_type_label' => $this->event_type->label(),
'channel' => $this->channel->value,
'channel_label' => $this->channel->label(),
'channel_configuration' => $this->channel_configuration ?? [],
'has_delivery_url' => $this->resource instanceof NotificationAction && filled($this->delivery_url),
'message_template' => $this->message_template,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
@@ -0,0 +1,37 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class NotificationDeliveryLogResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'notification_action_id' => $this->notification_action_id,
'event_type' => $this->event_type->value,
'event_type_label' => $this->event_type->label(),
'channel' => $this->channel->value,
'channel_label' => $this->channel->label(),
'delivery_status' => $this->delivery_status->value,
'delivery_status_label' => $this->delivery_status->label(),
'attempt_count' => $this->attempt_count,
'http_status' => $this->http_status,
'response_excerpt' => $this->response_excerpt,
'error_excerpt' => $this->error_excerpt,
'payload_metadata' => $this->payload_metadata,
'last_attempted_at' => $this->last_attempted_at?->toISOString(),
'delivered_at' => $this->delivered_at?->toISOString(),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}