| 39 | |
| 40 | |
| 41 | def task_user_remove_core(session: 'Session', |
| 42 | task_id: int, |
| 43 | user_id_list: int, |
| 44 | relation: str, |
| 45 | project_string_id: str, |
| 46 | log: dict): |
| 47 | project = Project.get_by_string_id(session, project_string_id = project_string_id) |
| 48 | task = Task.get_by_id(session, task_id) |
| 49 | |
| 50 | if task.project_id != project.id: |
| 51 | log['error']['project_id'] = 'Project and Task ID mismatch. Task does not belong to project.' |
| 52 | return False, log |
| 53 | |
| 54 | if relation != "reviewer" and relation != "assignee": |
| 55 | log['error']['relation'] = 'Invalid relation type. Only support "reviewer", "assignee"' |
| 56 | return False, log |
| 57 | |
| 58 | for user_id in user_id_list: |
| 59 | users_already_assigned = session.query(TaskUser).filter(TaskUser.task_id == task_id).filter(TaskUser.relation == relation).filter(TaskUser.user_id == user_id).count() |
| 60 | if (users_already_assigned < 1): |
| 61 | continue |
| 62 | |
| 63 | task_user = session.query(TaskUser).filter(TaskUser.task_id == task_id).filter(TaskUser.relation == relation).filter(TaskUser.user_id == user_id) |
| 64 | |
| 65 | if task_user: |
| 66 | task_user.delete() |
| 67 | |
| 68 | return True, log |