From 99a454ccd9e9093e36b4e323666534d1ef2e2851 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 3 Jun 2025 15:23:57 -0400 Subject: [PATCH] Update operator routes to separate GET and POST method handling --- src/FederationServer/Classes/Enums/Method.php | 6 ++ .../Methods/Audit/ViewAuditEntry.php | 63 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/FederationServer/Methods/Audit/ViewAuditEntry.php diff --git a/src/FederationServer/Classes/Enums/Method.php b/src/FederationServer/Classes/Enums/Method.php index c9b5e4d..364600c 100644 --- a/src/FederationServer/Classes/Enums/Method.php +++ b/src/FederationServer/Classes/Enums/Method.php @@ -7,6 +7,7 @@ use FederationServer\Methods\Attachments\DownloadAttachment; use FederationServer\Methods\Attachments\UploadAttachment; use FederationServer\Methods\Audit\ListAuditLogs; + use FederationServer\Methods\Audit\ViewAuditEntry; use FederationServer\Methods\Operators\CreateOperator; use FederationServer\Methods\Operators\DeleteOperator; use FederationServer\Methods\Operators\EnableOperator; @@ -20,6 +21,7 @@ enum Method { case LIST_AUDIT_LOGS; + case VIEW_AUDIT_ENTRY; case LIST_OPERATORS; case CREATE_OPERATOR; @@ -48,6 +50,9 @@ case self::LIST_AUDIT_LOGS: ListAuditLogs::handleRequest(); break; + case self::VIEW_AUDIT_ENTRY: + ViewAuditEntry::handleRequest(); + break; case self::LIST_OPERATORS: ListOperators::handleRequest(); @@ -101,6 +106,7 @@ return match (true) { $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 === 'DELETE' => Method::DELETE_ATTACHMENT, diff --git a/src/FederationServer/Methods/Audit/ViewAuditEntry.php b/src/FederationServer/Methods/Audit/ViewAuditEntry.php new file mode 100644 index 0000000..800d16b --- /dev/null +++ b/src/FederationServer/Methods/Audit/ViewAuditEntry.php @@ -0,0 +1,63 @@ +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()); + } + } +