Skip to content

Commit 3357c86

Browse files
authored
Merge pull request #352 from superannotateai/friday
Friday
2 parents ba46e0e + 23a0418 commit 3357c86

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,12 +2904,12 @@ def validate_annotations(
29042904
@Trackable
29052905
@validate_arguments
29062906
def add_contributors_to_project(
2907-
project_name: NotEmptyStr, emails: List[EmailStr], role: AnnotatorRole
2907+
project: NotEmptyStr, emails: List[EmailStr], role: AnnotatorRole
29082908
) -> Tuple[List[str], List[str]]:
29092909
"""Add contributors to project.
29102910
2911-
:param project_name: project name
2912-
:type project_name: str
2911+
:param project: project name
2912+
:type project: str
29132913
29142914
:param emails: users email
29152915
:type emails: list
@@ -2921,7 +2921,7 @@ def add_contributors_to_project(
29212921
rtype: tuple (2 members) of lists of strs
29222922
"""
29232923
response = controller.add_contributors_to_project(
2924-
project_name=project_name, emails=emails, role=role
2924+
project_name=project, emails=emails, role=role
29252925
)
29262926
if response.errors:
29272927
raise AppException(response.errors)

src/superannotate/lib/core/serviceproviders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def share_project_bulk(self, project_id: int, team_id: int, users: Iterable):
4646
raise NotImplementedError
4747

4848
@abstractmethod
49-
def invite_contributors(self, team_id: int, team_role: int, emails: Iterable) -> bool:
49+
def invite_contributors(self, team_id: int, team_role: int, emails: Iterable) -> Tuple[List[str], List[str]]:
5050
raise NotImplementedError
5151

5252
@abstractmethod

src/superannotate/lib/core/usecases/projects.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,8 @@ def execute(self):
981981
if user["user_role"] > constances.UserRole.ADMIN.value:
982982
project_users.add(user["email"])
983983

984-
to_add = team_users.intersection(self._emails) - project_users
985-
to_skip = set(self._emails).difference(to_add)
984+
to_add = list(team_users.intersection(self._emails) - project_users)
985+
to_skip = list(set(self._emails).difference(to_add))
986986

987987
if to_skip:
988988
self.reporter.log_warning(
@@ -1001,7 +1001,7 @@ def execute(self):
10011001
if response and not response.get("invalidUsers"):
10021002
self.reporter.log_info(
10031003
f"Added {len(to_add)}/{len(self._emails)} "
1004-
"contributors to the project <project_name> with the <role> role."
1004+
f"contributors to the project {self._project.name} with the {self.user_role} role."
10051005
)
10061006
self._response.data = to_add, to_skip
10071007
return self._response
@@ -1027,34 +1027,35 @@ def __init__(
10271027
self._service = service
10281028

10291029
def execute(self):
1030-
team_users = set()
1031-
for user in self._team.users:
1032-
if user.user_role > constances.UserRole.ADMIN.value:
1033-
team_users.add(user.email)
1034-
# collecting pending team users which is not admin
1035-
for user in self._team.pending_invitations:
1036-
if user["user_role"] > constances.UserRole.ADMIN.value:
1037-
team_users.add(user["email"])
1030+
team_users = {user.email for user in self._team.users}
1031+
# collecting pending team users
1032+
team_users.update({user["email"] for user in self._team.pending_invitations})
10381033

10391034
emails = set(self._emails)
10401035

1041-
to_skip = emails.intersection(team_users)
1036+
to_skip = list(emails.intersection(team_users))
10421037
to_add = list(emails.difference(to_skip))
10431038

10441039
if to_skip:
10451040
self.reporter.log_warning(
10461041
f"Found {len(to_skip)}/{len(self._emails)} existing members of the team."
10471042
)
10481043
if to_add:
1049-
response = self._service.invite_contributors(
1044+
invited, failed = self._service.invite_contributors(
10501045
team_id=self._team.uuid,
10511046
# REMINDER UserRole.VIEWER is the contributor for the teams
10521047
team_role=constances.UserRole.ADMIN.value if self._set_admin else constances.UserRole.VIEWER.value,
10531048
emails=to_add
10541049
)
1055-
if response:
1050+
if invited:
1051+
self.reporter.log_info(
1052+
f"Sent team {'admin' if self._set_admin else 'contributor'} invitations"
1053+
f" to {len(to_add)}/{len(self._emails)} users."
1054+
)
1055+
if failed:
10561056
self.reporter.log_info(
1057-
f"Sent team <admin/contributor> invitations to {len(to_add)}/{len(self._emails)}."
1057+
f"Skipped team {'admin' if self._set_admin else 'contributor'} "
1058+
f"invitations for {len(failed)}/{len(self._emails)} users."
10581059
)
10591060
self._response.data = to_add, to_skip
10601061
return self._response

src/superannotate/lib/infrastructure/services.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,16 @@ def delete_team_invitation(self, team_id: int, token: str, email: str) -> bool:
511511
)
512512
return res.ok
513513

514-
def invite_contributors(self, team_id: int, team_role: int, emails: list) -> bool:
514+
def invite_contributors(self, team_id: int, team_role: int, emails: list) -> Tuple[List[str], List[str]]:
515515
invite_contributors_url = urljoin(
516516
self.api_url, self.URL_INVITE_CONTRIBUTORS.format(team_id)
517517
)
518518
res = self._request(
519519
invite_contributors_url,
520520
"post",
521521
data=dict(emails=emails, team_role=team_role)
522-
)
523-
return res.ok
522+
).json()
523+
return res["success"]["emails"], res["failed"]["emails"]
524524

525525
def update_image(self, image_id: int, team_id: int, project_id: int, data: dict):
526526
update_image_url = urljoin(self.api_url, self.URL_GET_IMAGE.format(image_id))

tests/integration/projects/test_add_contributors_to_project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def test_add_contributors(self, client, get_project_metadata_mock, get_team_mock
5858
self.assertEqual(len(skipped), 7)
5959

6060
@patch("lib.infrastructure.controller.Controller.get_team")
61-
@patch("lib.infrastructure.controller.Controller.backend_client", MagicMock())
62-
def test_invite_contributors(self, get_team_mock):
61+
@patch("lib.infrastructure.controller.Controller.backend_client", new_callable=PropertyMock)
62+
def test_invite_contributors(self, client, get_team_mock):
6363
random_emails = [self.random_email for i in range(20)]
64-
64+
client.return_value.invite_contributors.return_value = random_emails[:3], []
6565
team_users = [UserEntity(email=email, user_role=3) for email in random_emails[: 10]]
6666
to_add_emails = random_emails[8: 18]
6767
pending_users = [dict(email=email, user_role=3) for email in random_emails[15: 20]]

0 commit comments

Comments
 (0)