🔧 fix(store.py): add filter_by_user query parameter to read_component endpoint to allow filtering components by user

🔧 fix(service.py): modify download method in StoreService to include filter_by_user parameter in API request to filter components by user
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-24 18:51:30 -03:00
commit dde22bd35f
2 changed files with 14 additions and 2 deletions

View file

@ -73,6 +73,7 @@ def list_components(
@router.get("/components/{component_id}", response_model=DownloadComponentResponse)
def read_component(
component_id: UUID,
filter_by_user: bool = Query(False),
store_service: StoreService = Depends(get_store_service),
store_api_Key: str = Depends(get_user_store_api_key),
settings_service=Depends(get_settings_service),
@ -81,7 +82,7 @@ def read_component(
try:
decrypted = auth_utils.decrypt_api_key(store_api_Key, settings_service)
component = store_service.download(decrypted, component_id)
component = store_service.download(decrypted, component_id, filter_by_user)
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc

View file

@ -1,4 +1,5 @@
from datetime import datetime
import json
from uuid import UUID
from langflow.services.base import Service
from typing import TYPE_CHECKING, List, Dict, Any, Optional
@ -124,11 +125,21 @@ class StoreService(Service):
results = self._get(self.components_url, api_key, params)
return [ListComponentResponse(**component) for component in results]
def download(self, api_key: str, component_id: str) -> DownloadComponentResponse:
def download(
self, api_key: str, component_id: str, filter_by_user: bool
) -> DownloadComponentResponse:
url = f"{self.components_url}/{component_id}"
params = {
"fields": ",".join(["id", "name", "description", "data", "is_component"])
}
if filter_by_user:
params["deep"] = json.dumps(
{
"components": {
"_filter": {"user_created": {"token": {"_eq": api_key}}}
}
}
)
component = self._get(url, api_key, params)
self.call_webhook(api_key, self.webhook_url, component_id)