Implement DeleteBlacklist functionality and refactor related methods
This commit is contained in:
parent
14da271f06
commit
0ad53d6032
3 changed files with 63 additions and 8 deletions
|
@ -9,6 +9,7 @@
|
||||||
use FederationServer\Methods\Audit\ListAuditLogs;
|
use FederationServer\Methods\Audit\ListAuditLogs;
|
||||||
use FederationServer\Methods\Audit\ViewAuditEntry;
|
use FederationServer\Methods\Audit\ViewAuditEntry;
|
||||||
use FederationServer\Methods\Blacklist\BlacklistEntity;
|
use FederationServer\Methods\Blacklist\BlacklistEntity;
|
||||||
|
use FederationServer\Methods\Blacklist\DeleteBlacklist;
|
||||||
use FederationServer\Methods\Blacklist\ListBlacklist;
|
use FederationServer\Methods\Blacklist\ListBlacklist;
|
||||||
use FederationServer\Methods\Entities\DeleteEntity;
|
use FederationServer\Methods\Entities\DeleteEntity;
|
||||||
use FederationServer\Methods\Entities\GetEntityRecord;
|
use FederationServer\Methods\Entities\GetEntityRecord;
|
||||||
|
@ -197,7 +198,7 @@
|
||||||
BlacklistEntity::handleRequest();
|
BlacklistEntity::handleRequest();
|
||||||
break;
|
break;
|
||||||
case self::DELETE_BLACKLIST:
|
case self::DELETE_BLACKLIST:
|
||||||
throw new \Exception('To be implemented');
|
DeleteBlacklist::handleRequest();
|
||||||
break;
|
break;
|
||||||
case self::LIFT_BLACKLIST:
|
case self::LIFT_BLACKLIST:
|
||||||
throw new \Exception('To be implemented');
|
throw new \Exception('To be implemented');
|
||||||
|
|
|
@ -166,26 +166,26 @@
|
||||||
/**
|
/**
|
||||||
* Deletes a blacklist entry for a specific entity.
|
* Deletes a blacklist entry for a specific entity.
|
||||||
*
|
*
|
||||||
* @param string $entity The UUID of the entity to remove from the blacklist.
|
* @param string $uuid The UUID of the blacklist entry to delete.
|
||||||
* @throws InvalidArgumentException If the entity is empty.
|
* @throws InvalidArgumentException If the entity is empty.
|
||||||
* @throws DatabaseOperationException If there is an error preparing or executing the SQL statement.
|
* @throws DatabaseOperationException If there is an error preparing or executing the SQL statement.
|
||||||
*/
|
*/
|
||||||
public static function deleteBlacklistEntry(string $entity): void
|
public static function deleteBlacklistRecord(string $uuid): void
|
||||||
{
|
{
|
||||||
if(empty($entity))
|
if(empty($uuid))
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Entity cannot be empty.");
|
throw new InvalidArgumentException("UUID cannot be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmt = DatabaseConnection::getConnection()->prepare("DELETE FROM blacklist WHERE entity = :entity");
|
$stmt = DatabaseConnection::getConnection()->prepare("DELETE FROM blacklist WHERE uuid = :uuid");
|
||||||
$stmt->bindParam(':entity', $entity);
|
$stmt->bindParam(':uuid', $uuid);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
catch (PDOException $e)
|
||||||
{
|
{
|
||||||
throw new DatabaseOperationException("Failed to delete blacklist entry: " . $e->getMessage(), 0, $e);
|
throw new DatabaseOperationException("Failed to delete blacklist record: " . $e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/FederationServer/Methods/Blacklist/DeleteBlacklist.php
Normal file
54
src/FederationServer/Methods/Blacklist/DeleteBlacklist.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?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 DeleteBlacklist 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
|
||||||
|
{
|
||||||
|
if(!BlacklistManager::blacklistExists($blacklistUuid))
|
||||||
|
{
|
||||||
|
throw new RequestException('Blacklist record not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlacklistManager::deleteBlacklistRecord($blacklistUuid);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new RequestException('Unable to retrieve blacklist records', 500, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue