add class progress and fix endpoints

This commit is contained in:
root
2026-03-12 17:27:49 -04:00
parent 0f39dbee62
commit 33be0c9a0d
40 changed files with 2086 additions and 438 deletions
@@ -0,0 +1,55 @@
<?php
namespace App\Policies;
use App\Models\ClassProgressReport;
use App\Models\User;
class ClassProgressReportPolicy
{
public function viewAny(User $user): bool
{
return $user !== null;
}
public function view(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
}
public function create(User $user): bool
{
return $user !== null;
}
public function update(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
}
public function delete(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
}
private function owns(User $user, ClassProgressReport $report): bool
{
return (int) $report->teacher_id === (int) $user->id;
}
private function isAdmin(User $user): bool
{
$roles = $user->roles()
->pluck('roles.name')
->map(fn ($name) => strtolower((string) $name))
->toArray();
foreach (['administrator', 'admin', 'principal', 'vice_principal', 'vice-principal'] as $role) {
if (in_array($role, $roles, true)) {
return true;
}
}
return false;
}
}