Files
L-Ami-Fiduciaire/app/Http/Controllers/FolderMentionController.php
Saad Zoubir 32e11db2b5 feat: add notification center with bell dropdown, full page, and workspace scoping (Story 3.3)
Enhance NotificationDropdown with type-specific icons, French description builder,
click-to-navigate with mark-as-read, and "Voir toutes les notifications" link.
Add full notifications page at /notifications with pagination (25/page), individual
mark-as-read, and empty state. Includes code review fixes: workspace-scoped unread
count and dropdown items, race condition fix (mark-as-read before navigate),
efficient markAllAsRead via direct update, deleted declaration URL handling,
and per-workspace cache keys. 7 new feature tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:26:40 +01:00

60 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreFolderMentionRequest;
use App\Models\Folder;
use App\Models\User;
use App\Models\Workspace;
use App\Notifications\FolderMentionNotification;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class FolderMentionController extends Controller
{
protected function currentWorkspace(Request $request): Workspace
{
$workspaceId = $request->session()->get('current_workspace_id');
return Workspace::query()->findOrFail($workspaceId);
}
protected function authorizeFolder(Workspace $workspace, Folder $folder): void
{
if ($folder->workspace_id !== $workspace->id) {
abort(404);
}
}
public function store(StoreFolderMentionRequest $request, Folder $folder): RedirectResponse
{
$workspace = $this->currentWorkspace($request);
$this->authorizeFolder($workspace, $folder);
$userRole = $workspace->users()
->where('users.id', $request->user()->id)
->first()
?->pivot
?->role
?->value;
if (! in_array($userRole, ['owner', 'manager'])) {
abort(403);
}
$validated = $request->validated();
$targetUser = User::findOrFail($validated['user_id']);
$targetUser->notify(new FolderMentionNotification(
$folder,
$request->user(),
$validated['message'],
));
Cache::forget("user:{$targetUser->id}:workspace:{$workspace->id}:unread_notifications");
return back()->with('flash', ['type' => 'success', 'message' => 'Notification envoyée.']);
}
}