feat: implement permission system via usePermission hook and integrate it into dashboard, project, and financial modules
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

This commit is contained in:
Ajjj
2026-08-05 05:26:23 +08:00
parent 089e421716
commit fa12179ca5
18 changed files with 99 additions and 51 deletions

View File

@@ -77,6 +77,8 @@ class ProjectController extends Controller
public function create()
{
abort_unless($this->canCreateProject(request()->user()), 403);
$employees = User::whereIn('user_type', ['admin', 'employee'])
->where(function ($q) {
$q->whereIn('user_type', ['admin'])
@@ -113,6 +115,8 @@ class ProjectController extends Controller
public function store(Request $request)
{
abort_unless($this->canCreateProject($request->user()), 403);
$validated = $request->validate([
'name' => 'required|string|max:255',
'client_name' => 'nullable|string|max:255',
@@ -548,6 +552,7 @@ class ProjectController extends Controller
]);
\DB::transaction(function () use ($project, $validated) {
$milestoneIdsByIndex = [];
if (!empty($validated['prepopulate_milestones']) && !$project->milestones()->exists()) {
$this->seedDefaultMilestones($project);
}
@@ -573,6 +578,7 @@ class ProjectController extends Controller
]);
}
$existingMilestoneIds[] = $milestone->id;
$milestoneIdsByIndex[$index] = $milestone->id;
}
$project->milestones()->whereNotIn('id', $existingMilestoneIds)->delete();
}
@@ -583,6 +589,9 @@ class ProjectController extends Controller
$milestoneId = null;
if (!empty($t['milestone_ulid'])) {
$milestoneId = \Modules\ProjectManagement\Models\ProjectMilestone::resolveUlidToId($t['milestone_ulid']);
if ($milestoneId === null && ctype_digit((string) $t['milestone_ulid'])) {
$milestoneId = $milestoneIdsByIndex[(int) $t['milestone_ulid']] ?? null;
}
}
$task = null;
@@ -1253,4 +1262,16 @@ class ProjectController extends Controller
$writer->save('php://output');
exit;
}
private function canCreateProject(?User $user): bool
{
return $user !== null && ! $user->hasAnyRole([
'Site Technical',
'Construction Supervisor',
'Site Operations',
'Site Engineer',
'Site Supervisor',
'Main Contractor Admin',
]);
}
}