base commit

This commit is contained in:
Mekan1206
2026-07-30 17:24:40 +05:00
commit a794dacd39
345 changed files with 29597 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
namespace App\Policies;
use App\Models\EmployeeDocument;
use App\Models\User;
use App\Policies\Concerns\ScopedByDepartment;
class EmployeeDocumentPolicy
{
use ScopedByDepartment;
public function viewAny(User $user): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
return $this->canRead($user);
}
public function view(User $user, EmployeeDocument $employeeDocument): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
return true;
}
if ($this->userIsViewer($user)) {
return true;
}
if ($user->hasRole('department_manager')) {
return $this->userManagesDepartment($user, $employeeDocument->employee?->department_id);
}
return false;
}
public function create(User $user): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
if ($this->hasFullAccess($user)) {
return true;
}
return $user->hasRole('department_manager');
}
public function update(User $user, EmployeeDocument $employeeDocument): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
if ($this->hasFullAccess($user)) {
return true;
}
if ($user->hasRole('department_manager')) {
return $this->userManagesDepartment($user, $employeeDocument->employee?->department_id);
}
return false;
}
public function delete(User $user, EmployeeDocument $employeeDocument): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
if ($this->hasFullAccess($user)) {
return true;
}
if ($user->hasRole('department_manager')) {
return $this->userManagesDepartment($user, $employeeDocument->employee?->department_id);
}
return false;
}
public function restore(User $user, EmployeeDocument $employeeDocument): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
if ($this->hasFullAccess($user)) {
return true;
}
if ($user->hasRole('department_manager')) {
return $this->userManagesDepartment($user, $employeeDocument->employee?->department_id);
}
return false;
}
public function forceDelete(User $user, EmployeeDocument $employeeDocument): bool
{
if ($this->isSuperAdmin($user)) {
return true;
}
return $this->canForceDelete($user);
}
}