LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
fixes for user role change and Api key permission (#779)
alie4459633475c
diff --git a/backend/account_v2/authentication_controller.py b/backend/account_v2/authentication_controller.pyindex 4cdac81b7..e7b7b7ddc 100644--- a/backend/account_v2/authentication_controller.py+++ b/backend/account_v2/authentication_controller.py@@ -408,7 +408,7 @@ class AuthenticationController:)if current_roles:self.save_organization_user_role(- user_uid=user.user.user.id, role=current_roles[0]+ user_uid=user.user.id, role=current_roles[0])return current_roles[0]else:diff --git a/backend/api_v2/api_key_views.py b/backend/api_v2/api_key_views.pyindex 35236ca29..a4f70d932 100644--- a/backend/api_v2/api_key_views.py+++ b/backend/api_v2/api_key_views.py@@ -4,8 +4,8 @@ from api_v2.deployment_helper import DeploymentHelperfrom api_v2.exceptions import APINotFound, PathVariablesNotFoundfrom api_v2.key_helper import KeyHelperfrom api_v2.models import APIKey+from api_v2.permission import IsOwnerOrOrganizationMemberfrom api_v2.serializers import APIKeyListSerializer, APIKeySerializer-from permissions.permission import IsOwnerfrom pipeline_v2.exceptions import PipelineNotFoundfrom pipeline_v2.pipeline_processor import PipelineProcessorfrom rest_framework import serializers, viewsets@@ -16,7 +16,7 @@ from rest_framework.response import Responseclass APIKeyViewSet(viewsets.ModelViewSet):queryset = APIKey.objects.all()- permission_classes = [IsOwner]+ permission_classes = [IsOwnerOrOrganizationMember]def get_serializer_class(self) -> serializers.Serializer:if self.action in ["api_keys"]:diff --git a/backend/api_v2/permission.py b/backend/api_v2/permission.pynew file mode 100644index 000000000..691f8946b--- /dev/null+++ b/backend/api_v2/permission.py@@ -0,0 +1,28 @@+from permissions.permission import IsOwner+from utils.user_context import UserContext+++class IsOwnerOrOrganizationMember(IsOwner):+ """Permission that grants access if the user is the owner or belongs to the+ same organization."""++ def has_object_permission(self, request, view, obj):+ # Check if the user is the owner via base class logic+ if super().has_object_permission(request, view, obj):+ return True++ # If the object has a 'created_by' field, but the user isn't the owner,+ # deny access+ if obj.created_by:+ return False++ # Support legacy API keys where 'created_by' is None by matching the+ # organization ID. This allows organization members to access API keys as per+ # the existing behavior.+ user_organization = UserContext.get_organization()+ # Check organization ID for associated `api` or `pipeline`+ related_obj = getattr(obj, "api", None) or getattr(obj, "pipeline", None)+ if related_obj and related_obj.organization_id == user_organization.id:+ return True++ return False