|
75 | 75 | from lib.core.jsx_conditions import EmptyQuery |
76 | 76 | from lib.core.entities.items import ProjectCategoryEntity |
77 | 77 |
|
78 | | - |
79 | 78 | logger = logging.getLogger("sa") |
80 | 79 |
|
81 | 80 | NotEmptyStr = constr(strict=True, min_length=1) |
@@ -5337,3 +5336,69 @@ def list_workflows(self): |
5337 | 5336 | EmptyQuery() |
5338 | 5337 | ) |
5339 | 5338 | return BaseSerializer.serialize_iterable(workflows.data) |
| 5339 | + |
| 5340 | + def remove_users(self, users: Union[List[int], List[str]]): |
| 5341 | + """ |
| 5342 | + Allows removing users from the team. |
| 5343 | + :param users: A list of emails or IDs of the users. |
| 5344 | + :type users: Union[List[int], List[str]] |
| 5345 | +
|
| 5346 | + :rtype: None: |
| 5347 | +
|
| 5348 | + Request Example: |
| 5349 | + :: |
| 5350 | +
|
| 5351 | + SAClient.remove_users(member=["example@gmail.com","example1@gmail.com"]) |
| 5352 | +
|
| 5353 | + """ |
| 5354 | + success = 0 |
| 5355 | + if users: |
| 5356 | + if isinstance(users[0], int): |
| 5357 | + users = self.controller.work_management.list_users(id__in=users) |
| 5358 | + user_emails = [user.email for user in users] |
| 5359 | + else: |
| 5360 | + user_emails = users |
| 5361 | + if user_emails: |
| 5362 | + success, _ = self.controller.work_management.remove_users(user_emails) |
| 5363 | + logger.info( |
| 5364 | + f"Successfully removed {success} user(s) out of the {len(users)} provided." |
| 5365 | + ) |
| 5366 | + |
| 5367 | + def remove_users_from_project( |
| 5368 | + self, project: Union[NotEmptyStr, int], users: Union[List[int], List[str]] |
| 5369 | + ): |
| 5370 | + """ |
| 5371 | + Allows removing users from the team. |
| 5372 | +
|
| 5373 | + :param project: The name or ID of the project. |
| 5374 | + :type project: Union[NotEmptyStr, int] |
| 5375 | +
|
| 5376 | + :param users: A list of emails or IDs of the users. |
| 5377 | + :type users: Union[List[int], List[str]] |
| 5378 | +
|
| 5379 | + :rtype: None: |
| 5380 | +
|
| 5381 | + Request Example: |
| 5382 | + :: |
| 5383 | +
|
| 5384 | + SAClient.remove_users_from_project(project="Test Project", users=["example@gmail.com","example1@gmail.com"]) |
| 5385 | +
|
| 5386 | + """ |
| 5387 | + project = self.controller.get_project(project) |
| 5388 | + |
| 5389 | + success = 0 |
| 5390 | + if users: |
| 5391 | + if isinstance(users[0], int): |
| 5392 | + users = self.controller.work_management.list_users( |
| 5393 | + project=project, id__in=users |
| 5394 | + ) |
| 5395 | + user_emails = [user.email for user in users] |
| 5396 | + else: |
| 5397 | + user_emails = users |
| 5398 | + if user_emails: |
| 5399 | + success, _ = self.controller.work_management.remove_users_from_project( |
| 5400 | + project, user_emails |
| 5401 | + ) |
| 5402 | + logger.info( |
| 5403 | + f"Successfully removed {success} users(s) out of the {len(users)} provided from the project {project.name}." |
| 5404 | + ) |
0 commit comments