88from lib .core .conditions import Condition
99from lib .core .conditions import CONDITION_EQ as EQ
1010from lib .core .entities import AnnotationClassEntity
11- from lib .core .entities import ContributorEntity
1211from lib .core .entities import FormModel
1312from lib .core .entities import generate_classes_from_form
1413from lib .core .entities import ProjectEntity
1514from lib .core .entities import SettingEntity
1615from lib .core .entities import TeamEntity
16+ from lib .core .entities import WMProjectUserEntity
1717from lib .core .enums import CustomFieldEntityEnum
1818from lib .core .enums import CustomFieldType
1919from lib .core .enums import WMUserStateEnum
@@ -830,7 +830,7 @@ def __init__(
830830 self ,
831831 team : TeamEntity ,
832832 project : ProjectEntity ,
833- contributors : List [ContributorEntity ],
833+ contributors : List [WMProjectUserEntity ],
834834 service_provider : BaseServiceProvider ,
835835 ):
836836 super ().__init__ ()
@@ -842,7 +842,7 @@ def __init__(
842842 def validate_emails (self ):
843843 email_entity_map = {}
844844 for c in self ._contributors :
845- email_entity_map [c .user_id ] = c
845+ email_entity_map [c .email ] = c
846846 len_unique , len_provided = len (email_entity_map ), len (self ._contributors )
847847 if len_unique < len_provided :
848848 logger .info (
@@ -853,7 +853,13 @@ def validate_emails(self):
853853 def execute (self ):
854854 if self .is_valid ():
855855 team_users = set ()
856- project_users = {user .user_id for user in self ._project .users }
856+ project_users = self ._service_provider .work_management .list_users (
857+ EmptyQuery (),
858+ include_custom_fields = True ,
859+ parent_entity = CustomFieldEntityEnum .PROJECT ,
860+ project_id = self ._project .id ,
861+ ).data
862+ project_emails = {user .email for user in project_users }
857863 users = self ._service_provider .work_management .list_users (EmptyQuery ()).data
858864 pending_invitations = []
859865 for user in users :
@@ -864,16 +870,16 @@ def execute(self):
864870
865871 # collecting pending project users which is not admin
866872 for user in self ._project .unverified_users :
867- project_users .add (user ["email" ])
873+ project_emails .add (user ["email" ])
868874
869875 role_email_map = defaultdict (list )
870876 to_skip = []
871877 to_add = []
872878 for contributor in self ._contributors :
873- role_email_map [contributor .user_role ].append (contributor .user_id )
874- for role , emails in role_email_map .items ():
875- role_id = self ._service_provider .get_role_id (self ._project , role )
876- _to_add = list (team_users .intersection (emails ) - project_users )
879+ role_email_map [contributor .role ].append (contributor .email )
880+ for role_id , emails in role_email_map .items ():
881+ role_name = self ._service_provider .get_role_name (self ._project , role_id )
882+ _to_add = list (team_users .intersection (emails ) - project_emails )
877883 to_add .extend (_to_add )
878884 to_skip .extend (list (set (emails ).difference (_to_add )))
879885 if _to_add :
@@ -893,7 +899,7 @@ def execute(self):
893899 if response and not response .data .get ("invalidUsers" ):
894900 logger .info (
895901 f"Added { len (_to_add )} /{ len (emails )} "
896- f"contributors to the project { self ._project .name } with the { role } role."
902+ f"contributors to the project { self ._project .name } with the { role_name } role."
897903 )
898904
899905 if to_skip :
@@ -902,7 +908,7 @@ def execute(self):
902908 "contributors that are out of the team scope or already have access to the project."
903909 )
904910 self ._response .data = to_add , to_skip
905- return self ._response
911+ return self ._response
906912
907913
908914class InviteContributorsToTeam (BaseUserBasedUseCase ):
0 commit comments