Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ introduce folder full search #6703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/specs/web-server/_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ async def list_folders(
...


@router.get(
"/folders:search",
response_model=Envelope[list[FolderGet]],
)
async def list_folders_full_search(
params: Annotated[PageQueryParameters, Depends()],
order_by: Annotated[
Json,
Query(
description="Order by field (modified_at|name|description) and direction (asc|desc). The default sorting order is ascending.",
example='{"field": "name", "direction": "desc"}',
),
] = '{"field": "modified_at", "direction": "desc"}',
filters: Annotated[
Json | None,
Query(description=FolderFilters.schema_json(indent=1)),
] = None,
):
...


@router.get(
"/folders/{folder_id}",
response_model=Envelope[FolderGet],
Expand Down
8 changes: 8 additions & 0 deletions packages/models-library/src/models_library/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pydantic import BaseModel, Field, PositiveInt, validator

from .access_rights import AccessRights
from .users import GroupID, UserID
from .utils.enums import StrAutoEnum
from .workspaces import WorkspaceID
Expand Down Expand Up @@ -66,3 +67,10 @@ class FolderDB(BaseModel):

class Config:
orm_mode = True


class UserFolderAccessRightsDB(FolderDB):
my_access_rights: AccessRights

class Config:
orm_mode = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def assemble_array_groups(user_group_ids: list[int]) -> str:
return (
"array[]::text[]"
if len(user_group_ids) == 0
else f"""array[{', '.join(f"'{group_id}'" for group_id in user_group_ids)}]"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from simcore_postgres_database.models.groups import user_to_groups
from simcore_postgres_database.models.workspaces_access_rights import (
workspaces_access_rights,
)
from sqlalchemy import func
from sqlalchemy.dialects.postgresql import BOOLEAN, INTEGER
from sqlalchemy.sql import Subquery, select


def create_my_workspace_access_rights_subquery(user_id: int) -> Subquery:
return (
select(
workspaces_access_rights.c.workspace_id,
func.json_build_object(
"read",
func.max(workspaces_access_rights.c.read.cast(INTEGER)).cast(BOOLEAN),
"write",
func.max(workspaces_access_rights.c.write.cast(INTEGER)).cast(BOOLEAN),
"delete",
func.max(workspaces_access_rights.c.delete.cast(INTEGER)).cast(BOOLEAN),
).label("my_access_rights"),
)
.select_from(
workspaces_access_rights.join(
user_to_groups, user_to_groups.c.gid == workspaces_access_rights.c.gid
)
)
.where(user_to_groups.c.uid == user_id)
.group_by(workspaces_access_rights.c.workspace_id)
).subquery("my_workspace_access_rights_subquery")
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
workspaces_access_rights,
)
from simcore_postgres_database.storage_models import file_meta_data, user_to_groups
from simcore_postgres_database.utils_sql import assemble_array_groups

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -117,14 +118,6 @@ def _aggregate_access_rights(
return AccessRights.none()


def assemble_array_groups(user_group_ids: list[GroupID]) -> str:
return (
"array[]::text[]"
if len(user_group_ids) == 0
else f"""array[{', '.join(f"'{group_id}'" for group_id in user_group_ids)}]"""
)


access_rights_subquery = (
sa.select(
project_to_groups.c.project_uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,70 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Envelope_FolderGet_'
/v0/folders:search:
get:
tags:
- folders
summary: List Folders Full Search
operationId: list_folders_full_search
parameters:
- description: Order by field (modified_at|name|description) and direction (asc|desc).
The default sorting order is ascending.
required: false
schema:
title: Order By
description: Order by field (modified_at|name|description) and direction
(asc|desc). The default sorting order is ascending.
default: '{"field": "modified_at", "direction": "desc"}'
example: '{"field": "name", "direction": "desc"}'
name: order_by
in: query
- description: "{\n \"title\": \"FolderFilters\",\n \"description\": \"Encoded\
\ as JSON. Each available filter can have its own logic (should be well\
\ documented)\\nInspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList.\"\
,\n \"type\": \"object\",\n \"properties\": {\n \"trashed\": {\n \"title\"\
: \"Trashed\",\n \"description\": \"Set to true to list trashed, false\
\ to list non-trashed (default), None to list all\",\n \"default\": false,\n\
\ \"type\": \"boolean\"\n }\n }\n}"
required: false
schema:
title: Filters
type: string
description: "{\n \"title\": \"FolderFilters\",\n \"description\": \"Encoded\
\ as JSON. Each available filter can have its own logic (should be well\
\ documented)\\nInspired by Docker API https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerList.\"\
,\n \"type\": \"object\",\n \"properties\": {\n \"trashed\": {\n \"\
title\": \"Trashed\",\n \"description\": \"Set to true to list trashed,\
\ false to list non-trashed (default), None to list all\",\n \"default\"\
: false,\n \"type\": \"boolean\"\n }\n }\n}"
format: json-string
name: filters
in: query
- required: false
schema:
title: Limit
exclusiveMaximum: true
minimum: 1
type: integer
default: 20
maximum: 50
name: limit
in: query
- required: false
schema:
title: Offset
minimum: 0
type: integer
default: 0
name: offset
in: query
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/Envelope_list_models_library.api_schemas_webserver.folders_v2.FolderGet__'
/v0/folders/{folder_id}:
get:
tags:
Expand Down
Loading
Loading