Skip to content

Commit

Permalink
[Fix] Show No Op adapters in UI only for zipstack and unstract domain…
Browse files Browse the repository at this point in the history
… emails (#1046)

* added fix to filter noOp adapters for common users

* added enum for allowed domains

---------

Co-authored-by: Gayathri <[email protected]>
  • Loading branch information
jagadeeswaran-zipstack and gaya3-zipstack authored Jan 6, 2025
1 parent eff8f54 commit 55b3028
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions backend/adapter_processor_v2/adapter_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Optional

from account_v2.models import User
from adapter_processor_v2.constants import AdapterKeys
from adapter_processor_v2.constants import AdapterKeys, AllowedDomains
from adapter_processor_v2.exceptions import (
InternalServiceError,
InValidAdapterId,
Expand Down Expand Up @@ -44,17 +44,25 @@ def get_json_schema(adapter_id: str) -> dict[str, Any]:
return schema_details

@staticmethod
def get_all_supported_adapters(type: str) -> list[dict[Any, Any]]:
def get_all_supported_adapters(user_email: str, type: str) -> list[dict[Any, Any]]:
"""Function to return list of all supported adapters."""
supported_adapters = []
updated_adapters = []
updated_adapters = AdapterProcessor.__fetch_adapters_by_key_value(
AdapterKeys.ADAPTER_TYPE, type
)
is_special_user = any(
identifier in user_email for identifier in AllowedDomains.list()
)

for each_adapter in updated_adapters:
adapter_id = each_adapter.get(AdapterKeys.ID)
if not is_special_user and adapter_id.startswith("noOp"):
continue

supported_adapters.append(
{
AdapterKeys.ID: each_adapter.get(AdapterKeys.ID),
AdapterKeys.ID: adapter_id,
AdapterKeys.NAME: each_adapter.get(AdapterKeys.NAME),
AdapterKeys.DESCRIPTION: each_adapter.get(AdapterKeys.DESCRIPTION),
AdapterKeys.ICON: each_adapter.get(AdapterKeys.ICON),
Expand Down
12 changes: 12 additions & 0 deletions backend/adapter_processor_v2/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from enum import Enum


class AdapterKeys:
JSON_SCHEMA = "json_schema"
ADAPTER_TYPE = "adapter_type"
Expand Down Expand Up @@ -27,3 +30,12 @@ class AdapterKeys:
ADAPTER_NAME = "adapter_name"
ADAPTER_CREATED_BY = "created_by_email"
ADAPTER_CONTEXT_WINDOW_SIZE = "context_window_size"


class AllowedDomains(Enum):
ZIPSTACK = "@zipstack.com"
UNSTRACT = "@unstract.com"

@staticmethod
def list():
return list(map(lambda c: c.value, AllowedDomains))
2 changes: 1 addition & 1 deletion backend/adapter_processor_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def list(
or adapter_type == AdapterKeys.OCR
):
json_schema = AdapterProcessor.get_all_supported_adapters(
type=adapter_type
type=adapter_type, user_email=request.user.email
)
return Response(json_schema, status=status.HTTP_200_OK)
else:
Expand Down

0 comments on commit 55b3028

Please sign in to comment.