Skip to content

Commit 0416cff

Browse files
committed
refactor
1 parent 9ff25a2 commit 0416cff

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
ProjectType,
3636
)
3737
from ..projects_access import AccessRights, GroupIDStr
38-
from ..projects_state import ProjectState, ProjectStatus
38+
from ..projects_state import (
39+
ProjectShareCurrentUserGroupIDs,
40+
ProjectShareLocked,
41+
ProjectShareStatus,
42+
ProjectStateRunningState,
43+
)
3944
from ..utils._original_fastapi_encoders import jsonable_encoder
4045
from ..utils.common_validators import (
4146
empty_str_to_none_pre_validator,
@@ -106,20 +111,14 @@ def to_domain_model(self) -> dict[str, Any]:
106111

107112

108113
class ProjectShareStateOutputSchema(OutputSchema):
109-
status: Annotated[ProjectStatus, Field(description="The status of the project")]
110-
locked: Annotated[bool, Field(description="True if the project is locked")]
111-
current_user_groupids: Annotated[
112-
list[GroupID],
113-
Field(
114-
description="Current users in the project (if the project is locked, the list contains only the lock owner)"
115-
),
116-
]
114+
status: ProjectShareStatus
115+
locked: ProjectShareLocked
116+
current_user_groupids: ProjectShareCurrentUserGroupIDs
117117

118118

119-
class ProjectStateOutputSchema(ProjectState, OutputSchema):
120-
share_state: Annotated[
121-
ProjectShareStateOutputSchema, Field(description="The project lock state")
122-
]
119+
class ProjectStateOutputSchema(OutputSchema):
120+
share_state: ProjectShareStateOutputSchema
121+
state: ProjectStateRunningState
123122

124123

125124
class ProjectGet(OutputSchema):

packages/models-library/src/models_library/projects_state.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from enum import Enum, unique
6-
from typing import Annotated, Self
6+
from typing import Annotated, Self, TypeAlias
77

88
from pydantic import (
99
BaseModel,
@@ -82,15 +82,24 @@ class ProjectStatus(str, Enum):
8282
MAINTAINING = "MAINTAINING" # used for maintenance tasks, like removing EFS data
8383

8484

85+
ProjectShareStatus: TypeAlias = Annotated[
86+
ProjectStatus, Field(description="The status of the project")
87+
]
88+
ProjectShareLocked: TypeAlias = Annotated[
89+
bool, Field(description="True if the project is locked")
90+
]
91+
ProjectShareCurrentUserGroupIDs: TypeAlias = Annotated[
92+
list[GroupID],
93+
Field(
94+
description="Current users in the project (if the project is locked, the list contains only the lock owner)"
95+
),
96+
]
97+
98+
8599
class ProjectShareState(BaseModel):
86-
status: Annotated[ProjectStatus, Field(description="The status of the project")]
87-
locked: Annotated[bool, Field(description="True if the project is locked")]
88-
current_user_groupids: Annotated[
89-
list[GroupID],
90-
Field(
91-
description="Current users in the project (if the project is locked, the list contains only the lock owner)"
92-
),
93-
]
100+
status: ProjectShareStatus
101+
locked: ProjectShareLocked
102+
current_user_groupids: ProjectShareCurrentUserGroupIDs
94103

95104
@staticmethod
96105
def _update_json_schema_extra(schema: JsonDict) -> None:
@@ -225,12 +234,16 @@ class ProjectRunningState(BaseModel):
225234
model_config = ConfigDict(extra="forbid")
226235

227236

237+
ProjectStateShareState: TypeAlias = Annotated[
238+
ProjectShareState, Field(description="The project share state")
239+
]
240+
ProjectStateRunningState: TypeAlias = Annotated[
241+
ProjectRunningState, Field(description="The project running state")
242+
]
243+
244+
228245
class ProjectState(BaseModel):
229-
share_state: Annotated[
230-
ProjectShareState, Field(description="The project lock state")
231-
]
232-
state: Annotated[
233-
ProjectRunningState, Field(description="The project running state")
234-
]
246+
share_state: ProjectStateShareState
247+
state: ProjectStateRunningState
235248

236249
model_config = ConfigDict(extra="forbid")

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15772,7 +15772,7 @@ components:
1577215772
properties:
1577315773
share_state:
1577415774
$ref: '#/components/schemas/ProjectShareState'
15775-
description: The project lock state
15775+
description: The project share state
1577615776
state:
1577715777
$ref: '#/components/schemas/ProjectRunningState'
1577815778
description: The project running state
@@ -15786,7 +15786,6 @@ components:
1578615786
properties:
1578715787
shareState:
1578815788
$ref: '#/components/schemas/ProjectShareStateOutputSchema'
15789-
description: The project lock state
1579015789
state:
1579115790
$ref: '#/components/schemas/ProjectRunningState'
1579215791
description: The project running state

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from simcore_postgres_database.webserver_models import ProjectType
2121

2222
from ..._meta import API_VTAG as VTAG
23-
from ...collaboration import settings as collaboration_settings
23+
from ...application_settings import get_application_settings
2424
from ...director_v2.exceptions import DirectorV2ServiceError
2525
from ...login.decorators import login_required
2626
from ...notifications import project_logs
@@ -94,16 +94,19 @@ async def open_project(request: web.Request) -> web.Response:
9494
)
9595

9696
product: Product = products_web.get_current_product(request)
97+
app_settings = get_application_settings(request.app)
9798

9899
if not await _projects_service.try_open_project_for_user(
99100
req_ctx.user_id,
100101
project_uuid=path_params.project_id,
101102
client_session_id=client_session_id,
102103
app=request.app,
103104
max_number_of_opened_projects_per_user=product.max_open_studies_per_user,
104-
max_number_of_user_sessions_per_project=collaboration_settings.get_plugin_settings(
105-
request.app
106-
).RTC_MAX_NUMBER_OF_USERS,
105+
max_number_of_user_sessions_per_project=(
106+
1
107+
if not app_settings.WEBSERVER_REALTIME_COLLABORATION
108+
else app_settings.WEBSERVER_REALTIME_COLLABORATION.RTC_MAX_NUMBER_OF_USERS
109+
),
107110
):
108111
raise HTTPLockedError(text="Project is locked, try later")
109112

0 commit comments

Comments
 (0)