Skip to content

Commit fc7ed8a

Browse files
committed
fixed examples
1 parent c845b87 commit fc7ed8a

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,40 @@
7575
UnitStr: TypeAlias = Annotated[str, StringConstraints(strip_whitespace=True)]
7676

7777

78-
class NodeLockReason(StrAutoEnum):
78+
class NodeShareStatus(StrAutoEnum):
7979
OPENING = auto()
8080
OPENED = auto()
8181
CLOSING = auto()
8282

8383

84-
class NodeLockState(BaseModel):
85-
is_locked: Annotated[
84+
class NodeShareState(BaseModel):
85+
locked: Annotated[
8686
bool,
8787
Field(
8888
description="True if the node is locked, False otherwise",
8989
),
9090
]
9191

92-
locked_by: Annotated[
93-
GroupID | None,
94-
Field(description="Group that owns locked the node, None if not locked"),
92+
current_user_groupids: Annotated[
93+
list[GroupID] | None,
94+
Field(
95+
description="Group(s) that currently have access to the node (or locked it)"
96+
),
9597
] = None
9698

97-
locked_reason: Annotated[
98-
NodeLockReason | None,
99+
status: Annotated[
100+
NodeShareStatus | None,
99101
Field(
100102
description="Reason why the node is locked, None if not locked",
101103
),
102104
] = None
103105

104106
@model_validator(mode="after")
105-
def _validate_lock_state(self) -> "NodeLockState":
106-
if self.is_locked and (self.locked_by is None or self.locked_reason is None):
107-
msg = "If the node is locked, both 'locked_by' and 'locked_reason' must be set"
108-
raise ValueError(msg)
109-
if not self.is_locked and (
110-
self.locked_by is not None or self.locked_reason is not None
111-
):
112-
msg = "If the node is not locked, both 'locked_by' and 'locked_reason' must be None"
107+
def _validate_lock_state(self) -> "NodeShareState":
108+
if self.locked and (self.current_user_groupids is None or self.status is None):
109+
msg = "If the node is locked, both 'current_user_groupids' and 'status' must be set"
113110
raise ValueError(msg)
111+
114112
return self
115113

116114
@staticmethod
@@ -119,12 +117,17 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
119117
{
120118
"examples": [
121119
{
122-
"is_locked": False,
120+
"locked": False,
123121
},
124122
{
125-
"is_locked": True,
126-
"locked_by": 666,
127-
"locked_reason": "OPENING",
123+
"locked": True,
124+
"current_user_groupids": [666],
125+
"status": "OPENING",
126+
},
127+
{
128+
"locked": False,
129+
"current_user_groupids": [666, 4563],
130+
"status": "OPENED",
128131
},
129132
]
130133
}
@@ -168,9 +171,9 @@ class NodeState(BaseModel):
168171
),
169172
] = 0
170173

171-
lock_state: Annotated[NodeLockState, Field(description="the node's lock state")] = (
172-
NodeLockState(is_locked=False, locked_by=None, locked_reason=None)
173-
)
174+
lock_state: Annotated[
175+
NodeShareState, Field(description="the node's lock state")
176+
] = NodeShareState(locked=False, current_user_groupids=None, status=None)
174177

175178
model_config = ConfigDict(
176179
extra="forbid",

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
from models_library.projects_access import Owner
4949
from models_library.projects_nodes import (
5050
Node,
51-
NodeLockReason,
52-
NodeLockState,
51+
NodeShareState,
52+
NodeShareStatus,
5353
NodeState,
5454
PartialNode,
5555
)
@@ -1375,9 +1375,9 @@ async def is_node_id_present_in_any_project_workbench(
13751375
return await db.node_id_exists(node_id)
13761376

13771377

1378-
async def _get_node_lock_state(
1378+
async def _get_node_share_state(
13791379
app: web.Application, *, user_id: UserID, project_uuid: ProjectID, node_id: NodeID
1380-
) -> NodeLockState:
1380+
) -> NodeShareState:
13811381
node = await _projects_nodes_repository.get(
13821382
app, project_id=project_uuid, node_id=node_id
13831383
)
@@ -1390,28 +1390,32 @@ async def _get_node_lock_state(
13901390

13911391
if isinstance(service, DynamicServiceGet | NodeGet):
13921392
# service is running
1393-
return NodeLockState(
1394-
is_locked=True,
1395-
locked_by=await users_service.get_user_primary_group_id(
1396-
app, TypeAdapter(UserID).validate_python(service.user_id)
1397-
),
1398-
locked_reason=NodeLockReason.OPENED,
1393+
return NodeShareState(
1394+
locked=True,
1395+
current_user_groupids=[
1396+
await users_service.get_user_primary_group_id(
1397+
app, TypeAdapter(UserID).validate_python(service.user_id)
1398+
)
1399+
],
1400+
status=NodeShareStatus.OPENED,
13991401
)
14001402
if isinstance(service, NodeGetUnknown):
14011403
# service state is unknown
14021404
# we should raise an exception here
14031405
msg = "Node state is unknown"
14041406
raise RuntimeError(msg)
1405-
return NodeLockState(is_locked=False)
1407+
return NodeShareState(locked=False)
14061408

14071409
# if the service is computational and no pipeline is running it is not locked
14081410
if await director_v2_service.is_pipeline_running(app, user_id, project_uuid):
1409-
return NodeLockState(
1410-
is_locked=True,
1411-
locked_by=await users_service.get_user_primary_group_id(app, user_id),
1412-
locked_reason=NodeLockReason.OPENED,
1411+
return NodeShareState(
1412+
locked=True,
1413+
current_user_groupids=[
1414+
await users_service.get_user_primary_group_id(app, user_id)
1415+
],
1416+
status=NodeShareStatus.OPENED,
14131417
)
1414-
return NodeLockState(is_locked=False)
1418+
return NodeShareState(locked=False)
14151419

14161420

14171421
async def _safe_retrieve(
@@ -1822,7 +1826,7 @@ async def add_project_states_for_user(
18221826
for node_uuid, node in project["workbench"].items():
18231827
assert isinstance(node, dict) # nosec
18241828

1825-
node_lock_state = await _get_node_lock_state(
1829+
node_lock_state = await _get_node_share_state(
18261830
app,
18271831
user_id=user_id,
18281832
project_uuid=project["uuid"],

0 commit comments

Comments
 (0)