fix tests
This commit is contained in:
@@ -15,7 +15,7 @@ class ApiDocsAuth
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
$authHeader = (string) $request->header('Authorization');
|
||||
if ($authHeader !== '' && stripos($authHeader, 'Bearer ') === 0) {
|
||||
$token = trim(substr($authHeader, 7));
|
||||
@@ -34,11 +34,11 @@ class ApiDocsAuth
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->deny('Unauthorized access to documentation.', 401);
|
||||
}
|
||||
|
||||
if (!$this->userIsAdmin((int) $user->id)) {
|
||||
if (! $this->userIsAdmin((int) $user->id)) {
|
||||
return $this->deny('Admin privileges required.', 403);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class ApiJwtAuth
|
||||
{
|
||||
try {
|
||||
$user = JWTAuth::parseToken()->authenticate();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return response()->json(['status' => false, 'message' => 'Unauthorized.'], 401);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CleanupScheduler
|
||||
{
|
||||
public function __construct(private CleanupSchedulerService $service)
|
||||
{
|
||||
}
|
||||
public function __construct(private CleanupSchedulerService $service) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
|
||||
@@ -28,8 +28,7 @@ class EnsurePrintRequestsAdminAccess
|
||||
->toArray();
|
||||
|
||||
foreach (
|
||||
['administrator', 'admin', 'principal', 'vice_principal', 'vice-principal']
|
||||
as $allowed
|
||||
['administrator', 'admin', 'principal', 'vice_principal', 'vice-principal'] as $allowed
|
||||
) {
|
||||
if (in_array($allowed, $roles, true)) {
|
||||
return $next($request);
|
||||
|
||||
@@ -12,13 +12,11 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureSchoolYearEditable
|
||||
{
|
||||
public function __construct(private SchoolYearWriteGuard $guard)
|
||||
{
|
||||
}
|
||||
public function __construct(private SchoolYearWriteGuard $guard) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (!in_array(strtoupper($request->method()), ['POST', 'PUT', 'PATCH', 'DELETE'], true)) {
|
||||
if (! in_array(strtoupper($request->method()), ['POST', 'PUT', 'PATCH', 'DELETE'], true)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
@@ -84,7 +82,7 @@ class EnsureSchoolYearEditable
|
||||
|
||||
private function lookupYear(string $id, string $table, string $column): ?string
|
||||
{
|
||||
if (!ctype_digit($id) || !DB::getSchemaBuilder()->hasTable($table)) {
|
||||
if (! ctype_digit($id) || ! DB::getSchemaBuilder()->hasTable($table)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class MultiAuth
|
||||
$sanctumUser = Auth::guard('sanctum')->user();
|
||||
if ($sanctumUser) {
|
||||
Auth::setUser($sanctumUser);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
@@ -25,6 +26,7 @@ class MultiAuth
|
||||
$jwtUser = JWTAuth::setToken($token)->authenticate();
|
||||
if ($jwtUser) {
|
||||
Auth::setUser($jwtUser);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
} catch (JWTException $e) {
|
||||
|
||||
@@ -9,9 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PrimeTimezone
|
||||
{
|
||||
public function __construct(private TimeService $timeService)
|
||||
{
|
||||
}
|
||||
public function __construct(private TimeService $timeService) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
|
||||
@@ -9,9 +9,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RequirePermission
|
||||
{
|
||||
public function __construct(private PermissionCheckService $permissions)
|
||||
{
|
||||
}
|
||||
public function __construct(private PermissionCheckService $permissions) {}
|
||||
|
||||
public function handle(Request $request, Closure $next, string $permission): Response
|
||||
{
|
||||
@@ -20,10 +18,11 @@ class RequirePermission
|
||||
return response()->json(['status' => false, 'message' => 'Unauthorized.'], 401);
|
||||
}
|
||||
|
||||
if (!$this->permissions->hasPermission($userId, $permission)) {
|
||||
if (! $this->permissions->hasPermission($userId, $permission)) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['status' => false, 'message' => 'Access denied.'], 403);
|
||||
}
|
||||
|
||||
return response()->json(['status' => false, 'message' => 'Access denied.'], 403);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user