Implement LiftBlacklist functionality and related methods
This commit is contained in:
parent
0ad53d6032
commit
663ce2ceac
4 changed files with 101 additions and 1 deletions
|
@ -10,6 +10,7 @@
|
|||
use FederationServer\Methods\Audit\ViewAuditEntry;
|
||||
use FederationServer\Methods\Blacklist\BlacklistEntity;
|
||||
use FederationServer\Methods\Blacklist\DeleteBlacklist;
|
||||
use FederationServer\Methods\Blacklist\LiftBlacklist;
|
||||
use FederationServer\Methods\Blacklist\ListBlacklist;
|
||||
use FederationServer\Methods\Entities\DeleteEntity;
|
||||
use FederationServer\Methods\Entities\GetEntityRecord;
|
||||
|
@ -201,7 +202,7 @@
|
|||
DeleteBlacklist::handleRequest();
|
||||
break;
|
||||
case self::LIFT_BLACKLIST:
|
||||
throw new \Exception('To be implemented');
|
||||
LiftBlacklist::handleRequest();
|
||||
break;
|
||||
case self::BLACKLIST_ATTACH_EVIDENCE:
|
||||
throw new \Exception('To be implemented');
|
||||
|
|
|
@ -189,6 +189,32 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifts a blacklist record, marking it as no longer active.
|
||||
*
|
||||
* @param string $uuid The UUID of the blacklist record to lift.
|
||||
* @throws InvalidArgumentException If the UUID is empty.
|
||||
* @throws DatabaseOperationException If there is an error preparing or executing the SQL statement.
|
||||
*/
|
||||
public static function liftBlacklistRecord(string $uuid): void
|
||||
{
|
||||
if(empty($uuid))
|
||||
{
|
||||
throw new InvalidArgumentException("UUID cannot be empty.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$stmt = DatabaseConnection::getConnection()->prepare("UPDATE blacklist SET lifted=1 WHERE uuid = :uuid");
|
||||
$stmt->bindParam(':uuid', $uuid);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
throw new DatabaseOperationException("Failed to lift blacklist record: " . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of blacklist records in a pagination style for the global database
|
||||
*
|
||||
|
|
61
src/FederationServer/Methods/Blacklist/LiftBlacklist.php
Normal file
61
src/FederationServer/Methods/Blacklist/LiftBlacklist.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace FederationServer\Methods\Blacklist;
|
||||
|
||||
use FederationServer\Classes\Configuration;
|
||||
use FederationServer\Classes\Managers\BlacklistManager;
|
||||
use FederationServer\Classes\RequestHandler;
|
||||
use FederationServer\Classes\Validate;
|
||||
use FederationServer\Exceptions\DatabaseOperationException;
|
||||
use FederationServer\Exceptions\RequestException;
|
||||
use FederationServer\FederationServer;
|
||||
|
||||
class LiftBlacklist extends RequestHandler
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function handleRequest(): void
|
||||
{
|
||||
$authenticatedOperator = FederationServer::requireAuthenticatedOperator();
|
||||
if(!$authenticatedOperator->canManageBlacklist())
|
||||
{
|
||||
throw new RequestException('Insufficient permissions to manage the blacklist', 401);
|
||||
}
|
||||
|
||||
if(!preg_match('#^/blacklist/([a-fA-F0-9\-]{36,})$#', FederationServer::getPath(), $matches))
|
||||
{
|
||||
throw new RequestException('Blacklist UUID required', 405);
|
||||
}
|
||||
|
||||
$blacklistUuid = $matches[1];
|
||||
if(!$blacklistUuid || !Validate::uuid($blacklistUuid))
|
||||
{
|
||||
throw new RequestException('Invalid blacklist UUID', 400);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$blacklistRecord = BlacklistManager::getBlacklistEntry($blacklistUuid);
|
||||
|
||||
if($blacklistRecord === null)
|
||||
{
|
||||
throw new RequestException('Blacklist record not found', 404);
|
||||
}
|
||||
|
||||
if($blacklistRecord->isLifted())
|
||||
{
|
||||
throw new RequestException('Blacklist record is already lifted', 400);
|
||||
}
|
||||
|
||||
BlacklistManager::liftBlacklistRecord($blacklistUuid);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new RequestException('Unable to retrieve blacklist records', 500, $e);
|
||||
}
|
||||
|
||||
self::successResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
private string $entity;
|
||||
private ?string $evidence;
|
||||
private BlacklistType $type;
|
||||
private bool $lifted;
|
||||
private ?int $expires;
|
||||
private int $created;
|
||||
|
||||
|
@ -35,6 +36,7 @@
|
|||
$this->entity = $data['entity'] ?? '';
|
||||
$this->evidence = $data['evidence'] ?? null;
|
||||
$this->type = isset($data['type']) ? BlacklistType::from($data['type']) : BlacklistType::OTHER;
|
||||
$this->lifted = isset($data['lifted']) ? (bool)$data['lifted'] : false;
|
||||
$this->expires = isset($data['expires']) ? (int)$data['expires'] : null;
|
||||
$this->created = isset($data['created']) ? (int)$data['created'] : time();
|
||||
}
|
||||
|
@ -92,6 +94,16 @@
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the blacklist record has been lifted.
|
||||
*
|
||||
* @return bool True if the record is lifted, false otherwise.
|
||||
*/
|
||||
public function isLifted(): bool
|
||||
{
|
||||
return $this->lifted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expiration timestamp of the blacklist record.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue