Add ManageOperatorsPermission method to handle operator permission management with validation
Some checks are pending
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / release (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
Some checks are pending
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / release (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
This commit is contained in:
parent
c816ed59fe
commit
7ab602eef0
2 changed files with 56 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace FederationServer\Classes\Enums;
|
||||
|
||||
use FederationServer\Exceptions\RequestException;
|
||||
use FederationServer\Methods\ManageOperatorsPermission;
|
||||
use FederationServer\Methods\CreateOperator;
|
||||
use FederationServer\Methods\DeleteOperator;
|
||||
use FederationServer\Methods\DownloadAttachment;
|
||||
|
@ -18,6 +19,7 @@
|
|||
case ENABLE_OPERATOR;
|
||||
case GET_OPERATOR;
|
||||
case REFRESH_OPERATOR_API_KEY;
|
||||
case MANAGE_OPERATORS_PERMISSION;
|
||||
|
||||
case UPLOAD_ATTACHMENT;
|
||||
case DOWNLOAD_ATTACHMENT;
|
||||
|
@ -47,6 +49,9 @@
|
|||
case self::REFRESH_OPERATOR_API_KEY:
|
||||
RefreshOperatorApiKey::handleRequest();
|
||||
break;
|
||||
case self::MANAGE_OPERATORS_PERMISSION:
|
||||
ManageOperatorsPermission::handleRequest();
|
||||
break;
|
||||
|
||||
case self::UPLOAD_ATTACHMENT:
|
||||
UploadAttachment::handleRequest();
|
||||
|
@ -78,6 +83,7 @@
|
|||
$requestMethod === 'GET' && $path === '/operators/get' => Method::GET_OPERATOR,
|
||||
$requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR,
|
||||
$requestMethod === 'POST' && $path === '/operators/refresh' => Method::REFRESH_OPERATOR_API_KEY,
|
||||
$requestMethod === 'POST' && $path === '/operators/permissions/manage_operators' => Method::MANAGE_OPERATORS_PERMISSION,
|
||||
|
||||
default => null,
|
||||
};
|
||||
|
|
50
src/FederationServer/Methods/ManageOperatorsPermission.php
Normal file
50
src/FederationServer/Methods/ManageOperatorsPermission.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 ManageOperatorsPermission 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::setManageOperators($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