diff --git a/src/FederationServer/Classes/Managers/AuditLogManager.php b/src/FederationServer/Classes/Managers/AuditLogManager.php index e974346..7b04386 100644 --- a/src/FederationServer/Classes/Managers/AuditLogManager.php +++ b/src/FederationServer/Classes/Managers/AuditLogManager.php @@ -8,7 +8,6 @@ use FederationServer\Classes\Logger; use FederationServer\Exceptions\DatabaseOperationException; use FederationServer\Objects\AuditLogRecord; - use FederationServer\Objects\PublicAuditRecord; use InvalidArgumentException; use PDO; use PDOException; @@ -319,31 +318,6 @@ } } - /** - * Converts an AuditLogRecord to a PublicAuditRecord. - * - * @param AuditLogRecord $record The AuditLogRecord to convert. - * @return PublicAuditRecord The converted PublicAuditRecord. - * @throws DatabaseOperationException Thrown if there was a database error while transforming the record. - */ - public static function toPublicAuditRecord(AuditLogRecord $record): PublicAuditRecord - { - $operatorRecord = null; - $entityRecord = null; - - if($record->getOperator() !== null) - { - $operatorRecord = OperatorManager::getOperator($record->getOperator()); - } - - if($record->getEntity() !== null) - { - $entityRecord = EntitiesManager::getEntityByUuid($record->getEntity()); - } - - return new PublicAuditRecord($record, $operatorRecord, $entityRecord); - } - /** * Deletes all audit log entries. * diff --git a/src/FederationServer/Methods/Audit/ListAuditLogs.php b/src/FederationServer/Methods/Audit/ListAuditLogs.php index b9e730d..1e326e0 100644 --- a/src/FederationServer/Methods/Audit/ListAuditLogs.php +++ b/src/FederationServer/Methods/Audit/ListAuditLogs.php @@ -50,8 +50,8 @@ try { - $results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log), - AuditLogManager::getEntries($limit, $page, $filteredEntries) + self::successResponse(array_map(fn($log) => $log->toArray(), + AuditLogManager::getEntries($limit, $page, $filteredEntries)) ); } catch (DatabaseOperationException $e) @@ -59,7 +59,6 @@ throw new RequestException('Internal Server Error: Unable to retrieve audit logs', 500, $e); } - self::successResponse(array_map(fn($log) => $log->toArray(), $results)); } } diff --git a/src/FederationServer/Methods/Audit/ViewAuditEntry.php b/src/FederationServer/Methods/Audit/ViewAuditEntry.php index 67dfaa8..6cb7037 100644 --- a/src/FederationServer/Methods/Audit/ViewAuditEntry.php +++ b/src/FederationServer/Methods/Audit/ViewAuditEntry.php @@ -3,14 +3,11 @@ 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\Classes\Validate; use FederationServer\Exceptions\DatabaseOperationException; use FederationServer\Exceptions\RequestException; use FederationServer\FederationServer; - use FederationServer\Objects\PublicAuditRecord; class ViewAuditEntry extends RequestHandler { @@ -38,27 +35,12 @@ 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); + self::successResponse($logRecord->toArray()); } catch (DatabaseOperationException $e) { throw new RequestException('Internal Server Error: Unable to retrieve audit log', 500, $e); } - - self::successResponse($result->toArray()); } } diff --git a/src/FederationServer/Methods/Entities/ListEntityAuditLogs.php b/src/FederationServer/Methods/Entities/ListEntityAuditLogs.php index dd08e90..b67b5e8 100644 --- a/src/FederationServer/Methods/Entities/ListEntityAuditLogs.php +++ b/src/FederationServer/Methods/Entities/ListEntityAuditLogs.php @@ -67,16 +67,14 @@ throw new RequestException('Not Found: Entity with the specified UUID does not exist', 404); } - $results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log), - AuditLogManager::getEntriesByEntity($entityUuid, $limit, $page, $filteredEntries) + self::successResponse(array_map(fn($log) => $log->toArray(), + AuditLogManager::getEntriesByEntity($entityUuid, $limit, $page, $filteredEntries)) ); } catch (DatabaseOperationException $e) { throw new RequestException('Internal Server Error: Unable to retrieve audit logs', 500, $e); } - - self::successResponse(array_map(fn($log) => $log->toArray(), $results)); } } diff --git a/src/FederationServer/Methods/Operators/ListOperatorAuditLogs.php b/src/FederationServer/Methods/Operators/ListOperatorAuditLogs.php index 334a304..1ea77cd 100644 --- a/src/FederationServer/Methods/Operators/ListOperatorAuditLogs.php +++ b/src/FederationServer/Methods/Operators/ListOperatorAuditLogs.php @@ -67,16 +67,14 @@ throw new RequestException('Not Found: Operator with the specified UUID does not exist', 404); } - $results = array_map(fn($log) => AuditLogManager::toPublicAuditRecord($log), - AuditLogManager::getEntriesByOperator($operatorUuid, $limit, $page, $filteredEntries) + self::successResponse(array_map(fn($log) => $log->toArray(), + AuditLogManager::getEntriesByOperator($operatorUuid, $limit, $page, $filteredEntries)) ); } catch (DatabaseOperationException $e) { throw new RequestException('Internal Server Error: Unable to retrieve audit logs', 500, $e); } - - self::successResponse(array_map(fn($log) => $log->toArray(), $results)); } } diff --git a/src/FederationServer/Objects/PublicAuditRecord.php b/src/FederationServer/Objects/PublicAuditRecord.php deleted file mode 100644 index 1364cae..0000000 --- a/src/FederationServer/Objects/PublicAuditRecord.php +++ /dev/null @@ -1,85 +0,0 @@ -toPublicRecord(); - } - - $this->uuid = $auditLogRecord->getUuid(); - $this->operator = $operator; - $this->entity = $entity; - $this->type = $auditLogRecord->getType(); - $this->message = $auditLogRecord->getMessage(); - $this->timestamp = $auditLogRecord->getTimestamp(); - } - - public function getUuid(): string - { - return $this->uuid; - } - - public function getOperator(): ?PublicOperatorRecord - { - return $this->operator; - } - - public function getEntity(): ?EntityRecord - { - return $this->entity; - } - - public function getType(): AuditLogType - { - return $this->type; - } - - public function getMessage(): string - { - return $this->message; - } - - public function getTimestamp(): int - { - return $this->timestamp; - } - - /** - * @inheritDoc - */ - public function toArray(): array - { - return [ - 'uuid' => $this->uuid, - 'operator' => $this->operator?->toArray(), - 'entity' => $this->entity?->toArray(), - 'type' => $this->type->value, - 'message' => $this->message, - 'timestamp' => $this->timestamp - ]; - } - - /** - * @inheritDoc - */ - public static function fromArray(array $array): SerializableInterface - { - throw new InvalidArgumentException('fromArray() is not implemented in PublicAuditRecord'); - } - } \ No newline at end of file