Add ListOperatorBlacklist request handler
This commit is contained in:
parent
d7095064c0
commit
0e6410fd62
1 changed files with 68 additions and 0 deletions
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace FederationServer\Methods\Operators;
|
||||
|
||||
use FederationServer\Classes\Configuration;
|
||||
use FederationServer\Classes\Managers\BlacklistManager;
|
||||
use FederationServer\Classes\Managers\OperatorManager;
|
||||
use FederationServer\Classes\RequestHandler;
|
||||
use FederationServer\Classes\Validate;
|
||||
use FederationServer\Exceptions\DatabaseOperationException;
|
||||
use FederationServer\Exceptions\RequestException;
|
||||
use FederationServer\FederationServer;
|
||||
|
||||
class ListOperatorBlacklist extends RequestHandler
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function handleRequest(): void
|
||||
{
|
||||
$authenticatedOperator = FederationServer::getAuthenticatedOperator(false);
|
||||
if(!Configuration::getServerConfiguration()->isBlacklistPublic() && $authenticatedOperator === null)
|
||||
{
|
||||
throw new RequestException('Unauthorized: You must be authenticated to list blacklist records', 401);
|
||||
}
|
||||
|
||||
$limit = (int) (FederationServer::getParameter('limit') ?? Configuration::getServerConfiguration()->getListBlacklistMaxItems());
|
||||
$page = (int) (FederationServer::getParameter('page') ?? 1);
|
||||
|
||||
if($limit < 1 || $limit > Configuration::getServerConfiguration()->getListBlacklistMaxItems())
|
||||
{
|
||||
$limit = Configuration::getServerConfiguration()->getListBlacklistMaxItems();
|
||||
}
|
||||
|
||||
if($page < 1)
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if(!preg_match('#^/operators/([a-fA-F0-9\-]{36,})/blacklist$#', FederationServer::getPath(), $matches))
|
||||
{
|
||||
throw new RequestException('Bad Request: Operator UUID is required', 400);
|
||||
}
|
||||
|
||||
$operatorUuid = $matches[1];
|
||||
if(!$operatorUuid || !Validate::uuid($operatorUuid))
|
||||
{
|
||||
throw new RequestException('Bad Request: a valid operator UUID is required', 400);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(!OperatorManager::operatorExists($operatorUuid))
|
||||
{
|
||||
throw new RequestException('Operator not found', 404);
|
||||
}
|
||||
|
||||
$blacklistRecords = BlacklistManager::getEntriesByOperator($operatorUuid, $limit, $page);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new RequestException('Internal Server Error: Unable to retrieve blacklist records from the operator', 500, $e);
|
||||
}
|
||||
|
||||
self::successResponse(array_map(fn($evidence) => $evidence->toArray(), $blacklistRecords));
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue