File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
packages/models-library/src/models_library Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,16 @@ class AccessRights(BaseModel):
1010
1111 model_config = ConfigDict (extra = "forbid" )
1212
13+ def check_access_constraints (self ):
14+ """Helper function that checks extra constraints in access-rights flags"""
15+ if self .write and not self .read :
16+ msg = "Write access requires read access"
17+ raise ValueError (msg )
18+ if self .delete and not self .write :
19+ msg = "Delete access requires read access"
20+ raise ValueError (msg )
21+ return self
22+
1323
1424class ExecutableAccessRights (BaseModel ):
1525 write : Annotated [bool , Field (description = "can change executable settings" )]
Original file line number Diff line number Diff line change 1- from typing import Annotated
1+ from typing import Annotated , Self
22
33from models_library .groups import GroupID
44from models_library .projects import ProjectID
5+ from pydantic import model_validator # Added for validation
56from pydantic import (
67 BaseModel ,
78 ConfigDict ,
1011 StringConstraints ,
1112)
1213
14+ from ..access_rights import AccessRights
1315from ._base import InputSchema , OutputSchema
1416
1517
1618class ProjectsGroupsPathParams (BaseModel ):
1719 project_id : ProjectID
1820 group_id : GroupID
21+
1922 model_config = ConfigDict (extra = "forbid" )
2023
2124
@@ -36,6 +39,13 @@ class ProjectShare(InputSchema):
3639 write : bool
3740 delete : bool
3841
42+ @model_validator (mode = "after" )
43+ def check_access_constraints (self ) -> Self :
44+ AccessRights (
45+ read = self .read , write = self .write , delete = self .delete
46+ ).check_access_constraints ()
47+ return self
48+
3949
4050class ProjectShareAccepted (OutputSchema ):
4151 sharee_email : EmailStr
You can’t perform that action at this time.
0 commit comments