From 235787d2237ae94a12fea26605afb9c857abce68 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 2 Jun 2025 18:29:12 -0400 Subject: [PATCH] Add CreateOperator class to handle operator creation and logging --- .../Methods/CreateOperator.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/FederationServer/Methods/CreateOperator.php diff --git a/src/FederationServer/Methods/CreateOperator.php b/src/FederationServer/Methods/CreateOperator.php new file mode 100644 index 0000000..611e298 --- /dev/null +++ b/src/FederationServer/Methods/CreateOperator.php @@ -0,0 +1,53 @@ +canManageOperators()) + { + throw new RequestException('Unauthorized: Insufficient permissions to create operators', 403); + } + + if(!FederationServer::getParameter('name')) + { + throw new RequestException('Bad Request: Operator name is required', 400); + } + + try + { + $operatorUuid = OperatorManager::createOperator(FederationServer::getParameter('name')); + AuditLogManager::createEntry(AuditLogType::OPERATOR_CREATED, sprintf('Operator %s (%s) created by %s (%s)', + FederationServer::getParameter('name'), + $operatorUuid, + $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($operatorUuid); + } + } \ No newline at end of file