Skip to content

Commit a4b7c7a

Browse files
🐛 Fix listing folders in workspace (#6718)
Co-authored-by: Odei Maiz <[email protected]>
1 parent e6e2c70 commit a4b7c7a

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

services/web/server/src/simcore_service_webserver/folders/_folders_db.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
178178
& (folders_v2.c.user_id.is_(None))
179179
)
180180
)
181+
182+
if workspace_query.workspace_scope == WorkspaceScope.SHARED:
183+
shared_workspace_query = shared_workspace_query.where(
184+
folders_v2.c.workspace_id == workspace_query.workspace_id
185+
)
186+
181187
else:
182188
shared_workspace_query = None
183189

services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,98 @@ async def test_workspaces_delete_folders(
365365
resp = await client.get(url)
366366
data, _ = await assert_status(resp, status.HTTP_200_OK)
367367
assert len(data) == 0
368+
369+
370+
@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)])
371+
async def test_listing_folders_and_projects_in_workspace__multiple_workspaces_created(
372+
client: TestClient,
373+
logged_user: UserInfoDict,
374+
user_project: ProjectDict,
375+
expected: HTTPStatus,
376+
mock_catalog_api_get_services_for_user_in_product: MockerFixture,
377+
fake_project: ProjectDict,
378+
workspaces_clean_db: None,
379+
):
380+
assert client.app
381+
382+
# create a new workspace
383+
url = client.app.router["create_workspace"].url_for()
384+
resp = await client.post(
385+
url.path,
386+
json={
387+
"name": "My first workspace",
388+
"description": "Custom description",
389+
"thumbnail": None,
390+
},
391+
)
392+
added_workspace_1, _ = await assert_status(resp, status.HTTP_201_CREATED)
393+
394+
# Create project in workspace
395+
project_data = deepcopy(fake_project)
396+
project_data["workspace_id"] = f"{added_workspace_1['workspaceId']}"
397+
project = await create_project(
398+
client.app,
399+
project_data,
400+
user_id=logged_user["id"],
401+
product_name="osparc",
402+
)
403+
404+
# Create folder in workspace
405+
url = client.app.router["create_folder"].url_for()
406+
resp = await client.post(
407+
url.path,
408+
json={
409+
"name": "Original user folder",
410+
"workspaceId": f"{added_workspace_1['workspaceId']}",
411+
},
412+
)
413+
first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED)
414+
415+
# create a new workspace
416+
url = client.app.router["create_workspace"].url_for()
417+
resp = await client.post(
418+
url.path,
419+
json={
420+
"name": "My first workspace",
421+
"description": "Custom description",
422+
"thumbnail": None,
423+
},
424+
)
425+
added_workspace_2, _ = await assert_status(resp, status.HTTP_201_CREATED)
426+
427+
# Create project in workspace
428+
project_data = deepcopy(fake_project)
429+
project_data["workspace_id"] = f"{added_workspace_2['workspaceId']}"
430+
project = await create_project(
431+
client.app,
432+
project_data,
433+
user_id=logged_user["id"],
434+
product_name="osparc",
435+
)
436+
437+
# Create folder in workspace
438+
url = client.app.router["create_folder"].url_for()
439+
resp = await client.post(
440+
url.path,
441+
json={
442+
"name": "Original user folder",
443+
"workspaceId": f"{added_workspace_2['workspaceId']}",
444+
},
445+
)
446+
first_folder, _ = await assert_status(resp, status.HTTP_201_CREATED)
447+
448+
# List projects in workspace 1
449+
base_url = client.app.router["list_projects"].url_for()
450+
url = base_url.with_query({"workspace_id": f"{added_workspace_1['workspaceId']}"})
451+
resp = await client.get(url)
452+
data, _ = await assert_status(resp, status.HTTP_200_OK)
453+
assert len(data) == 1
454+
455+
# List folders in workspace 1
456+
base_url = client.app.router["list_folders"].url_for()
457+
url = base_url.with_query(
458+
{"workspace_id": f"{added_workspace_1['workspaceId']}", "folder_id": "null"}
459+
)
460+
resp = await client.get(url)
461+
data, _ = await assert_status(resp, status.HTTP_200_OK)
462+
assert len(data) == 1

0 commit comments

Comments
 (0)