Skip to content

Commit f92a9fd

Browse files
author
Andrei Neagu
committed
unify functions
1 parent 69901dd commit f92a9fd

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_projects_extensions.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def allows_guests_to_push_states_and_output_ports(
2525
return result if result is not None else False
2626

2727
@classmethod
28-
async def set_allow_guests_to_push_states_and_output_ports(
28+
async def _set_allow_guests_to_push_states_and_output_ports(
2929
cls, async_engine: AsyncEngine, *, project_uuid: str
3030
) -> None:
3131
async with transaction_context(async_engine) as connection:
@@ -35,3 +35,22 @@ async def set_allow_guests_to_push_states_and_output_ports(
3535
allow_guests_to_push_states_and_output_ports=True,
3636
)
3737
)
38+
39+
@classmethod
40+
async def copy_allow_guests_to_push_states_and_output_ports(
41+
cls,
42+
async_engine: AsyncEngine,
43+
*,
44+
from_project_uuid: str,
45+
to_project_uuid: str,
46+
) -> None:
47+
# get setting from template project
48+
allow_guests = await cls.allows_guests_to_push_states_and_output_ports(
49+
async_engine, project_uuid=from_project_uuid
50+
)
51+
52+
# set same setting in new project if True
53+
if allow_guests:
54+
await cls._set_allow_guests_to_push_states_and_output_ports(
55+
async_engine, project_uuid=to_project_uuid
56+
)

packages/postgres-database/tests/test_utils_projects_extensions.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=protected-access
12
# pylint: disable=redefined-outer-name
23

34
from collections.abc import Awaitable, Callable
@@ -25,35 +26,50 @@ async def fake_project(
2526
create_fake_project: Callable[..., Awaitable[RowProxy]],
2627
create_fake_nodes: Callable[..., Awaitable[RowProxy]],
2728
) -> RowProxy:
28-
project: RowProxy = await create_fake_project(connection, fake_user, hidden=True)
29+
project: RowProxy = await create_fake_project(connection, fake_user)
2930
await create_fake_nodes(project)
3031
return project
3132

3233

34+
async def _assert_allows_to_psuh(
35+
asyncpg_engine: AsyncEngine, project_uuid: str, *, expected: bool
36+
) -> None:
37+
result = await ProjectsExtensionsRepo.allows_guests_to_push_states_and_output_ports(
38+
asyncpg_engine, project_uuid=project_uuid
39+
)
40+
assert result is expected
41+
42+
3343
async def test_workflow(
3444
asyncpg_engine: AsyncEngine,
3545
connection: SAConnection,
3646
create_fake_user: Callable[..., Awaitable[RowProxy]],
3747
create_fake_project: Callable[..., Awaitable[RowProxy]],
3848
):
3949
user: RowProxy = await create_fake_user(connection)
40-
project: RowProxy = await create_fake_project(connection, user, hidden=True)
50+
project: RowProxy = await create_fake_project(connection, user)
4151

42-
assert (
43-
await ProjectsExtensionsRepo.allows_guests_to_push_states_and_output_ports(
44-
asyncpg_engine, project_uuid=project["uuid"]
45-
)
46-
is False
47-
)
52+
await _assert_allows_to_psuh(asyncpg_engine, project["uuid"], expected=False)
4853

4954
# add the entry in the table
50-
await ProjectsExtensionsRepo.set_allow_guests_to_push_states_and_output_ports(
55+
await ProjectsExtensionsRepo._set_allow_guests_to_push_states_and_output_ports(
5156
asyncpg_engine, project_uuid=project["uuid"]
5257
)
5358

59+
await _assert_allows_to_psuh(asyncpg_engine, project["uuid"], expected=True)
60+
61+
copy_project: RowProxy = await create_fake_project(connection, user)
62+
5463
assert (
5564
await ProjectsExtensionsRepo.allows_guests_to_push_states_and_output_ports(
56-
asyncpg_engine, project_uuid=project["uuid"]
65+
asyncpg_engine, project_uuid=copy_project["uuid"]
5766
)
58-
is True
67+
is False
68+
)
69+
await _assert_allows_to_psuh(asyncpg_engine, copy_project["uuid"], expected=False)
70+
await ProjectsExtensionsRepo.copy_allow_guests_to_push_states_and_output_ports(
71+
asyncpg_engine,
72+
from_project_uuid=project["uuid"],
73+
to_project_uuid=copy_project["uuid"],
5974
)
75+
await _assert_allows_to_psuh(asyncpg_engine, copy_project["uuid"], expected=True)

services/web/server/src/simcore_service_webserver/studies_dispatcher/_studies_access.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,11 @@ async def copy_study_to_account(
223223
request.app, project_id=ProjectID(project["uuid"])
224224
)
225225

226-
# set the same option in the new project from the template
227-
if await ProjectsExtensionsRepo.allows_guests_to_push_states_and_output_ports(
228-
get_asyncpg_engine(request.app), project_uuid=template_project["uuid"]
229-
):
230-
await ProjectsExtensionsRepo.set_allow_guests_to_push_states_and_output_ports(
231-
get_asyncpg_engine(request.app), project_uuid=project["uuid"]
232-
)
226+
await ProjectsExtensionsRepo.copy_allow_guests_to_push_states_and_output_ports(
227+
get_asyncpg_engine(request.app),
228+
from_project_uuid=template_project["uuid"],
229+
to_project_uuid=project["uuid"],
230+
)
233231

234232
return project_uuid
235233

0 commit comments

Comments
 (0)