fix apply the plan docs/alrahma_api_fix_plan_school_year_only_v7
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m10s
API CI/CD / Test (PHPUnit) (push) Failing after 6m49s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 1m0s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -2,17 +2,20 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Configuration;
|
||||
use App\Services\SchoolYears\SelectedSchoolYearContextService;
|
||||
use App\Services\SchoolYears\SchoolYearWriteGuard;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureSchoolYearEditable
|
||||
{
|
||||
public function __construct(private SchoolYearWriteGuard $guard) {}
|
||||
public function __construct(
|
||||
private SchoolYearWriteGuard $guard,
|
||||
private SelectedSchoolYearContextService $selectedSchoolYear
|
||||
) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
@@ -22,11 +25,16 @@ class EnsureSchoolYearEditable
|
||||
|
||||
try {
|
||||
$this->guard->assertEditable($this->resolveSchoolYears($request));
|
||||
} catch (RuntimeException $e) {
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
], 409);
|
||||
], $e->getStatusCode());
|
||||
} catch (\RuntimeException $e) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
], Response::HTTP_CONFLICT);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
@@ -36,11 +44,11 @@ class EnsureSchoolYearEditable
|
||||
{
|
||||
$years = [];
|
||||
|
||||
foreach (['school_year', 'current_school_year'] as $field) {
|
||||
$value = $request->input($field, $request->query($field));
|
||||
if (is_string($value) && trim($value) !== '') {
|
||||
$years[] = trim($value);
|
||||
}
|
||||
$years[] = $this->selectedSchoolYear->fromRequest($request)->name;
|
||||
|
||||
$currentSchoolYear = $request->input('current_school_year', $request->query('current_school_year'));
|
||||
if (is_string($currentSchoolYear) && trim($currentSchoolYear) !== '') {
|
||||
$years[] = trim($currentSchoolYear);
|
||||
}
|
||||
|
||||
$routeYears = [
|
||||
@@ -69,14 +77,6 @@ class EnsureSchoolYearEditable
|
||||
$years[] = $resolved;
|
||||
}
|
||||
}
|
||||
|
||||
if ($years === []) {
|
||||
$current = trim((string) (Configuration::getConfig('school_year') ?? ''));
|
||||
if ($current !== '') {
|
||||
$years[] = $current;
|
||||
}
|
||||
}
|
||||
|
||||
return $years;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user