From e23d3280ee9fee8fca81f63f4243e47f5d45f3d4 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 2 Jun 2025 18:29:18 -0400 Subject: [PATCH] Add DeleteOperator class to handle operator deletion and logging --- .../Methods/DeleteOperator.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/FederationServer/Methods/DeleteOperator.php diff --git a/src/FederationServer/Methods/DeleteOperator.php b/src/FederationServer/Methods/DeleteOperator.php new file mode 100644 index 0000000..1600f1a --- /dev/null +++ b/src/FederationServer/Methods/DeleteOperator.php @@ -0,0 +1,59 @@ +canManageOperators()) + { + throw new RequestException('Unauthorized: Insufficient permissions to delete 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); + } + + OperatorManager::deleteOperator(FederationServer::getParameter('uuid')); + AuditLogManager::createEntry(AuditLogType::OPERATOR_DELETED, sprintf('Operator %s (%s) deleted by %s (%s)', + $existingOperator->getName(), + $existingOperator->getUuid(), + $authenticatedOperator->getName(), + $authenticatedOperator->getUuid() + ), $authenticatedOperator->getUuid()); + } + catch(DatabaseOperationException $e) + { + Logger::log()->error('Database error while creating operator: ' . $e->getMessage(), $e); + throw new RequestException('Internal Server Error: Unable to create operator', 500, $e); + } + + // Respond with the UUID of the newly created operator. + self::successResponse(); + } + } \ No newline at end of file