Files
L-Ami-Fiduciaire/app/Http/Controllers/NudgeController.php
Saad Zoubir 8f39bd9b73 fix: resolve permission toggle persistence, nudge terminology, and bulk action bugs (Bugs #2-5)
- Fix togglePermission() to always include all permission keys with false defaults
- Add migration to backfill null/empty Manager permissions with config defaults
- Rename nudge UI text from "Relance" to "Notification"/"Notifier" across 8 files
- Fix select-all checkbox and show checkboxes on all declaration rows
- Remove en_attente_client status restriction from BulkNotificationController

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

62 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Concerns\HasWorkspaceScope;
use App\Models\Declaration;
use App\Notifications\NudgeNotification;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class NudgeController extends Controller
{
use HasWorkspaceScope;
public function store(Request $request, Declaration $declaration): RedirectResponse
{
$this->authorizeWorkspaceAccess($declaration);
$workspace = $this->currentWorkspace();
$userRole = $workspace->users()
->where('users.id', $request->user()->id)
->first()
?->pivot
?->role
?->value;
if (! in_array($userRole, ['owner', 'manager'])) {
abort(404);
}
$assignee = $declaration->assignee;
if (! $assignee) {
return back()->with('flash', ['type' => 'warning', 'message' => 'Cette déclaration n\'a pas de collaborateur assigné.']);
}
$recentNudge = $assignee
->notifications()
->where('type', NudgeNotification::class)
->where('data->declaration_id', $declaration->id)
->where('created_at', '>=', now()->subHour())
->exists();
if ($recentNudge) {
return back()->with('flash', ['type' => 'warning', 'message' => 'Notification déjà envoyée récemment']);
}
$assignee->notify(new NudgeNotification($declaration, $request->user()));
activity()
->performedOn($declaration)
->causedBy($request->user())
->log('nudged');
Cache::forget("user:{$assignee->id}:workspace:{$workspace->id}:unread_notifications");
return back()->with('flash', ['type' => 'success', 'message' => 'Notification envoyée à '.$assignee->name]);
}
}