add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
@@ -39,7 +39,7 @@ class AuthController extends BaseApiController
}
$user = User::query()->whereRaw('LOWER(email) = ?', [$email])->first();
if (! $user) {
if (!$user) {
$security->logIpAttempt((string) $ip);
return response()->json([
@@ -70,7 +70,7 @@ class AuthController extends BaseApiController
$security->logSuccessfulLogin($user->fresh(), $request);
$fresh = $user->fresh();
if (! $fresh) {
if (!$fresh) {
return response()->json([
'status' => false,
'message' => 'Invalid email or password.',
@@ -100,7 +100,7 @@ class AuthController extends BaseApiController
public function me(): JsonResponse
{
$user = Auth::user();
if (! $user) {
if (!$user) {
return $this->respondError('Unauthorized.', 401);
}
@@ -44,7 +44,7 @@ class IpBanController extends BaseApiController
public function show(int $id): JsonResponse
{
$ban = $this->queryService->find($id);
if (! $ban) {
if (!$ban) {
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
}
@@ -67,12 +67,11 @@ class IpBanController extends BaseApiController
try {
$ban = $this->commandService->banNow($id ? (int) $id : null, $ip ? (string) $ip : null, $hours);
} catch (\Throwable $e) {
Log::error('IP ban failed: '.$e->getMessage());
Log::error('IP ban failed: ' . $e->getMessage());
return $this->error('Unable to ban IP.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (! $ban) {
if (!$ban) {
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
}
@@ -91,10 +90,9 @@ class IpBanController extends BaseApiController
try {
if ($all) {
$count = $this->commandService->unbanAll();
return $this->success([
'count' => $count,
], $count.' IP(s) unbanned.');
], $count . ' IP(s) unbanned.');
}
$ban = $this->commandService->unbanOne(
@@ -102,12 +100,11 @@ class IpBanController extends BaseApiController
$validated['ip'] ?? null
);
} catch (\Throwable $e) {
Log::error('IP unban failed: '.$e->getMessage());
Log::error('IP unban failed: ' . $e->getMessage());
return $this->error('Unable to unban IP.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (! $ban) {
if (!$ban) {
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
}
@@ -3,7 +3,6 @@
namespace App\Http\Controllers\Api\Auth;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Requests\Auth\RegisterRequest;
use App\Http\Resources\Auth\RegisterResource;
use App\Services\Auth\ApiRegistrationService;
use App\Services\Auth\RegistrationCaptchaService;
@@ -51,7 +50,7 @@ class RegisterController extends BaseApiController
]);
}
$validator = Validator::make($request->all(), RegisterRequest::ruleset());
$validator = Validator::make($request->all(), \App\Http\Requests\Auth\RegisterRequest::ruleset());
if ($validator->fails()) {
return response()->json([
'message' => 'Validation failed.',
@@ -56,7 +56,7 @@ class RolePermissionController extends BaseApiController
public function showRole(int $roleId): JsonResponse
{
$role = Role::query()->find($roleId);
if (! $role) {
if (!$role) {
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
}
@@ -70,8 +70,7 @@ class RolePermissionController extends BaseApiController
try {
$role = $this->roleCrudService->create($request->validated());
} catch (\Throwable $e) {
Log::error('Role store failed: '.$e->getMessage());
Log::error('Role store failed: ' . $e->getMessage());
return $this->error('Failed to create role.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -83,15 +82,14 @@ class RolePermissionController extends BaseApiController
public function updateRole(RoleUpdateRequest $request, int $roleId): JsonResponse
{
$role = Role::query()->find($roleId);
if (! $role) {
if (!$role) {
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
}
try {
$role = $this->roleCrudService->update($role, $request->validated());
} catch (\Throwable $e) {
Log::error('Role update failed: '.$e->getMessage());
Log::error('Role update failed: ' . $e->getMessage());
return $this->error('Failed to update role.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -103,15 +101,14 @@ class RolePermissionController extends BaseApiController
public function deleteRole(int $roleId): JsonResponse
{
$role = Role::query()->find($roleId);
if (! $role) {
if (!$role) {
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
}
try {
$this->roleCrudService->delete($role);
} catch (\Throwable $e) {
Log::error('Role delete failed: '.$e->getMessage());
Log::error('Role delete failed: ' . $e->getMessage());
return $this->error('Failed to delete role.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -147,12 +144,11 @@ class RolePermissionController extends BaseApiController
$actorId
);
} catch (\Throwable $e) {
Log::error('Assign roles failed: '.$e->getMessage());
Log::error('Assign roles failed: ' . $e->getMessage());
return $this->error('Failed to update roles.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
if (! ($result['ok'] ?? false)) {
if (!($result['ok'] ?? false)) {
return $this->error($result['message'] ?? 'Failed to update roles.', Response::HTTP_UNPROCESSABLE_ENTITY);
}
@@ -173,7 +169,7 @@ class RolePermissionController extends BaseApiController
public function showPermission(int $permissionId): JsonResponse
{
$permission = Permission::query()->find($permissionId);
if (! $permission) {
if (!$permission) {
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
}
@@ -187,8 +183,7 @@ class RolePermissionController extends BaseApiController
try {
$permission = $this->permissionCrudService->create($request->validated());
} catch (\Throwable $e) {
Log::error('Permission store failed: '.$e->getMessage());
Log::error('Permission store failed: ' . $e->getMessage());
return $this->error('Failed to create permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -200,15 +195,14 @@ class RolePermissionController extends BaseApiController
public function updatePermission(PermissionUpdateRequest $request, int $permissionId): JsonResponse
{
$permission = Permission::query()->find($permissionId);
if (! $permission) {
if (!$permission) {
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
}
try {
$permission = $this->permissionCrudService->update($permission, $request->validated());
} catch (\Throwable $e) {
Log::error('Permission update failed: '.$e->getMessage());
Log::error('Permission update failed: ' . $e->getMessage());
return $this->error('Failed to update permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -220,15 +214,14 @@ class RolePermissionController extends BaseApiController
public function deletePermission(int $permissionId): JsonResponse
{
$permission = Permission::query()->find($permissionId);
if (! $permission) {
if (!$permission) {
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
}
try {
$this->permissionCrudService->delete($permission);
} catch (\Throwable $e) {
Log::error('Permission delete failed: '.$e->getMessage());
Log::error('Permission delete failed: ' . $e->getMessage());
return $this->error('Failed to delete permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
@@ -249,14 +242,16 @@ class RolePermissionController extends BaseApiController
try {
$this->permissionService->saveRolePermissions($roleId, $request->validated()['permissions'] ?? []);
} catch (\Throwable $e) {
Log::error('Role permissions update failed: '.$e->getMessage());
Log::error('Role permissions update failed: ' . $e->getMessage());
return $this->error('Failed to update role permissions.', Response::HTTP_INTERNAL_SERVER_ERROR);
}
return $this->success(null, 'Permissions saved successfully.');
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
@@ -6,9 +6,9 @@ use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Requests\Roles\RoleSwitchRequest;
use App\Services\Roles\RoleSwitchService;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
class RoleSwitcherController extends BaseApiController
{
@@ -56,6 +56,9 @@ class RoleSwitcherController extends BaseApiController
], 'Role switched successfully.');
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
@@ -19,7 +19,8 @@ class SessionTimeoutController extends Controller
public function __construct(
private ApplicationUrlService $urls,
) {}
) {
}
/**
* Returns timeout metadata for the web portal.