55from enum import Enum , unique
66from typing import Any , ClassVar
77
8- from pydantic import BaseModel , Extra , Field , validator
8+ from pydantic import BaseModel , Extra , Field , root_validator , validator
99
1010from .projects_access import Owner
1111
@@ -57,10 +57,10 @@ class ProjectStatus(str, Enum):
5757
5858class ProjectLocked (BaseModel ):
5959 value : bool = Field (..., description = "True if the project is locked" )
60+ status : ProjectStatus = Field (..., description = "The status of the project" )
6061 owner : Owner | None = Field (
6162 default = None , description = "If locked, the user that owns the lock"
6263 )
63- status : ProjectStatus = Field (..., description = "The status of the project" )
6464
6565 class Config :
6666 extra = Extra .forbid
@@ -80,14 +80,6 @@ class Config:
8080 ]
8181 }
8282
83- @validator ("owner" , pre = True , always = True )
84- @classmethod
85- def check_not_null (cls , v , values ):
86- if values ["value" ] is True and v is None :
87- msg = "value cannot be None when project is locked"
88- raise ValueError (msg )
89- return v
90-
9183 @validator ("status" , always = True )
9284 @classmethod
9385 def check_status_compatible (cls , v , values ):
@@ -99,6 +91,23 @@ def check_status_compatible(cls, v, values):
9991 raise ValueError (msg )
10092 return v
10193
94+ @root_validator (pre = True )
95+ @classmethod
96+ def check_owner_compatible (cls , values ):
97+ if (
98+ values ["value" ] is True
99+ and values .get ("owner" ) is None
100+ and values ["status" ]
101+ in [
102+ status .value
103+ for status in ProjectStatus
104+ if status != ProjectStatus .MAINTAINING
105+ ]
106+ ):
107+ msg = "Owner must be specified when the project is not in the 'MAINTAINING' status."
108+ raise ValueError (msg )
109+ return values
110+
102111
103112class ProjectRunningState (BaseModel ):
104113 value : RunningState = Field (
0 commit comments