Add GetOperator method to retrieve operator details with permission checks
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (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 / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (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
bfabbe3e17
commit
a278d5cc25
2 changed files with 57 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
use FederationServer\Methods\DeleteOperator;
|
use FederationServer\Methods\DeleteOperator;
|
||||||
use FederationServer\Methods\DownloadAttachment;
|
use FederationServer\Methods\DownloadAttachment;
|
||||||
use FederationServer\Methods\EnableOperator;
|
use FederationServer\Methods\EnableOperator;
|
||||||
|
use FederationServer\Methods\GetOperator;
|
||||||
use FederationServer\Methods\UploadAttachment;
|
use FederationServer\Methods\UploadAttachment;
|
||||||
|
|
||||||
enum Method
|
enum Method
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
case CREATE_OPERATOR;
|
case CREATE_OPERATOR;
|
||||||
case DELETE_OPERATOR;
|
case DELETE_OPERATOR;
|
||||||
case ENABLE_OPERATOR;
|
case ENABLE_OPERATOR;
|
||||||
|
case GET_OPERATOR;
|
||||||
|
|
||||||
case UPLOAD_ATTACHMENT;
|
case UPLOAD_ATTACHMENT;
|
||||||
case DOWNLOAD_ATTACHMENT;
|
case DOWNLOAD_ATTACHMENT;
|
||||||
|
@ -37,6 +39,9 @@
|
||||||
case self::ENABLE_OPERATOR:
|
case self::ENABLE_OPERATOR:
|
||||||
EnableOperator::handleRequest();
|
EnableOperator::handleRequest();
|
||||||
break;
|
break;
|
||||||
|
case self::GET_OPERATOR:
|
||||||
|
GetOperator::handleRequest();
|
||||||
|
break;
|
||||||
|
|
||||||
case self::UPLOAD_ATTACHMENT:
|
case self::UPLOAD_ATTACHMENT:
|
||||||
UploadAttachment::handleRequest();
|
UploadAttachment::handleRequest();
|
||||||
|
@ -65,6 +70,7 @@
|
||||||
|
|
||||||
$requestMethod === 'POST' && $path === '/operators/create' => Method::CREATE_OPERATOR,
|
$requestMethod === 'POST' && $path === '/operators/create' => Method::CREATE_OPERATOR,
|
||||||
$requestMethod === 'DELETE' && $path === '/operators/delete' => Method::DELETE_OPERATOR,
|
$requestMethod === 'DELETE' && $path === '/operators/delete' => Method::DELETE_OPERATOR,
|
||||||
|
$requestMethod === 'GET' && $path === '/operators/get' => Method::GET_OPERATOR,
|
||||||
$requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR,
|
$requestMethod === 'POST' && $path === '/operators/enable' => Method::ENABLE_OPERATOR,
|
||||||
|
|
||||||
default => null,
|
default => null,
|
||||||
|
|
51
src/FederationServer/Methods/GetOperator.php
Normal file
51
src/FederationServer/Methods/GetOperator.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FederationServer\Methods;
|
||||||
|
|
||||||
|
use FederationServer\Classes\Enums\AuditLogType;
|
||||||
|
use FederationServer\Classes\Logger;
|
||||||
|
use FederationServer\Classes\Managers\AuditLogManager;
|
||||||
|
use FederationServer\Classes\Managers\OperatorManager;
|
||||||
|
use FederationServer\Classes\RequestHandler;
|
||||||
|
use FederationServer\Exceptions\DatabaseOperationException;
|
||||||
|
use FederationServer\Exceptions\RequestException;
|
||||||
|
use FederationServer\FederationServer;
|
||||||
|
|
||||||
|
class GetOperator extends RequestHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function handleRequest(): void
|
||||||
|
{
|
||||||
|
$authenticatedOperator = FederationServer::getAuthenticatedOperator();
|
||||||
|
|
||||||
|
// Ensure the authenticated operator has permission to delete operators.
|
||||||
|
if(!$authenticatedOperator->canManageOperators())
|
||||||
|
{
|
||||||
|
throw new RequestException('Unauthorized: Insufficient permissions to get operators', 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!FederationServer::getParameter('uuid'))
|
||||||
|
{
|
||||||
|
throw new RequestException('Bad Request: Operator UUID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$existingOperator = OperatorManager::getOperator(FederationServer::getParameter('uuid'));
|
||||||
|
if($existingOperator === null)
|
||||||
|
{
|
||||||
|
throw new RequestException('Operator Not Found', 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
Logger::log()->error('Database error while getting operator: ' . $e->getMessage(), $e);
|
||||||
|
throw new RequestException('Internal Server Error: Unable to get operator', 500, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Respond with the UUID of the newly created operator.
|
||||||
|
self::successResponse($existingOperator->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue