Beispiel #1
0
    def test_staff_close_requests(self, mock_slack, mock_experts_slack,
                                  mock_mail):
        """
        Test that existing staffbot requests for a task is closed when
        a staff function is called.
        """
        CLOSED = StaffBotRequest.Status.CLOSED.value

        bot = StaffBot()
        task = TaskFactory()
        init_num_request = StaffBotRequest.objects.filter(task=task).count()
        self.assertEqual(init_num_request, 0)

        bot.staff(task.id)
        requests = StaffBotRequest.objects.filter(task=task)
        num_request = requests.count()
        self.assertEqual(num_request, init_num_request + 1)
        self.assertNotEqual(requests.last().status, CLOSED)

        # Calling staff on the same task should close the previous request
        # and create a new one.
        bot.staff(task.id)
        requests = list(StaffBotRequest.objects.filter(task=task))
        num_request = len(requests)
        self.assertEqual(num_request, init_num_request + 2)
        self.assertEqual(requests[-2].status, CLOSED)
        self.assertNotEqual(requests[-1].status, CLOSED)
Beispiel #2
0
def staff_task(request):
    data = load_encoded_json(request.body)
    errors = {}
    try:
        task = Task.objects.get(id=data.get('task_id'))
        request_cause = StaffBotRequest.RequestCause.USER.value
        bot = StaffBot()
        assignment = current_assignment(task)
        is_restaff = assignment is not None
        if is_restaff:
            username = assignment.worker.user.username
            bot.restaff(task.id, username, request_cause=request_cause)
        else:
            bot.staff(task.id, request_cause=request_cause)
    except Exception as e:
        raise BadRequest(e)
    success = len(errors) == 0
    return {'success': success, 'is_restaff': is_restaff}
Beispiel #3
0
def staffbot_autoassign(task, **kwargs):
    request_cause = StaffBotRequest.RequestCause.AUTOSTAFF.value
    bot = StaffBot()
    bot.staff(task.id, request_cause=request_cause)
    return task