Update operator routes to separate GET and POST method handling
This commit is contained in:
parent
92acf4257c
commit
99a454ccd9
2 changed files with 69 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
use FederationServer\Methods\Attachments\DownloadAttachment;
|
use FederationServer\Methods\Attachments\DownloadAttachment;
|
||||||
use FederationServer\Methods\Attachments\UploadAttachment;
|
use FederationServer\Methods\Attachments\UploadAttachment;
|
||||||
use FederationServer\Methods\Audit\ListAuditLogs;
|
use FederationServer\Methods\Audit\ListAuditLogs;
|
||||||
|
use FederationServer\Methods\Audit\ViewAuditEntry;
|
||||||
use FederationServer\Methods\Operators\CreateOperator;
|
use FederationServer\Methods\Operators\CreateOperator;
|
||||||
use FederationServer\Methods\Operators\DeleteOperator;
|
use FederationServer\Methods\Operators\DeleteOperator;
|
||||||
use FederationServer\Methods\Operators\EnableOperator;
|
use FederationServer\Methods\Operators\EnableOperator;
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
enum Method
|
enum Method
|
||||||
{
|
{
|
||||||
case LIST_AUDIT_LOGS;
|
case LIST_AUDIT_LOGS;
|
||||||
|
case VIEW_AUDIT_ENTRY;
|
||||||
|
|
||||||
case LIST_OPERATORS;
|
case LIST_OPERATORS;
|
||||||
case CREATE_OPERATOR;
|
case CREATE_OPERATOR;
|
||||||
|
@ -48,6 +50,9 @@
|
||||||
case self::LIST_AUDIT_LOGS:
|
case self::LIST_AUDIT_LOGS:
|
||||||
ListAuditLogs::handleRequest();
|
ListAuditLogs::handleRequest();
|
||||||
break;
|
break;
|
||||||
|
case self::VIEW_AUDIT_ENTRY:
|
||||||
|
ViewAuditEntry::handleRequest();
|
||||||
|
break;
|
||||||
|
|
||||||
case self::LIST_OPERATORS:
|
case self::LIST_OPERATORS:
|
||||||
ListOperators::handleRequest();
|
ListOperators::handleRequest();
|
||||||
|
@ -101,6 +106,7 @@
|
||||||
return match (true)
|
return match (true)
|
||||||
{
|
{
|
||||||
$path === '/' && $requestMethod === 'GET' => Method::LIST_AUDIT_LOGS,
|
$path === '/' && $requestMethod === 'GET' => Method::LIST_AUDIT_LOGS,
|
||||||
|
preg_match('#^/audit/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::VIEW_AUDIT_ENTRY,
|
||||||
|
|
||||||
preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::DOWNLOAD_ATTACHMENT,
|
preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::DOWNLOAD_ATTACHMENT,
|
||||||
preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_ATTACHMENT,
|
preg_match('#^/attachments/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_ATTACHMENT,
|
||||||
|
|
63
src/FederationServer/Methods/Audit/ViewAuditEntry.php
Normal file
63
src/FederationServer/Methods/Audit/ViewAuditEntry.php
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FederationServer\Methods\Audit;
|
||||||
|
|
||||||
|
use FederationServer\Classes\Managers\AuditLogManager;
|
||||||
|
use FederationServer\Classes\Managers\EntitiesManager;
|
||||||
|
use FederationServer\Classes\Managers\OperatorManager;
|
||||||
|
use FederationServer\Classes\RequestHandler;
|
||||||
|
use FederationServer\Exceptions\DatabaseOperationException;
|
||||||
|
use FederationServer\Exceptions\RequestException;
|
||||||
|
use FederationServer\FederationServer;
|
||||||
|
use FederationServer\Objects\PublicAuditRecord;
|
||||||
|
|
||||||
|
class ViewAuditEntry extends RequestHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function handleRequest(): void
|
||||||
|
{
|
||||||
|
if(!preg_match('#^/audit/([a-fA-F0-9\-]{36,})$#', FederationServer::getPath(), $matches))
|
||||||
|
{
|
||||||
|
throw new RequestException('Bad Request: Audit UUID is required', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$entryUuid = $matches[1];
|
||||||
|
if(!$entryUuid || !Validate::uuid($entryUuid))
|
||||||
|
{
|
||||||
|
throw new RequestException('Bad Request: Invalid Audit UUID', 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$logRecord = AuditLogManager::getEntry($entryUuid);
|
||||||
|
if(!$logRecord)
|
||||||
|
{
|
||||||
|
throw new RequestException('Audit log not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$operatorRecord = null;
|
||||||
|
$entityRecord = null;
|
||||||
|
|
||||||
|
if($logRecord->getOperator() !== null)
|
||||||
|
{
|
||||||
|
$operatorRecord = OperatorManager::getOperator($logRecord->getOperator());
|
||||||
|
}
|
||||||
|
|
||||||
|
if($logRecord->getEntity() !== null)
|
||||||
|
{
|
||||||
|
$entityRecord = EntitiesManager::getEntityByUuid($logRecord->getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = new PublicAuditRecord($logRecord, $operatorRecord, $entityRecord);
|
||||||
|
}
|
||||||
|
catch (DatabaseOperationException $e)
|
||||||
|
{
|
||||||
|
throw new RequestException('Internal Server Error: Unable to retrieve audit log', 500, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::successResponse($result->toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue