8025fa6d05
Permissions now actually govern access instead of the hard-coded Admin role:
- Super-admin bypass (see all projects / full access) -> can('manage all')
in Project::scopeAccessibleBy, ProjectMap, ProjectDashboard, PhaseGantt,
LayerManager, ProjectReportController.
- Redundant '|| hasRole(Admin)' fallbacks dropped (Gate::before already lets
manage-all through can()): LayerManager (upload/delete layers), MediaManager
(upload), ProjectMap (update progress), ProjectUsers/ProjectCompanies
(assign users).
- Admin-only screens now gated by the matching permission: AdminUsers/UserView
-> can('view users'), UserForm -> can('create users')|can('edit users'),
CompanyView -> can('view companies').
- MediaManager delete: can('delete media') OR owner.
- Kept UserForm's domain guard (can't remove your own Admin role).
Note: the /admin route group still has middleware can:manage all, so admin
screens stay super-admin-only until that group is relaxed per-route.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.4 KiB
PHP
37 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Project;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ProjectReportController extends Controller
|
|
{
|
|
public function show(Project $project)
|
|
{
|
|
$user = Auth::user();
|
|
if (!$user->can('manage all') && !$project->users()->where('user_id', $user->id)->exists()) {
|
|
abort(403);
|
|
}
|
|
|
|
$phases = $project->phases()
|
|
->with(['layers.features.inspections', 'layers.features.issues'])
|
|
->orderBy('order')
|
|
->get();
|
|
|
|
$stats = [
|
|
'total_features' => $phases->flatMap(fn($p) => $p->layers)->flatMap(fn($l) => $l->features)->count(),
|
|
'completed_features' => $phases->flatMap(fn($p) => $p->layers)->flatMap(fn($l) => $l->features)->where('status', 'completed')->count(),
|
|
'total_inspections' => \App\Models\Inspection::where('project_id', $project->id)->count(),
|
|
'open_issues' => \App\Models\Issue::where('project_id', $project->id)->where('status', 'open')->count(),
|
|
'avg_progress' => round($phases->avg('progress_percent') ?? 0),
|
|
];
|
|
|
|
$pdf_data = compact('project', 'phases', 'stats');
|
|
|
|
// Use Blade to render HTML, then return as "print" view
|
|
// (barryvdh/laravel-dompdf is not installed, so we render a printable HTML page)
|
|
return view('reports.project-report', $pdf_data);
|
|
}
|
|
}
|