🐛 fix(store.py): rename create_component function to share_component for better semantics

✨ feat(store.py): add support for private query parameter in get_components function to filter components by privacy
🐛 fix(schema.py): set default value of private field in StoreComponentCreate schema to True
🐛 fix(service.py): change status field to private field in build_filter_conditions and get_list_component_response_model functions to filter components by privacy
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-20 19:49:11 -03:00
commit 3432a07285
3 changed files with 20 additions and 23 deletions

View file

@ -69,7 +69,7 @@ async def check_if_store_has_api_key(
@router.post("/components/", response_model=CreateComponentResponse, status_code=201) @router.post("/components/", response_model=CreateComponentResponse, status_code=201)
async def create_component( async def share_component(
component: StoreComponentCreate, component: StoreComponentCreate,
store_service: StoreService = Depends(get_store_service), store_service: StoreService = Depends(get_store_service),
store_api_Key: str = Depends(get_user_store_api_key), store_api_Key: str = Depends(get_user_store_api_key),
@ -105,7 +105,7 @@ async def create_component(
@router.get("/components/", response_model=ListComponentResponseModel) @router.get("/components/", response_model=ListComponentResponseModel)
async def get_components( async def get_components(
search: Annotated[Optional[str], Query()] = None, search: Annotated[Optional[str], Query()] = None,
status: Annotated[Optional[str], Query()] = None, private: Annotated[Optional[bool], Query()] = None,
is_component: Annotated[Optional[bool], Query()] = None, is_component: Annotated[Optional[bool], Query()] = None,
tags: Annotated[Optional[list[str]], Query()] = None, tags: Annotated[Optional[list[str]], Query()] = None,
sort: Annotated[Union[list[str], None], Query()] = None, sort: Annotated[Union[list[str], None], Query()] = None,
@ -119,7 +119,7 @@ async def get_components(
try: try:
return await store_service.get_list_component_response_model( return await store_service.get_list_component_response_model(
search=search, search=search,
status=status, private=private,
is_component=is_component, is_component=is_component,
tags=tags, tags=tags,
sort=sort, sort=sort,

View file

@ -71,4 +71,4 @@ class StoreComponentCreate(BaseModel):
parent: Optional[UUID] = None parent: Optional[UUID] = None
is_component: Optional[bool] is_component: Optional[bool]
last_tested_version: Optional[str] = None last_tested_version: Optional[str] = None
public: Optional[bool] = False private: Optional[bool] = True

View file

@ -5,19 +5,16 @@ from uuid import UUID
import httpx import httpx
from httpx import HTTPError, HTTPStatusError from httpx import HTTPError, HTTPStatusError
from langflow.services.base import Service from langflow.services.base import Service
from langflow.services.store.exceptions import APIKeyError, FilterError, ForbiddenError from langflow.services.store.exceptions import (APIKeyError, FilterError,
from langflow.services.store.schema import ( ForbiddenError)
CreateComponentResponse, from langflow.services.store.schema import (CreateComponentResponse,
DownloadComponentResponse, DownloadComponentResponse,
ListComponentResponse, ListComponentResponse,
ListComponentResponseModel, ListComponentResponseModel,
StoreComponentCreate, StoreComponentCreate)
) from langflow.services.store.utils import (process_component_data,
from langflow.services.store.utils import ( process_tags_for_post,
process_component_data, update_components_with_user_data)
process_tags_for_post,
update_components_with_user_data,
)
from loguru import logger from loguru import logger
if TYPE_CHECKING: if TYPE_CHECKING:
@ -170,7 +167,7 @@ class StoreService(Service):
def build_filter_conditions( def build_filter_conditions(
self, self,
search: Optional[str] = None, search: Optional[str] = None,
status: Optional[str] = None, private: Optional[bool] = None,
tags: Optional[List[str]] = None, tags: Optional[List[str]] = None,
is_component: Optional[bool] = None, is_component: Optional[bool] = None,
filter_by_user: Optional[bool] = False, filter_by_user: Optional[bool] = False,
@ -183,8 +180,8 @@ class StoreService(Service):
search_conditions = self.build_search_filter_conditions(search) search_conditions = self.build_search_filter_conditions(search)
filter_conditions.append(search_conditions) filter_conditions.append(search_conditions)
if status is not None: if private is not None:
filter_conditions.append({"status": {"_eq": status}}) filter_conditions.append({"private": {"_eq": private}})
if tags: if tags:
tags_filter = self.build_tags_filter(tags) tags_filter = self.build_tags_filter(tags)
@ -206,7 +203,7 @@ class StoreService(Service):
elif filter_by_user and not store_api_Key: elif filter_by_user and not store_api_Key:
raise APIKeyError("You must provide an API key to filter your components") raise APIKeyError("You must provide an API key to filter your components")
else: else:
filter_conditions.append({"status": {"_in": ["public", "Public"]}}) filter_conditions.append({"private": {"_eq": False}})
return filter_conditions return filter_conditions
@ -411,7 +408,7 @@ class StoreService(Service):
async def get_list_component_response_model( async def get_list_component_response_model(
self, self,
search: Optional[str] = None, search: Optional[str] = None,
status: Optional[str] = None, private: Optional[bool] = None,
tags: Optional[List[str]] = None, tags: Optional[List[str]] = None,
is_component: Optional[bool] = None, is_component: Optional[bool] = None,
filter_by_user: bool = False, filter_by_user: bool = False,
@ -424,7 +421,7 @@ class StoreService(Service):
async with user_data_context(api_key=store_api_Key, store_service=self): async with user_data_context(api_key=store_api_Key, store_service=self):
filter_conditions: List[Dict[str, Any]] = self.build_filter_conditions( filter_conditions: List[Dict[str, Any]] = self.build_filter_conditions(
search=search, search=search,
status=status, private=private,
tags=tags, tags=tags,
is_component=is_component, is_component=is_component,
filter_by_user=filter_by_user, filter_by_user=filter_by_user,