fix parent, teacher and admin pages

This commit is contained in:
root
2026-04-25 00:00:23 -04:00
parent 4cd98f1d30
commit eafe4eb134
30 changed files with 1566 additions and 105 deletions
+18 -21
View File
@@ -3,7 +3,6 @@
namespace App\Policies;
use App\Models\ClassProgressReport;
use App\Models\Configuration;
use App\Models\TeacherClass;
use App\Models\User;
@@ -16,7 +15,11 @@ class ClassProgressReportPolicy
public function view(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
if ($this->isAdmin($user)) {
return true;
}
return $this->isAuthor($user, $report) || $this->teachesSection($user, $report);
}
public function create(User $user): bool
@@ -26,33 +29,27 @@ class ClassProgressReportPolicy
public function update(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
return $this->isAdmin($user) || $this->isAuthor($user, $report);
}
public function delete(User $user, ClassProgressReport $report): bool
{
return $this->owns($user, $report) || $this->isAdmin($user);
return $this->isAdmin($user) || $this->isAuthor($user, $report);
}
private function owns(User $user, ClassProgressReport $report): bool
private function isAuthor(User $user, ClassProgressReport $report): bool
{
if ((int) $report->teacher_id === (int) $user->id) {
return true;
}
return (int) $report->teacher_id === (int) $user->id;
}
$schoolYear = (string) (Configuration::getConfig('school_year') ?? '');
if ($schoolYear === '') {
return false;
}
$semester = (string) (Configuration::getConfig('semester') ?? '');
foreach (TeacherClass::assignedForSectionTerm((int) $report->class_section_id, $semester, $schoolYear) as $row) {
if ((int) ($row['teacher_id'] ?? 0) === (int) $user->id) {
return true;
}
}
return false;
/** Same relaxed section membership used by `ClassProgressQueryService::listReports`. */
private function teachesSection(User $user, ClassProgressReport $report): bool
{
return in_array(
(int) $report->class_section_id,
TeacherClass::distinctSectionIdsForTeacher((int) $user->id),
true
);
}
private function isAdmin(User $user): bool