|
28 | 28 | from ...notifications import project_logs |
29 | 29 | from ...products import products_web |
30 | 30 | from ...products.models import Product |
31 | | -from ...resource_manager.user_sessions import managed_resource |
| 31 | +from ...resource_manager.user_sessions import PROJECT_ID_KEY, managed_resource |
32 | 32 | from ...security.decorators import permission_required |
33 | 33 | from ...socketio.server import get_socket_server |
34 | 34 | from ...users import users_service |
@@ -91,11 +91,17 @@ async def open_project(request: web.Request) -> web.Response: |
91 | 91 | ), |
92 | 92 | ) |
93 | 93 |
|
| 94 | + # Check if projects wallet is not in debt |
94 | 95 | await projects_wallets_service.check_project_financial_status( |
95 | 96 | request.app, |
96 | 97 | project_id=path_params.project_id, |
97 | 98 | product_name=req_ctx.product_name, |
98 | 99 | ) |
| 100 | + # Check if user has access to a project wallet (Useful for simultaneous access to project by different users) |
| 101 | + project_wallet = await projects_wallets_service.get_project_wallet( |
| 102 | + request.app, |
| 103 | + project_id=path_params.project_id, |
| 104 | + ) |
99 | 105 |
|
100 | 106 | product: Product = products_web.get_current_product(request) |
101 | 107 | app_settings = get_application_settings(request.app) |
@@ -220,7 +226,17 @@ async def close_project(request: web.Request) -> web.Response: |
220 | 226 | X_SIMCORE_USER_AGENT, UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE |
221 | 227 | ), |
222 | 228 | ) |
223 | | - await project_logs.unsubscribe(request.app, path_params.project_id) |
| 229 | + |
| 230 | + with managed_resource( |
| 231 | + req_ctx.user_id, client_session_id, request.app |
| 232 | + ) as user_session: |
| 233 | + all_user_sessions_with_project = await user_session.find_users_of_resource( |
| 234 | + request.app, key=PROJECT_ID_KEY, value=f"{path_params.project_id}" |
| 235 | + ) |
| 236 | + # Only unsubscribe from logs if there is no other occurrence of the open project |
| 237 | + if len(all_user_sessions_with_project) == 0: |
| 238 | + await project_logs.unsubscribe(request.app, path_params.project_id) |
| 239 | + |
224 | 240 | return web.json_response(status=status.HTTP_204_NO_CONTENT) |
225 | 241 |
|
226 | 242 |
|
|
0 commit comments