Skip to content

Commit e25197f

Browse files
author
Andrei Neagu
committed
Merge remote-tracking branch 'upstream/master' into pr-osparc-fix-lrt-interface-again
2 parents 7ad32d9 + 0d75a45 commit e25197f

File tree

7 files changed

+85
-48
lines changed

7 files changed

+85
-48
lines changed

services/director-v2/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
"tags": [
6666
"computations"
6767
],
68-
"summary": "Create Computation",
68+
"summary": "Create Or Update Or Start Computation",
6969
"description": "Create and optionally start a new computation",
70-
"operationId": "create_computation_v2_computations_post",
70+
"operationId": "create_or_update_or_start_computation_v2_computations_post",
7171
"requestBody": {
7272
"content": {
7373
"application/json": {

services/director-v2/src/simcore_service_director_v2/api/routes/computations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ async def _try_start_pipeline(
268268
)
269269
# NOTE: in case of a burst of calls to that endpoint, we might end up in a weird state.
270270
@run_sequentially_in_context(target_args=["computation.project_id"])
271-
async def create_computation( # noqa: PLR0913 # pylint: disable=too-many-positional-arguments
271+
# NOTE: This endpoint is historically used for CREATE, UPDATE or START a computation!
272+
async def create_or_update_or_start_computation( # noqa: PLR0913 # pylint: disable=too-many-positional-arguments
272273
computation: ComputationCreate,
273274
request: Request,
274275
project_repo: Annotated[

services/web/server/src/simcore_service_webserver/director_v2/_director_v2_service.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async def create_or_update_pipeline(
6666
user_id=user_id,
6767
project_id=project_id,
6868
product_name=product_name,
69+
check_user_wallet_permission=False,
6970
),
7071
}
7172

@@ -203,6 +204,7 @@ async def get_wallet_info(
203204
user_id: UserID,
204205
project_id: ProjectID,
205206
product_name: ProductName,
207+
check_user_wallet_permission: bool = True,
206208
) -> WalletInfo | None:
207209
app_settings = get_application_settings(app)
208210
if not (
@@ -234,13 +236,24 @@ async def get_wallet_info(
234236
else:
235237
project_wallet_id = project_wallet.wallet_id
236238

237-
# Check whether user has access to the wallet
238-
wallet = await wallets_service.get_wallet_with_available_credits_by_user_and_wallet(
239-
app,
240-
user_id=user_id,
241-
wallet_id=project_wallet_id,
242-
product_name=product_name,
243-
)
239+
if check_user_wallet_permission:
240+
# Check whether user has access to the wallet
241+
wallet = (
242+
await wallets_service.get_wallet_with_available_credits_by_user_and_wallet(
243+
app,
244+
user_id=user_id,
245+
wallet_id=project_wallet_id,
246+
product_name=product_name,
247+
)
248+
)
249+
else:
250+
# This function is used also when we are synchronizing the projects/projects_nodes with the comp_pipelines/comp_tasks tables in director-v2
251+
# In situations where a project is connected to a wallet, but the user does not have access to it and is performing an action such as
252+
# upgrading the service version, we still want to retrieve the wallet info and pass it to director-v2.
253+
wallet = await wallets_service.get_wallet_with_available_credits(
254+
app, wallet_id=project_wallet_id, product_name=product_name
255+
)
256+
244257
return WalletInfo(
245258
wallet_id=project_wallet_id,
246259
wallet_name=wallet.name,

services/web/server/src/simcore_service_webserver/functions/_functions_repository.py

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,14 @@ async def delete_function(
627627
)
628628

629629

630-
async def update_function_title(
630+
async def _update_function_attribute(
631631
app: web.Application,
632-
connection: AsyncConnection | None = None,
632+
connection: AsyncConnection | None,
633633
*,
634634
user_id: UserID,
635635
product_name: ProductName,
636636
function_id: FunctionID,
637-
title: str,
637+
**update_kwargs,
638638
) -> RegisteredFunctionDB:
639639
async with transaction_context(get_asyncpg_engine(app), connection) as transaction:
640640
await check_user_api_access_rights(
@@ -661,7 +661,7 @@ async def update_function_title(
661661
result = await transaction.execute(
662662
functions_table.update()
663663
.where(functions_table.c.uuid == function_id)
664-
.values(title=title)
664+
.values(**update_kwargs)
665665
.returning(*_FUNCTIONS_TABLE_COLS)
666666
)
667667
row = result.one_or_none()
@@ -672,48 +672,42 @@ async def update_function_title(
672672
return RegisteredFunctionDB.model_validate(row)
673673

674674

675-
async def update_function_description(
675+
async def update_function_title(
676676
app: web.Application,
677677
connection: AsyncConnection | None = None,
678678
*,
679679
user_id: UserID,
680680
product_name: ProductName,
681681
function_id: FunctionID,
682-
description: str,
682+
title: str,
683683
) -> RegisteredFunctionDB:
684-
async with transaction_context(get_asyncpg_engine(app), connection) as transaction:
685-
await check_user_api_access_rights(
686-
app,
687-
connection=transaction,
688-
user_id=user_id,
689-
product_name=product_name,
690-
api_access_rights=[
691-
FunctionsApiAccessRights.READ_FUNCTIONS,
692-
FunctionsApiAccessRights.WRITE_FUNCTIONS,
693-
],
694-
)
695-
await check_user_permissions(
696-
app,
697-
transaction,
698-
user_id=user_id,
699-
product_name=product_name,
700-
object_id=function_id,
701-
object_type="function",
702-
permissions=["write"],
703-
)
704-
705-
result = await transaction.execute(
706-
functions_table.update()
707-
.where(functions_table.c.uuid == function_id)
708-
.values(description=description)
709-
.returning(*_FUNCTIONS_TABLE_COLS)
710-
)
711-
row = result.one_or_none()
684+
return await _update_function_attribute(
685+
app,
686+
connection=connection,
687+
user_id=user_id,
688+
product_name=product_name,
689+
function_id=function_id,
690+
title=title,
691+
)
712692

713-
if row is None:
714-
raise FunctionIDNotFoundError(function_id=function_id)
715693

716-
return RegisteredFunctionDB.model_validate(row)
694+
async def update_function_description(
695+
app: web.Application,
696+
connection: AsyncConnection | None = None,
697+
*,
698+
user_id: UserID,
699+
product_name: ProductName,
700+
function_id: FunctionID,
701+
description: str,
702+
) -> RegisteredFunctionDB:
703+
return await _update_function_attribute(
704+
app,
705+
connection=connection,
706+
user_id=user_id,
707+
product_name=product_name,
708+
function_id=function_id,
709+
description=description,
710+
)
717711

718712

719713
async def get_function_job(

services/web/server/src/simcore_service_webserver/projects/_projects_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ async def patch_project_node(
11531153
partial_node=partial_node,
11541154
)
11551155

1156-
# 4. Make calls to director-v2 to keep data in sync (ex. comp_tasks DB table)
1156+
# 4. Make calls to director-v2 to keep data in sync (ex. comp_* DB tables)
11571157
await director_v2_service.create_or_update_pipeline(
11581158
app,
11591159
user_id,

services/web/server/src/simcore_service_webserver/wallets/_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ async def get_wallet_with_available_credits_by_user_and_wallet(
108108
)
109109

110110

111+
async def get_wallet_with_available_credits(
112+
app: web.Application,
113+
*,
114+
wallet_id: WalletID,
115+
product_name: ProductName,
116+
) -> WalletGetWithAvailableCredits:
117+
wallet_db: WalletDB = await db.get_wallet(
118+
app=app, wallet_id=wallet_id, product_name=product_name
119+
)
120+
121+
available_credits: WalletTotalCredits = await get_wallet_total_available_credits(
122+
app, product_name, wallet_db.wallet_id
123+
)
124+
125+
return WalletGetWithAvailableCredits(
126+
wallet_id=wallet_db.wallet_id,
127+
name=IDStr(wallet_db.name),
128+
description=wallet_db.description,
129+
owner=wallet_db.owner,
130+
thumbnail=wallet_db.thumbnail,
131+
status=wallet_db.status,
132+
created=wallet_db.created,
133+
modified=wallet_db.modified,
134+
available_credits=available_credits.available_osparc_credits,
135+
)
136+
137+
111138
async def get_user_default_wallet_with_available_credits(
112139
app: web.Application,
113140
*,

services/web/server/src/simcore_service_webserver/wallets/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ._api import (
22
get_wallet_by_user,
3+
get_wallet_with_available_credits,
34
get_wallet_with_available_credits_by_user_and_wallet,
45
get_wallet_with_permissions_by_user,
56
list_wallets_for_user,
@@ -8,6 +9,7 @@
89

910
__all__: tuple[str, ...] = (
1011
"get_wallet_by_user",
12+
"get_wallet_with_available_credits",
1113
"get_wallet_with_permissions_by_user",
1214
"get_wallet_with_available_credits_by_user_and_wallet",
1315
"list_wallets_for_user",

0 commit comments

Comments
 (0)