fix parent pages and teachers and admin
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -97,13 +97,22 @@ class ClassProgressController extends BaseApiController
|
||||
return $auth;
|
||||
}
|
||||
|
||||
if ($this->isLegacyTeacherProgressListRoute($request) && ! $this->hasAnyRole($auth, ['teacher', 'administrator', 'admin'])) {
|
||||
if ($this->isLegacyTeacherProgressListRoute($request) && ! $this->hasAnyRole($auth, ['teacher', 'teacher_assistant', 'ta', 'administrator', 'admin'])) {
|
||||
return $this->respondError('Forbidden.', Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$filters = $request->validated();
|
||||
$meta = $this->queryService->meta($filters['school_year'] ?? null, $filters['semester'] ?? null);
|
||||
$filters['school_year'] = $filters['school_year'] ?? ($meta['school_year'] ?? null);
|
||||
if ($this->isLegacyTeacherProgressListRoute($request) && empty($filters['class_section_id'])) {
|
||||
$resolvedClassSectionId = $this->resolveTeacherHistoryClassSectionId($auth, $filters);
|
||||
if ($resolvedClassSectionId instanceof JsonResponse) {
|
||||
return $resolvedClassSectionId;
|
||||
}
|
||||
if ($resolvedClassSectionId > 0) {
|
||||
$filters['class_section_id'] = $resolvedClassSectionId;
|
||||
}
|
||||
}
|
||||
if ($this->isAdminProgressAliasRoute($request)) {
|
||||
$filters['group_by_week'] = true;
|
||||
}
|
||||
@@ -136,7 +145,12 @@ class ClassProgressController extends BaseApiController
|
||||
|
||||
try {
|
||||
$filesBySubject = $request->filesBySubject();
|
||||
$reports = $this->mutationService->createReports($auth, $request->validated(), $filesBySubject);
|
||||
$payload = $this->resolveTeacherStorePayload($auth, $request->validated());
|
||||
if ($payload instanceof JsonResponse) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
$reports = $this->mutationService->createReports($auth, $payload, $filesBySubject);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
if ($e->getMessage() === 'CONFIRM_OVERWRITE') {
|
||||
return response()->json([
|
||||
@@ -278,6 +292,100 @@ class ClassProgressController extends BaseApiController
|
||||
|| $request->is('api/v1/admin/progress');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
* @return array<string, mixed>|JsonResponse
|
||||
*/
|
||||
private function resolveTeacherStorePayload(User $user, array $payload): array|JsonResponse
|
||||
{
|
||||
if ($this->hasAnyRole($user, ['administrator', 'admin', 'principal', 'vice_principal', 'vice-principal'])) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
if (! $this->hasAnyRole($user, ['teacher', 'teacher_assistant', 'ta'])) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
$assignments = $this->queryService->teacherAssignments(
|
||||
$user,
|
||||
$payload['school_year'] ?? null,
|
||||
$payload['semester'] ?? null
|
||||
);
|
||||
|
||||
if ($assignments === []) {
|
||||
return $this->respondError('No class section assigned to this teacher.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$postedSectionId = (int) ($payload['class_section_id'] ?? 0);
|
||||
$assignment = null;
|
||||
if ($postedSectionId > 0) {
|
||||
$assignment = collect($assignments)->first(function (array $assignment) use ($postedSectionId) {
|
||||
return (int) ($assignment['class_section_id'] ?? 0) === $postedSectionId
|
||||
|| (int) ($assignment['class_section_pk'] ?? 0) === $postedSectionId;
|
||||
});
|
||||
}
|
||||
|
||||
if (! $assignment) {
|
||||
$sessionClassSectionId = (int) session('class_section_id', 0);
|
||||
if ($sessionClassSectionId > 0) {
|
||||
$assignment = collect($assignments)->first(function (array $assignment) use ($sessionClassSectionId) {
|
||||
return (int) ($assignment['class_section_id'] ?? 0) === $sessionClassSectionId
|
||||
|| (int) ($assignment['class_section_pk'] ?? 0) === $sessionClassSectionId;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$assignment ??= $assignments[0];
|
||||
$payload['class_section_id'] = (int) ($assignment['class_section_id'] ?? 0);
|
||||
|
||||
if (empty($payload['school_year']) && ! empty($assignment['school_year'])) {
|
||||
$payload['school_year'] = $assignment['school_year'];
|
||||
}
|
||||
if (empty($payload['semester']) && ! empty($assignment['semester'])) {
|
||||
$payload['semester'] = $assignment['semester'];
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $filters
|
||||
*/
|
||||
private function resolveTeacherHistoryClassSectionId(User $user, array $filters): int|JsonResponse
|
||||
{
|
||||
if ($this->hasAnyRole($user, ['administrator', 'admin', 'principal', 'vice_principal', 'vice-principal'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$assignments = $this->queryService->teacherAssignments(
|
||||
$user,
|
||||
$filters['school_year'] ?? null,
|
||||
$filters['semester'] ?? null
|
||||
);
|
||||
$assignedSectionIds = collect($assignments)
|
||||
->pluck('class_section_id')
|
||||
->map(fn ($id) => (int) $id)
|
||||
->filter(fn ($id) => $id > 0)
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if ($assignedSectionIds === []) {
|
||||
return $this->respondError('No class section assigned to this teacher.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (count($assignedSectionIds) === 1) {
|
||||
return (int) $assignedSectionIds[0];
|
||||
}
|
||||
|
||||
$sessionClassSectionId = (int) session('class_section_id', 0);
|
||||
if ($sessionClassSectionId > 0 && in_array($sessionClassSectionId, $assignedSectionIds, true)) {
|
||||
return $sessionClassSectionId;
|
||||
}
|
||||
|
||||
return (int) $assignedSectionIds[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user