LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
add initial default platform key while creating a new organization (#63)
ali26a6e6568217
diff --git a/backend/account/authentication_controller.py b/backend/account/authentication_controller.pyindex f434a6a03..bc13270d1 100644--- a/backend/account/authentication_controller.py+++ b/backend/account/authentication_controller.py@@ -187,6 +187,7 @@ class AuthenticationController:self, request: Request, organization_id: str) -> Response:user: User = request.user+ new_organization = Falseorganization_ids = CacheService.get_user_organizations(user.user_id)if not organization_ids:z_organizations: list[@@ -212,12 +213,17 @@ class AuthenticationController:organization_data.display_name,organization_data.id,)+ new_organization = Trueexcept IntegrityError:raise DuplicateData(f"{ErrorMessage.ORGANIZATION_EXIST}, \{ErrorMessage.DUPLICATE_API}")self.create_tenant_user(organization=organization, user=user)+ if new_organization:+ self.authentication_helper.create_initial_platform_key(+ user=user, organization=organization+ )user_info: Optional[UserInfo] = self.get_user_info(request)serialized_user_info = SetOrganizationsResponseSerializer(user_infodiff --git a/backend/account/authentication_helper.py b/backend/account/authentication_helper.pyindex 69a80dcd4..6642ac238 100644--- a/backend/account/authentication_helper.py+++ b/backend/account/authentication_helper.py@@ -1,9 +1,16 @@+import loggingfrom typing import Anyfrom account.constants import DefaultOrgfrom account.dto import CallbackData, MemberData, OrganizationData+from account.models import Organization, User+from platform_settings.platform_auth_service import (+ PlatformAuthenticationService,+)from rest_framework.request import Request+logger = logging.getLogger(__name__)+class AuthenticationHelper:def __init__(self) -> None:@@ -36,3 +43,37 @@ class AuthenticationHelper:members.append(MemberData(user_id=user_id, email=email, name=name))return members++ def create_initial_platform_key(+ self, user: User, organization: Organization+ ) -> None:+ """Create an initial platform key for the given user and organization.++ This method generates a new platform key with the specified parameters+ and saves it to the database. The generated key is set as active and+ assigned the name "Key #1". The key is associated with the provided+ user and organization.++ Parameters:+ user (User): The user for whom the platform key is being created.+ organization (Organization):+ The organization to which the platform key belongs.++ Raises:+ Exception: If an error occurs while generating the platform key.++ Returns:+ None+ """+ try:+ PlatformAuthenticationService.generate_platform_key(+ is_active=True,+ key_name="Key #1",+ user=user,+ organization=organization,+ )+ except Exception:+ logger.error(+ "Failed to create default platform key for "+ f"organization {organization.organization_id}"+ )diff --git a/backend/middleware/remove_allow_header.py b/backend/middleware/remove_allow_header.pyindex ffdc7d589..ccd8bcb9e 100644--- a/backend/middleware/remove_allow_header.py+++ b/backend/middleware/remove_allow_header.py@@ -1,7 +1,10 @@+from django.http import HttpRequest, HttpResponsefrom django.utils.deprecation import MiddlewareMixinclass RemoveAllowHeaderMiddleware(MiddlewareMixin):- def process_response(self, request, response):- response.headers.pop('Allow', None)+ def process_response(+ self, request: HttpRequest, response: HttpResponse+ ) -> HttpResponse:+ response.headers.pop("Allow", None)return responsediff --git a/backend/platform_settings/platform_auth_service.py b/backend/platform_settings/platform_auth_service.pyindex 8ad74b20e..7258b982f 100644--- a/backend/platform_settings/platform_auth_service.py+++ b/backend/platform_settings/platform_auth_service.py@@ -23,21 +23,35 @@ class PlatformAuthenticationService:@staticmethoddef generate_platform_key(- is_active: bool, key_name: str, user: User+ is_active: bool,+ key_name: str,+ user: User,+ organization: Optional[Organization] = None,) -> dict[str, Any]:"""Method to support generation of new platform key. Throws error whenmaximum count is exceeded. Forbids for user other than adminpermission.Args:- key (str): Value of the key+ key_name (str): Value of the keyis_active (bool): By default the key is False- organization_id (str): Org the key belongs to.+ user (User): User object representing the user generating the key+ organization (Optional[Organization], optional):+ Org the key belongs to. Defaults to None.Returns:- PlatformKey+ dict[str, Any]:+ A dictionary containing the generated platform key details,+ including the id, key name, and key value.+ Raises:+ DuplicateData: If a platform key with the same key name+ already exists for the organization.+ InternalServiceError: If an internal error occurs while+ generating the platform key."""- organization = connection.get_tenant()+ organization = organization or connection.tenant+ if not organization:+ raise InternalServiceError("No valid organization provided")try:# TODO : Add encryption to Platform keys# id is added here to avoid passing of keys in transactions.