Skip to content

Commit a50321d

Browse files
πŸ› Relax Wallet Access Check for Project Upgrades 🚨 (#7917)
1 parent 1a1b0b2 commit a50321d

File tree

6 files changed

+54
-11
lines changed

6 files changed

+54
-11
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/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)