Files
KanbanGit/app/Http/Controllers/ProjectNotificationSettingsController.php
T
Twyco ff796aa10a
linter / quality (pull_request) Successful in 1m28s
tests / ci (8.4) (pull_request) Successful in 1m47s
feat: overhaul project workspace navigation
2026-07-18 17:52:25 +02:00

90 lines
3.1 KiB
PHP

<?php
namespace App\Http\Controllers;
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\Enums\ProjectSettingsSection;
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;
class ProjectNotificationSettingsController extends Controller
{
public function __construct(
private readonly DeleteProjectNotificationAction $deleteProjectNotificationAction,
private readonly PermissionService $permissionService,
private readonly StoreProjectNotificationAction $storeProjectNotificationAction,
private readonly UpdateProjectNotificationAction $updateProjectNotificationAction,
) {}
public function store(
StoreProjectNotificationActionRequest $request,
Project $project,
): RedirectResponse {
$this->abortUnlessCanManage($request, $project);
$notificationAction = $this->storeProjectNotificationAction->handle($project, $request->validated());
return $this->settingsRedirect($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 $this->settingsRedirect($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 $this->settingsRedirect($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,
);
}
private function settingsRedirect(Project $project): RedirectResponse
{
return to_route('projects.settings.index', [
'project' => $project,
'section' => ProjectSettingsSection::Notifications->value,
]);
}
}