|
|
@ -10,6 +10,7 @@ from asgiref.sync import sync_to_async
|
|
|
|
from django_etebase.models import Collection, Stoken, AccessLevels, CollectionMember
|
|
|
|
from django_etebase.models import Collection, Stoken, AccessLevels, CollectionMember
|
|
|
|
from .authentication import get_authenticated_user
|
|
|
|
from .authentication import get_authenticated_user
|
|
|
|
from .msgpack import MsgpackRoute, MsgpackResponse
|
|
|
|
from .msgpack import MsgpackRoute, MsgpackResponse
|
|
|
|
|
|
|
|
from .stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_queryset_stoken
|
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
User = get_user_model()
|
|
|
|
collection_router = APIRouter(route_class=MsgpackRoute)
|
|
|
|
collection_router = APIRouter(route_class=MsgpackRoute)
|
|
|
@ -51,9 +52,11 @@ class ListResponse(BaseModel):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sync_to_async
|
|
|
|
@sync_to_async
|
|
|
|
def list_common(queryset: QuerySet, stoken: t.Optional[str], user: User) -> MsgpackResponse:
|
|
|
|
def list_common(queryset: QuerySet, user: User, stoken: t.Optional[str], limit: int) -> MsgpackResponse:
|
|
|
|
|
|
|
|
result, new_stoken_obj, done = filter_by_stoken_and_limit(stoken, limit, queryset, Collection.stoken_annotation)
|
|
|
|
|
|
|
|
new_stoken = new_stoken_obj and new_stoken_obj.uid
|
|
|
|
data: t.List[CollectionOut] = [CollectionOut.from_orm_user(item, user) for item in queryset]
|
|
|
|
data: t.List[CollectionOut] = [CollectionOut.from_orm_user(item, user) for item in queryset]
|
|
|
|
ret = ListResponse(data=data, stoken=stoken, done=True)
|
|
|
|
ret = ListResponse(data=data, stoken=new_stoken, done=done)
|
|
|
|
return MsgpackResponse(content=ret)
|
|
|
|
return MsgpackResponse(content=ret)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -62,11 +65,13 @@ def get_collection_queryset(user: User, queryset: QuerySet) -> QuerySet:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@collection_router.post("/list_multi/")
|
|
|
|
@collection_router.post("/list_multi/")
|
|
|
|
async def list_multi(limit: int, data: ListMulti, user: User = Depends(get_authenticated_user)):
|
|
|
|
async def list_multi(
|
|
|
|
|
|
|
|
data: ListMulti, stoken: t.Optional[str] = None, limit: int = 50, user: User = Depends(get_authenticated_user)
|
|
|
|
|
|
|
|
):
|
|
|
|
queryset = get_collection_queryset(user, default_queryset)
|
|
|
|
queryset = get_collection_queryset(user, default_queryset)
|
|
|
|
# FIXME: Remove the isnull part once we attach collection types to all objects ("collection-type-migration")
|
|
|
|
# FIXME: Remove the isnull part once we attach collection types to all objects ("collection-type-migration")
|
|
|
|
queryset = queryset.filter(
|
|
|
|
queryset = queryset.filter(
|
|
|
|
Q(members__collectionType__uid__in=data.collectionTypes) | Q(members__collectionType__isnull=True)
|
|
|
|
Q(members__collectionType__uid__in=data.collectionTypes) | Q(members__collectionType__isnull=True)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
response = await list_common(queryset, None, user)
|
|
|
|
response = await list_common(queryset, user, stoken, limit)
|
|
|
|
return response
|
|
|
|
return response
|
|
|
|