From 21a52238994733d7b23fbcd082e937501a676991 Mon Sep 17 00:00:00 2001 From: matusdrobuliak66 <60785969+matusdrobuliak66@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:47:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=F0=9F=97=83=EF=B8=8F=20adding=20produ?= =?UTF-8?q?ct=5Fname=20to=20the=20wallets=20api=20(#4780)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...093c21bb_adding_product_name_to_wallets.py | 34 ++++++++++++++++++ .../models/wallets.py | 1 + .../director_v2/_handlers.py | 2 +- .../payments/_api.py | 19 +++++++--- .../payments/_methods_api.py | 36 +++++++++++++++---- .../projects/_wallets_handlers.py | 5 ++- .../projects/projects_api.py | 2 +- .../resource_usage/_observer.py | 8 +++-- .../resource_usage/_service_runs_api.py | 2 +- .../simcore_service_webserver/wallets/_api.py | 22 ++++++++---- .../simcore_service_webserver/wallets/_db.py | 30 +++++++++++++--- .../wallets/_groups_api.py | 13 ++++--- .../wallets/_groups_handlers.py | 8 ++++- .../wallets/_handlers.py | 4 ++- .../wallets/_payments_handlers.py | 14 ++++++-- .../02/test_projects_wallet_handlers.py | 7 +++- .../test_usage_services__list.py | 7 +++- 17 files changed, 175 insertions(+), 39 deletions(-) create mode 100644 packages/postgres-database/src/simcore_postgres_database/migration/versions/61fa093c21bb_adding_product_name_to_wallets.py diff --git a/packages/postgres-database/src/simcore_postgres_database/migration/versions/61fa093c21bb_adding_product_name_to_wallets.py b/packages/postgres-database/src/simcore_postgres_database/migration/versions/61fa093c21bb_adding_product_name_to_wallets.py new file mode 100644 index 00000000000..71a130de3dc --- /dev/null +++ b/packages/postgres-database/src/simcore_postgres_database/migration/versions/61fa093c21bb_adding_product_name_to_wallets.py @@ -0,0 +1,34 @@ +"""adding product_name to wallets + +Revision ID: 61fa093c21bb +Revises: ae72826e75fc +Create Date: 2023-09-20 14:42:10.661569+00:00 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "61fa093c21bb" +down_revision = "ae72826e75fc" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column("wallets", sa.Column("product_name", sa.String(), nullable=True)) + op.execute( + sa.DDL("UPDATE wallets SET product_name = 'osparc' WHERE product_name IS NULL") + ) + op.alter_column( + "wallets", + "product_name", + existing_type=sa.String(), + nullable=False, + ) + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("wallets", "product_name") + # ### end Alembic commands ### diff --git a/packages/postgres-database/src/simcore_postgres_database/models/wallets.py b/packages/postgres-database/src/simcore_postgres_database/models/wallets.py index 0637f8cb289..e26545f1f4a 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/wallets.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/wallets.py @@ -50,6 +50,7 @@ class WalletStatus(str, enum.Enum): ), column_created_datetime(timezone=True), column_modified_datetime(timezone=True), + sa.Column("product_name", sa.String, nullable=False, doc="Product name"), ) # ------------------------ TRIGGERS diff --git a/services/web/server/src/simcore_service_webserver/director_v2/_handlers.py b/services/web/server/src/simcore_service_webserver/director_v2/_handlers.py index 8cf8f690823..19559feebf7 100644 --- a/services/web/server/src/simcore_service_webserver/director_v2/_handlers.py +++ b/services/web/server/src/simcore_service_webserver/director_v2/_handlers.py @@ -105,7 +105,7 @@ async def start_computation(request: web.Request) -> web.Response: if project_wallet and app_settings.WEBSERVER_DEV_FEATURES_ENABLED: # Check whether user has access to the wallet await wallets_api.get_wallet_by_user( - request.app, req_ctx.user_id, project_wallet.wallet_id + request.app, req_ctx.user_id, project_wallet.wallet_id, req_ctx.product_name ) wallet_info = WalletInfo( wallet_id=project_wallet.wallet_id, wallet_name=project_wallet.name diff --git a/services/web/server/src/simcore_service_webserver/payments/_api.py b/services/web/server/src/simcore_service_webserver/payments/_api.py index 1eaceb6b75b..2c91525d2a6 100644 --- a/services/web/server/src/simcore_service_webserver/payments/_api.py +++ b/services/web/server/src/simcore_service_webserver/payments/_api.py @@ -9,6 +9,7 @@ PaymentTransaction, WalletPaymentCreated, ) +from models_library.products import ProductName from models_library.users import UserID from models_library.wallets import WalletID from simcore_postgres_database.models.payments_transactions import ( @@ -27,10 +28,13 @@ async def check_wallet_permissions( - app: web.Application, user_id: UserID, wallet_id: WalletID + app: web.Application, + user_id: UserID, + wallet_id: WalletID, + product_name: ProductName, ): permissions = await get_wallet_with_permissions_by_user( - app, user_id=user_id, wallet_id=wallet_id + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if not permissions.read or not permissions.write: raise WalletAccessForbiddenError( @@ -83,7 +87,9 @@ async def create_payment_to_wallet( user = await get_user_name_and_email(app, user_id=user_id) # check permissions - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) # hold timestamp initiated_at = arrow.utcnow().datetime @@ -170,7 +176,7 @@ async def complete_payment( if completion_state == PaymentTransactionState.SUCCESS: # notifying RUT user_wallet = await get_wallet_by_user( - app, transaction.user_id, transaction.wallet_id + app, transaction.user_id, transaction.wallet_id, transaction.product_name ) await add_credits_to_wallet( app=app, @@ -193,8 +199,11 @@ async def cancel_payment_to_wallet( payment_id: PaymentID, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> PaymentTransaction: - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) return await complete_payment( app, diff --git a/services/web/server/src/simcore_service_webserver/payments/_methods_api.py b/services/web/server/src/simcore_service_webserver/payments/_methods_api.py index af31aa9f6ff..0147746af01 100644 --- a/services/web/server/src/simcore_service_webserver/payments/_methods_api.py +++ b/services/web/server/src/simcore_service_webserver/payments/_methods_api.py @@ -13,6 +13,7 @@ PaymentMethodInit, PaymentMethodTransaction, ) +from models_library.products import ProductName from models_library.users import UserID from models_library.wallets import WalletID from simcore_postgres_database.models.payments_methods import InitPromptAckFlowState @@ -68,7 +69,11 @@ def _to_api_model( async def init_creation_of_wallet_payment_method( - app: web.Application, *, user_id: UserID, wallet_id: WalletID + app: web.Application, + *, + user_id: UserID, + wallet_id: WalletID, + product_name: ProductName, ) -> PaymentMethodInit: """ @@ -78,7 +83,9 @@ async def init_creation_of_wallet_payment_method( """ # check permissions - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) # hold timestamp initiated_at = arrow.utcnow().datetime @@ -149,9 +156,12 @@ async def cancel_creation_of_wallet_payment_method( user_id: UserID, wallet_id: WalletID, payment_method_id: PaymentMethodID, + product_name: ProductName, ): """Acks as CANCELED""" - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) await _complete_create_of_wallet_payment_method( app, @@ -176,10 +186,16 @@ async def cancel_creation_of_wallet_payment_method( async def list_wallet_payment_methods( - app: web.Application, *, user_id: UserID, wallet_id: WalletID + app: web.Application, + *, + user_id: UserID, + wallet_id: WalletID, + product_name: ProductName, ) -> list[PaymentMethodGet]: # check permissions - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) # get acked acked = await list_successful_payment_methods( @@ -218,9 +234,12 @@ async def get_wallet_payment_method( user_id: UserID, wallet_id: WalletID, payment_method_id: PaymentMethodID, + product_name: ProductName, ) -> PaymentMethodGet: # check permissions - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) acked = await get_successful_payment_method( app, user_id=user_id, wallet_id=wallet_id, payment_method_id=payment_method_id @@ -246,9 +265,12 @@ async def delete_wallet_payment_method( user_id: UserID, wallet_id: WalletID, payment_method_id: PaymentMethodID, + product_name: ProductName, ): # check permissions - await check_wallet_permissions(app, user_id=user_id, wallet_id=wallet_id) + await check_wallet_permissions( + app, user_id=user_id, wallet_id=wallet_id, product_name=product_name + ) assert payment_method_id # nosec acked = await get_successful_payment_method( diff --git a/services/web/server/src/simcore_service_webserver/projects/_wallets_handlers.py b/services/web/server/src/simcore_service_webserver/projects/_wallets_handlers.py index 00d17969c85..bd675070498 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_wallets_handlers.py +++ b/services/web/server/src/simcore_service_webserver/projects/_wallets_handlers.py @@ -97,7 +97,10 @@ async def connect_wallet_to_project(request: web.Request): ) # ensure the wallet can be used by the user wallet: WalletGet = await wallet_api.get_wallet_by_user( - request.app, user_id=req_ctx.user_id, wallet_id=path_params.wallet_id + request.app, + user_id=req_ctx.user_id, + wallet_id=path_params.wallet_id, + product_name=req_ctx.product_name, ) await db.connect_wallet_to_project( diff --git a/services/web/server/src/simcore_service_webserver/projects/projects_api.py b/services/web/server/src/simcore_service_webserver/projects/projects_api.py index 0407ea8d413..39280583401 100644 --- a/services/web/server/src/simcore_service_webserver/projects/projects_api.py +++ b/services/web/server/src/simcore_service_webserver/projects/projects_api.py @@ -271,7 +271,7 @@ async def _start_dynamic_service( if project_wallet and app_settings.WEBSERVER_DEV_FEATURES_ENABLED: # Check whether user has access to the wallet await wallets_api.get_wallet_by_user( - request.app, user_id, project_wallet.wallet_id + request.app, user_id, project_wallet.wallet_id, product_name ) wallet_info = WalletInfo( wallet_id=project_wallet.wallet_id, wallet_name=project_wallet.name diff --git a/services/web/server/src/simcore_service_webserver/resource_usage/_observer.py b/services/web/server/src/simcore_service_webserver/resource_usage/_observer.py index 09fc04a3d6e..cdef9687131 100644 --- a/services/web/server/src/simcore_service_webserver/resource_usage/_observer.py +++ b/services/web/server/src/simcore_service_webserver/resource_usage/_observer.py @@ -28,7 +28,9 @@ async def _on_user_disconnected( product_name: ProductName, ) -> None: # Get all user wallets and unsubscribe - user_wallet = await wallets_api.list_wallets_for_user(app, user_id=user_id) + user_wallet = await wallets_api.list_wallets_for_user( + app, user_id=user_id, product_name=product_name + ) disconnect_tasks = [ wallet_osparc_credits.unsubscribe(app, wallet.wallet_id) for wallet in user_wallet @@ -40,7 +42,9 @@ async def _on_user_connected( user_id: int, app: web.Application, product_name: str ) -> None: # Get all user wallets and subscribe - user_wallet = await wallets_api.list_wallets_for_user(app, user_id=user_id) + user_wallet = await wallets_api.list_wallets_for_user( + app, user_id=user_id, product_name=product_name + ) connect_tasks = [ wallet_osparc_credits.subscribe(app, wallet.wallet_id) for wallet in user_wallet ] diff --git a/services/web/server/src/simcore_service_webserver/resource_usage/_service_runs_api.py b/services/web/server/src/simcore_service_webserver/resource_usage/_service_runs_api.py index e05b479f850..66b594a7785 100644 --- a/services/web/server/src/simcore_service_webserver/resource_usage/_service_runs_api.py +++ b/services/web/server/src/simcore_service_webserver/resource_usage/_service_runs_api.py @@ -30,7 +30,7 @@ async def list_usage_services( else: wallet: WalletGetPermissions = ( await wallet_api.get_wallet_with_permissions_by_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) ) access_all_wallet_usage = wallet.write is True diff --git a/services/web/server/src/simcore_service_webserver/wallets/_api.py b/services/web/server/src/simcore_service_webserver/wallets/_api.py index 4a4fc75c968..71ad93c10d2 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_api.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_api.py @@ -28,6 +28,7 @@ async def create_wallet( wallet_name: str, description: str | None, thumbnail: str | None, + product_name: ProductName, ) -> WalletGet: user: dict = await users_api.get_user(app, user_id) wallet_db: WalletDB = await db.create_wallet( @@ -36,6 +37,7 @@ async def create_wallet( wallet_name=wallet_name, description=description, thumbnail=thumbnail, + product_name=product_name, ) wallet_api: WalletGet = parse_obj_as(WalletGet, wallet_db) return wallet_api @@ -43,11 +45,11 @@ async def create_wallet( async def list_wallets_with_available_credits_for_user( app: web.Application, - product_name: ProductName, user_id: UserID, + product_name: ProductName, ) -> list[WalletGetWithAvailableCredits]: user_wallets: list[UserWalletDB] = await db.list_wallets_for_user( - app=app, user_id=user_id + app=app, user_id=user_id, product_name=product_name ) # Now we return the user wallets with available credits @@ -78,9 +80,10 @@ async def list_wallets_with_available_credits_for_user( async def list_wallets_for_user( app: web.Application, user_id: UserID, + product_name: ProductName, ) -> list[WalletGet]: user_wallets: list[UserWalletDB] = await db.list_wallets_for_user( - app=app, user_id=user_id + app=app, user_id=user_id, product_name=product_name ) wallets_api = parse_obj_as(list[WalletGet], user_wallets) @@ -95,9 +98,10 @@ async def update_wallet( description: str | None, thumbnail: str | None, status: WalletStatus, + product_name: ProductName, ) -> WalletGet: wallet: UserWalletDB = await db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.write is False: raise WalletAccessForbiddenError( @@ -111,6 +115,7 @@ async def update_wallet( description=description, thumbnail=thumbnail, status=status, + product_name=product_name, ) wallet_api: WalletGet = parse_obj_as(WalletGet, wallet_db) @@ -121,9 +126,10 @@ async def delete_wallet( app: web.Application, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> None: wallet: UserWalletDB = await db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.delete is False: raise WalletAccessForbiddenError( @@ -137,9 +143,10 @@ async def get_wallet_by_user( app: web.Application, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> WalletGet: wallet: UserWalletDB = await db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.read is False: raise WalletAccessForbiddenError( @@ -163,9 +170,10 @@ async def get_wallet_with_permissions_by_user( app: web.Application, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> WalletGetPermissions: wallet: UserWalletDB = await db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) permissions: WalletGetPermissions = parse_obj_as(WalletGetPermissions, wallet) diff --git a/services/web/server/src/simcore_service_webserver/wallets/_db.py b/services/web/server/src/simcore_service_webserver/wallets/_db.py index 13494f74ed5..779f7053281 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_db.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_db.py @@ -6,6 +6,7 @@ import logging from aiohttp import web +from models_library.products import ProductName from models_library.users import GroupID, UserID from models_library.wallets import UserWalletDB, WalletDB, WalletID, WalletStatus from pydantic import parse_obj_as @@ -24,6 +25,7 @@ async def create_wallet( app: web.Application, + product_name: ProductName, owner: GroupID, wallet_name: str, description: str | None, @@ -40,6 +42,7 @@ async def create_wallet( status=WalletStatus.ACTIVE, created=func.now(), modified=func.now(), + product_name=product_name, ) .returning(literal_column("*")) ) @@ -69,6 +72,7 @@ async def create_wallet( async def list_wallets_for_user( app: web.Application, user_id: UserID, + product_name: ProductName, ) -> list[UserWalletDB]: stmt = ( select(*_SELECTION_ARGS) @@ -76,6 +80,7 @@ async def list_wallets_for_user( .where( (user_to_groups.c.uid == user_id) & (user_to_groups.c.access_rights["read"].astext == "true") + & (wallets.c.product_name == product_name) ) .group_by( wallets.c.wallet_id, @@ -100,6 +105,7 @@ async def get_wallet_for_user( app: web.Application, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> UserWalletDB: stmt = ( select(*_SELECTION_ARGS) @@ -108,6 +114,7 @@ async def get_wallet_for_user( (user_to_groups.c.uid == user_id) & (user_to_groups.c.access_rights["read"].astext == "true") & (wallets.c.wallet_id == wallet_id) + & (wallets.c.product_name == product_name) ) .group_by( wallets.c.wallet_id, @@ -131,7 +138,9 @@ async def get_wallet_for_user( return parse_obj_as(UserWalletDB, row) -async def get_wallet(app: web.Application, wallet_id: WalletID) -> WalletDB: +async def get_wallet( + app: web.Application, wallet_id: WalletID, product_name: ProductName +) -> WalletDB: stmt = ( select( wallets.c.wallet_id, @@ -144,7 +153,10 @@ async def get_wallet(app: web.Application, wallet_id: WalletID) -> WalletDB: wallets.c.modified, ) .select_from(wallets) - .where(wallets.c.wallet_id == wallet_id) + .where( + (wallets.c.wallet_id == wallet_id) + & (wallets.c.product_name == product_name) + ) ) async with get_database_engine(app).acquire() as conn: result = await conn.execute(stmt) @@ -161,6 +173,7 @@ async def update_wallet( description: str | None, thumbnail: str | None, status: WalletStatus, + product_name: ProductName, ) -> WalletDB: async with get_database_engine(app).acquire() as conn: result = await conn.execute( @@ -172,7 +185,10 @@ async def update_wallet( status=status, modified=func.now(), ) - .where(wallets.c.wallet_id == wallet_id) + .where( + (wallets.c.wallet_id == wallet_id) + & (wallets.c.product_name == product_name) + ) .returning(literal_column("*")) ) row = await result.first() @@ -184,6 +200,12 @@ async def update_wallet( async def delete_wallet( app: web.Application, wallet_id: WalletID, + product_name: ProductName, ) -> None: async with get_database_engine(app).acquire() as conn: - await conn.execute(wallets.delete().where(wallets.c.wallet_id == wallet_id)) + await conn.execute( + wallets.delete().where( + (wallets.c.wallet_id == wallet_id) + & (wallets.c.product_name == product_name) + ) + ) diff --git a/services/web/server/src/simcore_service_webserver/wallets/_groups_api.py b/services/web/server/src/simcore_service_webserver/wallets/_groups_api.py index 951e0b8eafc..9b82fcc855c 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_groups_api.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_groups_api.py @@ -2,6 +2,7 @@ from datetime import datetime from aiohttp import web +from models_library.products import ProductName from models_library.users import GroupID, UserID from models_library.wallets import UserWalletDB, WalletID from pydantic import BaseModel, parse_obj_as @@ -32,9 +33,10 @@ async def create_wallet_group( read: bool, write: bool, delete: bool, + product_name: ProductName, ) -> WalletGroupGet: wallet: UserWalletDB = await wallets_db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.write is False: raise WalletAccessForbiddenError( @@ -58,9 +60,10 @@ async def list_wallet_groups_by_user_and_wallet( app: web.Application, user_id: UserID, wallet_id: WalletID, + product_name: ProductName, ) -> list[WalletGroupGet]: wallet: UserWalletDB = await wallets_db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.read is False: raise WalletAccessForbiddenError( @@ -103,9 +106,10 @@ async def update_wallet_group( read: bool, write: bool, delete: bool, + product_name: ProductName, ) -> WalletGroupGet: wallet: UserWalletDB = await wallets_db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.write is False: raise WalletAccessForbiddenError( @@ -137,9 +141,10 @@ async def delete_wallet_group( user_id: UserID, wallet_id: WalletID, group_id: GroupID, + product_name: ProductName, ) -> None: wallet: UserWalletDB = await wallets_db.get_wallet_for_user( - app=app, user_id=user_id, wallet_id=wallet_id + app=app, user_id=user_id, wallet_id=wallet_id, product_name=product_name ) if wallet.delete is False: raise WalletAccessForbiddenError( diff --git a/services/web/server/src/simcore_service_webserver/wallets/_groups_handlers.py b/services/web/server/src/simcore_service_webserver/wallets/_groups_handlers.py index ec6200c2653..4d811f4d475 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_groups_handlers.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_groups_handlers.py @@ -93,6 +93,7 @@ async def create_wallet_group(request: web.Request): read=body_params.read, write=body_params.write, delete=body_params.delete, + product_name=req_ctx.product_name, ) return envelope_json_response(wallet_groups, web.HTTPCreated) @@ -109,7 +110,10 @@ async def list_wallet_groups(request: web.Request): wallets: list[ WalletGroupGet ] = await _groups_api.list_wallet_groups_by_user_and_wallet( - request.app, user_id=req_ctx.user_id, wallet_id=path_params.wallet_id + request.app, + user_id=req_ctx.user_id, + wallet_id=path_params.wallet_id, + product_name=req_ctx.product_name, ) return envelope_json_response(wallets, web.HTTPOk) @@ -135,6 +139,7 @@ async def update_wallet_group(request: web.Request): read=body_params.read, write=body_params.write, delete=body_params.delete, + product_name=req_ctx.product_name, ) @@ -154,5 +159,6 @@ async def delete_wallet_group(request: web.Request): user_id=req_ctx.user_id, wallet_id=path_params.wallet_id, group_id=path_params.group_id, + product_name=req_ctx.product_name, ) raise web.HTTPNoContent(content_type=MIMETYPE_APPLICATION_JSON) diff --git a/services/web/server/src/simcore_service_webserver/wallets/_handlers.py b/services/web/server/src/simcore_service_webserver/wallets/_handlers.py index 5c7e30b843b..d51d655e516 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_handlers.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_handlers.py @@ -96,6 +96,7 @@ async def create_wallet(request: web.Request): wallet_name=body_params.name, description=body_params.description, thumbnail=body_params.thumbnail, + product_name=req_ctx.product_name, ) return envelope_json_response(wallet, web.HTTPCreated) @@ -111,7 +112,7 @@ async def list_wallets(request: web.Request): wallets: list[ WalletGetWithAvailableCredits ] = await _api.list_wallets_with_available_credits_for_user( - request.app, req_ctx.product_name, user_id=req_ctx.user_id + app=request.app, user_id=req_ctx.user_id, product_name=req_ctx.product_name ) return envelope_json_response(wallets) @@ -137,5 +138,6 @@ async def update_wallet(request: web.Request): description=body_params.description, thumbnail=body_params.thumbnail, status=body_params.status, + product_name=req_ctx.product_name, ) return envelope_json_response(updated_wallet) diff --git a/services/web/server/src/simcore_service_webserver/wallets/_payments_handlers.py b/services/web/server/src/simcore_service_webserver/wallets/_payments_handlers.py index e50abf9edb7..7c172c734b9 100644 --- a/services/web/server/src/simcore_service_webserver/wallets/_payments_handlers.py +++ b/services/web/server/src/simcore_service_webserver/wallets/_payments_handlers.py @@ -159,6 +159,7 @@ async def cancel_payment(request: web.Request): user_id=req_ctx.user_id, wallet_id=path_params.wallet_id, payment_id=path_params.payment_id, + product_name=req_ctx.product_name, ) return web.HTTPNoContent(content_type=MIMETYPE_APPLICATION_JSON) @@ -197,7 +198,10 @@ async def init_creation_of_payment_method(request: web.Request): extra=get_log_record_extra(user_id=req_ctx.user_id), ): initiated: PaymentMethodInit = await init_creation_of_wallet_payment_method( - request.app, user_id=req_ctx.user_id, wallet_id=path_params.wallet_id + request.app, + user_id=req_ctx.user_id, + wallet_id=path_params.wallet_id, + product_name=req_ctx.product_name, ) # NOTE: the request has been accepted to create a payment-method @@ -231,6 +235,7 @@ async def cancel_creation_of_payment_method(request: web.Request): user_id=req_ctx.user_id, wallet_id=path_params.wallet_id, payment_method_id=path_params.payment_method_id, + product_name=req_ctx.product_name, ) return web.HTTPNoContent(content_type=MIMETYPE_APPLICATION_JSON) @@ -248,7 +253,10 @@ async def list_payments_methods(request: web.Request): path_params = parse_request_path_parameters_as(WalletsPathParams, request) payments_methods: list[PaymentMethodGet] = await list_wallet_payment_methods( - request.app, user_id=req_ctx.user_id, wallet_id=path_params.wallet_id + request.app, + user_id=req_ctx.user_id, + wallet_id=path_params.wallet_id, + product_name=req_ctx.product_name, ) return envelope_json_response(payments_methods) @@ -270,6 +278,7 @@ async def get_payment_method(request: web.Request): user_id=req_ctx.user_id, wallet_id=path_params.wallet_id, payment_method_id=path_params.payment_method_id, + product_name=req_ctx.product_name, ) return envelope_json_response(payment_method) @@ -291,5 +300,6 @@ async def delete_payment_method(request: web.Request): user_id=req_ctx.user_id, wallet_id=path_params.wallet_id, payment_method_id=path_params.payment_method_id, + product_name=req_ctx.product_name, ) return web.HTTPNoContent(content_type=MIMETYPE_APPLICATION_JSON) diff --git a/services/web/server/tests/unit/with_dbs/02/test_projects_wallet_handlers.py b/services/web/server/tests/unit/with_dbs/02/test_projects_wallet_handlers.py index 1b0d00a83eb..97be8ee6ba9 100644 --- a/services/web/server/tests/unit/with_dbs/02/test_projects_wallet_handlers.py +++ b/services/web/server/tests/unit/with_dbs/02/test_projects_wallet_handlers.py @@ -80,7 +80,12 @@ def setup_wallets_db( for name in ["My wallet 1", "My wallet 2"]: result = con.execute( wallets.insert() - .values(name=name, owner=logged_user["primary_gid"], status="ACTIVE") + .values( + name=name, + owner=logged_user["primary_gid"], + status="ACTIVE", + product_name="osparc", + ) .returning(sa.literal_column("*")) ) output.append(parse_obj_as(WalletGet, result.fetchone())) diff --git a/services/web/server/tests/unit/with_dbs/03/resource_usage/test_usage_services__list.py b/services/web/server/tests/unit/with_dbs/03/resource_usage/test_usage_services__list.py index 8703fce6e54..8a5c2ecaa55 100644 --- a/services/web/server/tests/unit/with_dbs/03/resource_usage/test_usage_services__list.py +++ b/services/web/server/tests/unit/with_dbs/03/resource_usage/test_usage_services__list.py @@ -82,7 +82,12 @@ def setup_wallets_db( with postgres_db.connect() as con: result = con.execute( wallets.insert() - .values(name="My wallet", owner=logged_user["primary_gid"], status="ACTIVE") + .values( + name="My wallet", + owner=logged_user["primary_gid"], + status="ACTIVE", + product_name="osparc", + ) .returning(sa.literal_column("*")) ) row = result.fetchone()