44 ResourceNotFoundError ,
55 UnprocessableEntityError ,
66)
7- from typing import Set , Iterator , Any
7+ from typing import Set , Iterator , Any , List
88from pydantic import (
99 Field ,
1010 field_validator ,
@@ -25,7 +25,7 @@ class ProjectMembership(_CamelCaseMixin):
2525 """
2626
2727 project_id : str
28- role : Optional [Role ] = None
28+ role : Optional [Role ] = Field ( default = None )
2929
3030 def __hash__ (self ) -> int :
3131 return self .project_id .__hash__ ()
@@ -34,7 +34,7 @@ def __hash__(self) -> int:
3434 def serialize_model (self ):
3535 return {
3636 "projectId" : self .project_id ,
37- "roleId" : None if self .role is None else self .role .id ,
37+ "roleId" : None if self .role is None else self .role .uid ,
3838 }
3939
4040
@@ -214,6 +214,7 @@ def update(self) -> "Member":
214214 Raises:
215215 ResourceNotFoundError: If the update fails due to unknown member
216216 UnprocessableEntityError: If the update fails due to a malformed input
217+ ValueError: If the member id is current member id.
217218 """
218219 query = """
219220 mutation SetUserAccessPyApi($id: ID!, $roleId: ID!, $canAccessAllProjects: Boolean!, $groupIds: [String!], $projectMemberships: [ProjectMembershipsInput!]) {
@@ -230,13 +231,16 @@ def update(self) -> "Member":
230231 "id" : self .id ,
231232 "roleId" : self .default_role .uid if self .default_role else None ,
232233 "canAccessAllProjects" : self .can_access_all_projects ,
233- "groupIds" : self .user_group_ids ,
234+ "groupIds" : list ( self .user_group_ids ) ,
234235 "projectMemberships" : [
235236 project_membership .model_dump ()
236237 for project_membership in self .project_memberships
237238 ],
238239 }
239240
241+ if self .id == self ._current_user_id :
242+ raise ValueError ("Unable to update self" )
243+
240244 try :
241245 result = self .client .execute (query , params , experimental = True )
242246 if not result :
@@ -282,7 +286,7 @@ def delete(self) -> bool:
282286 raise ResourceNotFoundError (
283287 message = "Failed to delete member as member does not exist"
284288 )
285- return result ["data" ][ " updateUser" ]["deleted" ]
289+ return result ["updateUser" ]["deleted" ]
286290
287291 def _get_project_memberships (self , user_id : str ) -> Set [ProjectMembership ]:
288292 """
@@ -331,8 +335,8 @@ def _get_project_memberships(self, user_id: str) -> Set[ProjectMembership]:
331335 def get_members (
332336 self ,
333337 search : str = "" ,
334- roles : Optional [list [Role ]] = None ,
335- group_ids : Optional [list [str ]] = None ,
338+ roles : Optional [List [Role ]] = None ,
339+ group_ids : Optional [List [str ]] = None ,
336340 ) -> Iterator ["Member" ]:
337341 """
338342 Gets all members in Labelbox.
0 commit comments