2026-03-11 23:33:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
use App\Http\Requests\StoreDeclarationMentionRequest;
|
|
|
|
|
use App\Models\Declaration;
|
2026-03-11 23:33:10 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
2026-03-12 18:25:32 +00:00
|
|
|
use App\Notifications\DeclarationMentionNotification;
|
2026-03-11 23:33:10 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
class DeclarationMentionController extends Controller
|
2026-03-11 23:33:10 +00:00
|
|
|
{
|
|
|
|
|
protected function currentWorkspace(Request $request): Workspace
|
|
|
|
|
{
|
|
|
|
|
$workspaceId = $request->session()->get('current_workspace_id');
|
|
|
|
|
|
|
|
|
|
return Workspace::query()->findOrFail($workspaceId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
protected function authorizeDeclaration(Workspace $workspace, Declaration $declaration): void
|
2026-03-11 23:33:10 +00:00
|
|
|
{
|
2026-03-12 18:25:32 +00:00
|
|
|
if ($declaration->workspace_id !== $workspace->id) {
|
2026-03-11 23:33:10 +00:00
|
|
|
abort(404);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
public function store(StoreDeclarationMentionRequest $request, Declaration $declaration): RedirectResponse
|
2026-03-11 23:33:10 +00:00
|
|
|
{
|
|
|
|
|
$workspace = $this->currentWorkspace($request);
|
2026-03-12 18:25:32 +00:00
|
|
|
$this->authorizeDeclaration($workspace, $declaration);
|
2026-03-11 23:33:10 +00:00
|
|
|
|
|
|
|
|
$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']);
|
|
|
|
|
|
2026-03-12 18:25:32 +00:00
|
|
|
$targetUser->notify(new DeclarationMentionNotification(
|
|
|
|
|
$declaration,
|
2026-03-11 23:33:10 +00:00
|
|
|
$request->user(),
|
|
|
|
|
$validated['message'],
|
|
|
|
|
));
|
|
|
|
|
|
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
|
|
|
Cache::forget("user:{$targetUser->id}:workspace:{$workspace->id}:unread_notifications");
|
2026-03-11 23:33:10 +00:00
|
|
|
|
|
|
|
|
return back()->with('flash', ['type' => 'success', 'message' => 'Notification envoyée.']);
|
|
|
|
|
}
|
|
|
|
|
}
|