Add ManageBlacklistPermission method to handle blacklist permission management with validation
This commit is contained in:
parent
7ab602eef0
commit
9358366f3c
2 changed files with 56 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace FederationServer\Classes\Enums;
|
namespace FederationServer\Classes\Enums;
|
||||||
|
|
||||||
use FederationServer\Exceptions\RequestException;
|
use FederationServer\Exceptions\RequestException;
|
||||||
|
use FederationServer\Methods\ManageBlacklistPermission;
|
||||||
use FederationServer\Methods\ManageOperatorsPermission;
|
use FederationServer\Methods\ManageOperatorsPermission;
|
||||||
use FederationServer\Methods\CreateOperator;
|
use FederationServer\Methods\CreateOperator;
|
||||||
use FederationServer\Methods\DeleteOperator;
|
use FederationServer\Methods\DeleteOperator;
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
case GET_OPERATOR;
|
case GET_OPERATOR;
|
||||||
case REFRESH_OPERATOR_API_KEY;
|
case REFRESH_OPERATOR_API_KEY;
|
||||||
case MANAGE_OPERATORS_PERMISSION;
|
case MANAGE_OPERATORS_PERMISSION;
|
||||||
|
case MANAGE_BLACKLIST_PERMISSION;
|
||||||
|
|
||||||
case UPLOAD_ATTACHMENT;
|
case UPLOAD_ATTACHMENT;
|
||||||
case DOWNLOAD_ATTACHMENT;
|
case DOWNLOAD_ATTACHMENT;
|
||||||
|
@ -52,6 +54,9 @@
|
||||||
case self::MANAGE_OPERATORS_PERMISSION:
|
case self::MANAGE_OPERATORS_PERMISSION:
|
||||||
ManageOperatorsPermission::handleRequest();
|
ManageOperatorsPermission::handleRequest();
|
||||||
break;
|
break;
|
||||||
|
case self::MANAGE_BLACKLIST_PERMISSION:
|
||||||
|
ManageBlacklistPermission::handleRequest();
|
||||||
|
break;
|
||||||
|
|
||||||
case self::UPLOAD_ATTACHMENT:
|
case self::UPLOAD_ATTACHMENT:
|
||||||
UploadAttachment::handleRequest();
|
UploadAttachment::handleRequest();
|
||||||
|
@ -84,6 +89,7 @@
|
||||||
$requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR,
|
$requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR,
|
||||||
$requestMethod === 'POST' && $path === '/operators/refresh' => Method::REFRESH_OPERATOR_API_KEY,
|
$requestMethod === 'POST' && $path === '/operators/refresh' => Method::REFRESH_OPERATOR_API_KEY,
|
||||||
$requestMethod === 'POST' && $path === '/operators/permissions/manage_operators' => Method::MANAGE_OPERATORS_PERMISSION,
|
$requestMethod === 'POST' && $path === '/operators/permissions/manage_operators' => Method::MANAGE_OPERATORS_PERMISSION,
|
||||||
|
$requestMethod === 'POST' && $path === '/operators/permissions/manage_blacklist' => Method::MANAGE_BLACKLIST_PERMISSION,
|
||||||
|
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
50
src/FederationServer/Methods/ManageBlacklistPermission.php
Normal file
50
src/FederationServer/Methods/ManageBlacklistPermission.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FederationServer\Methods;
|
||||||
|
|
||||||
|
use FederationServer\Classes\Logger;
|
||||||
|
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 ManageBlacklistPermission extends RequestHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function handleRequest(): void
|
||||||
|
{
|
||||||
|
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
|
||||||
|
if(!$authenticatedOperator->canManageOperators())
|
||||||
|
{
|
||||||
|
throw new RequestException('Unauthorized: Insufficient permissions manage permissions', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$operatorUuid = FederationServer::getParameter('uuid');
|
||||||
|
$enabled = (bool)filter_var(FederationServer::getParameter('enabled'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||||
|
if($operatorUuid === null)
|
||||||
|
{
|
||||||
|
throw new RequestException('Bad Request: Missing required parameters', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!Validate::uuid($operatorUuid))
|
||||||
|
{
|
||||||
|
throw new RequestException('Bad Request: Invalid operator UUID', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OperatorManager::setManageBlacklist($operatorUuid, $enabled);
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
Logger::log()->error('Database error while managing operator\'s permissions: ' . $e->getMessage(), $e);
|
||||||
|
throw new RequestException('Internal Server Error: Unable to manage operator\'s permissions', 500, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::successResponse();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue