LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Adapter permission fixes (#145)
Rahul Johny943807695e5e
diff --git a/backend/account/authentication_controller.py b/backend/account/authentication_controller.pyindex 629b992bf..197e82f88 100644--- a/backend/account/authentication_controller.py+++ b/backend/account/authentication_controller.py@@ -34,7 +34,6 @@ from account.serializer import (SetOrganizationsResponseSerializer,)from account.user import UserService-from utils.local_context import StateStorefrom django.conf import settingsfrom django.contrib.auth import login as django_loginfrom django.contrib.auth import logout as django_logout@@ -49,6 +48,7 @@ from rest_framework.response import Responsefrom tenant_account.models import OrganizationMember as OrganizationMemberfrom tenant_account.organization_member_service import OrganizationMemberServicefrom utils.cache_service import CacheService+from utils.local_context import StateStoreLogger = logging.getLogger(__name__)@@ -236,7 +236,9 @@ class AuthenticationController:data={"user": serialized_user_info,"organization": organization_info,- f"{Common.LOG_EVENTS_ID}": StateStore.get(Common.LOG_EVENTS_ID)+ f"{Common.LOG_EVENTS_ID}": StateStore.get(+ Common.LOG_EVENTS_ID+ ),},)# Update user session data in redis@@ -400,6 +402,9 @@ class AuthenticationController:is_removed = Falseif is_removed:OrganizationMember.objects.filter(user__in=ids_list).delete()+ # removing adapter relations on user removal+ for user_id in ids_list:+ User.objects.get(pk=user_id).shared_adapters.clear()return is_removeddef add_user_role(diff --git a/backend/prompt_studio/prompt_studio_core/exceptions.py b/backend/prompt_studio/prompt_studio_core/exceptions.pyindex 609dd567d..f7210f309 100644--- a/backend/prompt_studio/prompt_studio_core/exceptions.py+++ b/backend/prompt_studio/prompt_studio_core/exceptions.py@@ -54,3 +54,8 @@ class ToolDeleteError(APIException):class NoPromptsFound(APIException):status_code = 404default_detail = "No prompts available to process"+++class PermissionError(APIException):+ status_code = 403+ default_detail = "You do not have permission to perform this action."diff --git a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.pyindex f1ef785e9..0a16f6feb 100644--- a/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py+++ b/backend/prompt_studio/prompt_studio_core/prompt_studio_helper.py@@ -7,7 +7,6 @@ from typing import Any, Optionalfrom account.constants import Commonfrom adapter_processor.models import AdapterInstancefrom django.conf import settings-from django.core.exceptions import PermissionDeniedfrom file_management.file_management_helper import FileManagerHelperfrom prompt_studio.prompt_profile_manager.models import ProfileManagerfrom prompt_studio.prompt_studio.models import ToolStudioPrompt@@ -20,6 +19,7 @@ from prompt_studio.prompt_studio_core.exceptions import (DefaultProfileError,IndexingError,NoPromptsFound,+ PermissionError,PromptNotValid,ToolNotValid,)@@ -59,7 +59,7 @@ class PromptStudioHelper:validate.Raises:- PermissionDenied: If the owner does not have permission to perform+ PermissionError: If the owner does not have permission to performthe action."""profile_manager_owner = profile_manager.created_by@@ -95,34 +95,45 @@ class PromptStudioHelper:and is_embedding_model_ownedand is_x2text_owned):+ adapter_names = set()if not is_llm_owned:logger.error(ERROR_MSG,profile_manager_owner.user_id,profile_manager.llm.id,)+ adapter_names.add(profile_manager.llm.adapter_name)if not is_vector_store_owned:logger.error(ERROR_MSG,profile_manager_owner.user_id,profile_manager.vector_store.id,)+ adapter_names.add(profile_manager.vector_store.adapter_name)if not is_embedding_model_owned:logger.error(ERROR_MSG,profile_manager_owner.user_id,profile_manager.embedding_model.id,)+ adapter_names.add(profile_manager.embedding_model.adapter_name)if not is_x2text_owned:logger.error(ERROR_MSG,profile_manager_owner.user_id,profile_manager.x2text.id,)+ adapter_names.add(profile_manager.x2text.adapter_name)+ if len(adapter_names) > 1:+ error_msg = (+ f"Multiple permission errors were encountered with {', '.join(adapter_names)}", # noqa: E501+ )+ else:+ error_msg = (+ f"Permission Error: You do not have access to {adapter_names.pop()}", # noqa: E501+ )- raise PermissionDenied(- "You don't have permission to perform this action."- )+ raise PermissionError(error_msg)def _publish_log(component: dict[str, str], level: str, state: str, message: str@@ -329,7 +340,7 @@ class PromptStudioHelper:org_id=org_id,document_id=document_id,)- except PermissionDenied as e:+ except PermissionError as e:raise eexcept Exception as exc:logger.error(@@ -377,7 +388,7 @@ class PromptStudioHelper:org_id=org_id,document_id=document_id,)- except PermissionDenied as e:+ except PermissionError as e:raise eexcept Exception as e:logger.error(