Skip to content

Commit f1585fb

Browse files
committed
added exception to handle use sessions error
1 parent 9c5dfc3 commit f1585fb

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

services/web/server/src/simcore_service_webserver/projects/_controller/_rest_exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
ProjectOwnerNotFoundInTheProjectAccessRightsError,
4545
ProjectStartsTooManyDynamicNodesError,
4646
ProjectTooManyProjectOpenedError,
47+
ProjectTooManyUserSessionsError,
4748
ProjectTypeAndTemplateIncompatibilityError,
4849
ProjectWalletPendingTransactionError,
4950
WrongTagIdsInQueryError,
@@ -148,6 +149,13 @@
148149
_version=1,
149150
),
150151
),
152+
ProjectTooManyUserSessionsError: HttpErrorInfo(
153+
status.HTTP_409_CONFLICT,
154+
user_message(
155+
"You cannot open more than {max_num_sessions} session(s) for the same project at once. Please close another session and retry.",
156+
_version=1,
157+
),
158+
),
151159
ProjectInDebtCanNotChangeWalletError: HttpErrorInfo(
152160
status.HTTP_402_PAYMENT_REQUIRED,
153161
user_message(

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
ProjectOwnerNotFoundInTheProjectAccessRightsError,
153153
ProjectStartsTooManyDynamicNodesError,
154154
ProjectTooManyProjectOpenedError,
155+
ProjectTooManyUserSessionsError,
155156
ProjectTypeAndTemplateIncompatibilityError,
156157
)
157158
from .models import ProjectDict, ProjectPatchInternalExtended
@@ -1415,13 +1416,23 @@ async def _open_project() -> bool:
14151416
sessions_with_project = await user_session.find_users_of_resource(
14161417
app, PROJECT_ID_KEY, f"{project_uuid}"
14171418
)
1419+
if max_number_of_user_sessions_per_project is not None and (
1420+
len(sessions_with_project)
1421+
>= max_number_of_user_sessions_per_project
1422+
):
1423+
raise ProjectTooManyUserSessionsError(
1424+
max_num_sessions=max_number_of_user_sessions_per_project,
1425+
user_id=user_id,
1426+
project_uuid=project_uuid,
1427+
client_session_id=client_session_id,
1428+
)
14181429
if (
14191430
max_number_of_user_sessions_per_project is None
14201431
or not sessions_with_project
14211432
) or (
14221433
len(sessions_with_project) < max_number_of_user_sessions_per_project
14231434
):
1424-
# no one has the project so we assign it
1435+
# if there are no sessions with this project, or the number of sessions is less than the maximum allowed
14251436
await user_session.add(PROJECT_ID_KEY, f"{project_uuid}")
14261437
return True
14271438

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ def __init__(self, *, user_id: UserID, project_uuid: ProjectID, **ctx):
147147

148148

149149
class ProjectTooManyProjectOpenedError(BaseProjectError):
150-
msg_template = "You cannot open more than {max_num_projects} study/ies at once. Please close another study and retry."
150+
msg_template = "You cannot open more than {max_num_projects} project/s at once. Please close another project and retry."
151151

152152
def __init__(self, *, max_num_projects: int, **ctx):
153153
super().__init__(**ctx)
154154
self.max_num_projects = max_num_projects
155155

156156

157+
class ProjectTooManyUserSessionsError(BaseProjectError):
158+
msg_template = "You cannot open more than {max_num_sessions} session(s) for the same project at once. Please close another session and retry."
159+
160+
def __init__(self, *, max_num_sessions: int, **ctx):
161+
super().__init__(**ctx)
162+
self.max_num_sessions = max_num_sessions
163+
164+
157165
class PermalinkNotAllowedError(BaseProjectError): ...
158166

159167

0 commit comments

Comments
 (0)