base commit
This commit is contained in:
117
app/Policies/BonusPolicy.php
Normal file
117
app/Policies/BonusPolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Bonus;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class BonusPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Bonus $bonus): 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, $bonus->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, Bonus $bonus): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $bonus->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, Bonus $bonus): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $bonus->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, Bonus $bonus): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $bonus->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Bonus $bonus): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
50
app/Policies/Concerns/ScopedByDepartment.php
Normal file
50
app/Policies/Concerns/ScopedByDepartment.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
trait ScopedByDepartment
|
||||
{
|
||||
protected function userManagesDepartment(User $user, ?int $departmentId): bool
|
||||
{
|
||||
if (! $user->hasRole('department_manager')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($departmentId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->department_id === $departmentId;
|
||||
}
|
||||
|
||||
protected function userIsViewer(User $user): bool
|
||||
{
|
||||
return $user->hasRole('viewer');
|
||||
}
|
||||
|
||||
protected function isSuperAdmin(User $user): bool
|
||||
{
|
||||
return $user->hasRole('super_admin');
|
||||
}
|
||||
|
||||
protected function hasFullAccess(User $user): bool
|
||||
{
|
||||
return $user->hasRole(['administrator', 'hr_manager']);
|
||||
}
|
||||
|
||||
protected function canForceDelete(User $user): bool
|
||||
{
|
||||
return $user->hasRole('administrator');
|
||||
}
|
||||
|
||||
protected function canRead(User $user): bool
|
||||
{
|
||||
return $this->hasFullAccess($user)
|
||||
|| $user->hasRole(['supervisor', 'department_manager'])
|
||||
|| $this->userIsViewer($user);
|
||||
}
|
||||
}
|
||||
89
app/Policies/DepartmentPolicy.php
Normal file
89
app/Policies/DepartmentPolicy.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class DepartmentPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Department $department): 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, $department->id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function update(User $user, Department $department): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function delete(User $user, Department $department): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function restore(User $user, Department $department): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Department $department): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/DisciplinaryReportPolicy.php
Normal file
117
app/Policies/DisciplinaryReportPolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\DisciplinaryReport;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class DisciplinaryReportPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, DisciplinaryReport $disciplinaryReport): 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, $disciplinaryReport->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->hasRole('department_manager');
|
||||
}
|
||||
|
||||
public function update(User $user, DisciplinaryReport $disciplinaryReport): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $disciplinaryReport->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, DisciplinaryReport $disciplinaryReport): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $disciplinaryReport->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, DisciplinaryReport $disciplinaryReport): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $disciplinaryReport->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, DisciplinaryReport $disciplinaryReport): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/EmployeeDocumentPolicy.php
Normal file
117
app/Policies/EmployeeDocumentPolicy.php
Normal 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);
|
||||
}
|
||||
}
|
||||
117
app/Policies/EmployeePolicy.php
Normal file
117
app/Policies/EmployeePolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Employee;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class EmployeePolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Employee $employee): 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, $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, Employee $employee): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $employee->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, Employee $employee): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $employee->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, Employee $employee): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $employee->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Employee $employee): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/ExplanationPolicy.php
Normal file
117
app/Policies/ExplanationPolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Explanation;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class ExplanationPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Explanation $explanation): 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, $explanation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->hasRole('department_manager');
|
||||
}
|
||||
|
||||
public function update(User $user, Explanation $explanation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $explanation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, Explanation $explanation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $explanation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, Explanation $explanation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $explanation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Explanation $explanation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/GiftPolicy.php
Normal file
117
app/Policies/GiftPolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Gift;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class GiftPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Gift $gift): 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, $gift->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, Gift $gift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $gift->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, Gift $gift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $gift->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, Gift $gift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $gift->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Gift $gift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
77
app/Policies/PositionPolicy.php
Normal file
77
app/Policies/PositionPolicy.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Position;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class PositionPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Position $position): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function update(User $user, Position $position): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function delete(User $user, Position $position): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function restore(User $user, Position $position): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Position $position): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
77
app/Policies/ShiftPolicy.php
Normal file
77
app/Policies/ShiftPolicy.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Shift;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class ShiftPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Shift $shift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function update(User $user, Shift $shift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function delete(User $user, Shift $shift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function restore(User $user, Shift $shift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasFullAccess($user);
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Shift $shift): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/SickLeavePolicy.php
Normal file
117
app/Policies/SickLeavePolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\SickLeave;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class SickLeavePolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, SickLeave $sickLeave): 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, $sickLeave->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, SickLeave $sickLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $sickLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, SickLeave $sickLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $sickLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, SickLeave $sickLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $sickLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, SickLeave $sickLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/UnpaidLeavePolicy.php
Normal file
117
app/Policies/UnpaidLeavePolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\UnpaidLeave;
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class UnpaidLeavePolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, UnpaidLeave $unpaidLeave): 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, $unpaidLeave->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, UnpaidLeave $unpaidLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $unpaidLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, UnpaidLeave $unpaidLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $unpaidLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, UnpaidLeave $unpaidLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $unpaidLeave->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, UnpaidLeave $unpaidLeave): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
60
app/Policies/UserPolicy.php
Normal file
60
app/Policies/UserPolicy.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $this->isSuperAdmin($user) || $user->hasAnyRole(['administrator', 'hr_manager']);
|
||||
}
|
||||
|
||||
public function view(User $user, User $model): bool
|
||||
{
|
||||
return $this->viewAny($user);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $this->isSuperAdmin($user) || $user->hasAnyRole(['administrator', 'hr_manager']);
|
||||
}
|
||||
|
||||
public function update(User $user, User $model): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($model->hasRole('super_admin')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->hasAnyRole(['administrator', 'hr_manager']);
|
||||
}
|
||||
|
||||
public function delete(User $user, User $model): bool
|
||||
{
|
||||
if ($model->hasRole('super_admin') || $user->id === $model->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isSuperAdmin($user) || $user->hasRole('administrator');
|
||||
}
|
||||
|
||||
public function restore(User $user, User $model): bool
|
||||
{
|
||||
return $this->delete($user, $model);
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, User $model): bool
|
||||
{
|
||||
return $this->isSuperAdmin($user);
|
||||
}
|
||||
}
|
||||
117
app/Policies/VacationPolicy.php
Normal file
117
app/Policies/VacationPolicy.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Vacation;
|
||||
use App\Policies\Concerns\ScopedByDepartment;
|
||||
|
||||
class VacationPolicy
|
||||
{
|
||||
use ScopedByDepartment;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canRead($user);
|
||||
}
|
||||
|
||||
public function view(User $user, Vacation $vacation): 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, $vacation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->hasRole('department_manager');
|
||||
}
|
||||
|
||||
public function update(User $user, Vacation $vacation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user) || $user->hasRole('supervisor')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $vacation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete(User $user, Vacation $vacation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $vacation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function restore(User $user, Vacation $vacation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasFullAccess($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user->hasRole('department_manager')) {
|
||||
return $this->userManagesDepartment($user, $vacation->employee?->department_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function forceDelete(User $user, Vacation $vacation): bool
|
||||
{
|
||||
if ($this->isSuperAdmin($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canForceDelete($user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user