Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Adapter permission fixes (#145)

Rahul Johny943807695e5e
diff --git a/backend/account/authentication_controller.py b/backend/account/authentication_controller.py
index 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 StateStore
from django.conf import settings
from django.contrib.auth import login as django_login
from django.contrib.auth import logout as django_logout
@@ -49,6 +48,7 @@ from rest_framework.response import Response
from tenant_account.models import OrganizationMember as OrganizationMember
from tenant_account.organization_member_service import OrganizationMemberService
from utils.cache_service import CacheService
+from utils.local_context import StateStore
Logger = 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 = False
if 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_removed
def add_user_role(
diff --git a/backend/prompt_studio/prompt_studio_core/exceptions.py b/backend/prompt_studio/prompt_studio_core/exceptions.py
index 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 = 404
default_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.py
index 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, Optional
from account.constants import Common
from adapter_processor.models import AdapterInstance
from django.conf import settings
-from django.core.exceptions import PermissionDenied
from file_management.file_management_helper import FileManagerHelper
from prompt_studio.prompt_profile_manager.models import ProfileManager
from 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 perform
the action.
"""
profile_manager_owner = profile_manager.created_by
@@ -95,34 +95,45 @@ class PromptStudioHelper:
and is_embedding_model_owned
and 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 e
except 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 e
except Exception as e:
logger.error(