Exemplo n.º 1
0
    def test_clear_assignation(self):
        self.generate_fixture_task()
        self.generate_fixture_shot_task()
        task_id = str(self.task.id)
        shot_task_id = str(self.shot_task.id)
        tasks_service.assign_task(self.task.id, self.person.id)
        tasks_service.assign_task(self.shot_task.id, self.person.id)
        data = {"task_ids": [task_id, shot_task_id]}
        self.put("/actions/tasks/clear-assignation", data)

        task = tasks_service.get_task_with_relations(task_id)
        self.assertEqual(len(task["assignees"]), 0)
        task = tasks_service.get_task_with_relations(shot_task_id)
        self.assertEqual(len(task["assignees"]), 0)
Exemplo n.º 2
0
    def test_multiple_task_assign(self):
        self.generate_fixture_task()
        self.generate_fixture_shot_task()
        task_id = str(self.task.id)
        shot_task_id = str(self.shot_task.id)
        person_id = str(self.person.id)
        data = {"task_ids": [task_id, shot_task_id]}
        self.put("/actions/persons/%s/assign" % person_id, data)

        task = tasks_service.get_task_with_relations(task_id)
        self.assertEqual(len(task["assignees"]), 1)
        task = tasks_service.get_task_with_relations(shot_task_id)
        self.assertEqual(len(task["assignees"]), 1)
        notifications = notifications_service.get_last_notifications()
        self.assertEqual(len(notifications), 2)
Exemplo n.º 3
0
    def test_import_task(self):
        self.load_task()
        self.assertEqual(len(self.tasks), 1)

        self.tasks = self.get("data/tasks")
        self.assertEqual(len(self.tasks), 1)

        task = self.tasks[0]
        task = tasks_service.get_task_with_relations(task["id"])
        project = Project.get_by(name=self.sg_task["project"]["name"])
        task_type = \
            TaskType.get_by(name=self.sg_task["step"]["name"])
        task_status = TaskStatus.get_by(
            short_name=self.sg_task["sg_status_list"])
        assets = assets_service.get_assets(
            {"shotgun_id": self.sg_task["entity"]["id"]})
        entity = assets[0]
        assigner = Person.get_by(
            last_name=self.sg_task["created_by"]["name"].split(" ")[1])
        assignee = Person.get_by(
            last_name=self.sg_task["task_assignees"][0]["name"].split(" ")[1])

        self.assertEqual(task["name"], self.sg_task["cached_display_name"])
        self.assertEqual(task["duration"], self.sg_task["duration"])
        self.assertEqual(task["shotgun_id"], self.sg_task["id"])
        self.assertEqual(task["project_id"], str(project.id))
        self.assertEqual(task["task_type_id"], str(task_type.id))
        self.assertEqual(task["task_status_id"], str(task_status.id))
        self.assertEqual(task["entity_id"], entity["id"])
        self.assertEqual(task["assigner_id"], str(assigner.id))
        self.assertEqual(task["assignees"][0], str(assignee.id))
Exemplo n.º 4
0
    def post(self):
        """
        Create a task with data given in the request body. JSON format is
        expected. The model performs the validation automatically when
        instantiated.
        """
        try:
            data = request.json
            is_assignees = "assignees" in data
            assignees = None

            if is_assignees:
                assignees = data["assignees"]
                persons = Person.query.filter(Person.id.in_(assignees)).all()
                del data["assignees"]

            instance = self.model(**data)
            if assignees is not None:
                instance.assignees = persons
            instance.save()

            return tasks_service.get_task_with_relations(str(instance.id)), 201

        except TypeError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"message": str(exception)}, 400

        except IntegrityError as exception:
            current_app.logger.error(str(exception), exc_info=1)
            return {"message": "Task already exists."}, 400
Exemplo n.º 5
0
def create_comment(
    person_id,
    task_id,
    task_status_id,
    comment,
    checklist,
    files,
    created_at
):
    """
    Create a new comment and related: news, notifications and events.
    """
    task = tasks_service.get_task_with_relations(task_id)
    task_status = tasks_service.get_task_status(task_status_id)
    author = _get_comment_author(person_id)
    comment = new_comment(
        task_id=task_id,
        object_type="Task",
        files=files,
        person_id=author["id"],
        task_status_id=task_status_id,
        text=comment,
        checklist=checklist,
        created_at=created_at
    )
    task, status_changed = _manage_status_change(task_status, task, comment)
    _manage_subscriptions(task, comment, status_changed)
    comment["task_status"] = task_status
    comment["person"] = author
    return comment
Exemplo n.º 6
0
def create_comment(person_id, task_id, task_status_id, text, checklist, files,
                   created_at):
    """
    Create a new comment and related: news, notifications and events.
    """
    task = tasks_service.get_task_with_relations(task_id)
    task_status = tasks_service.get_task_status(task_status_id)
    author = _get_comment_author(person_id)
    _check_retake_capping(task_status, task)
    comment = new_comment(
        task_id=task_id,
        object_type="Task",
        files=files,
        person_id=author["id"],
        task_status_id=task_status_id,
        text=text,
        checklist=checklist,
        created_at=created_at,
    )
    task, status_changed = _manage_status_change(task_status, task, comment)
    _manage_subscriptions(task, comment, status_changed)
    comment["task_status"] = task_status
    comment["person"] = author

    status_automations = projects_service.get_project_status_automations(
        task["project_id"])
    for automation in status_automations:
        _run_status_automation(automation, task, person_id)
    return comment
Exemplo n.º 7
0
    def post(self, task_id):
        (task_status_id, comment, person_id) = self.get_arguments()

        task = tasks_service.get_task(task_id)
        user_service.check_project_access(task["project_id"])
        task_status = tasks_service.get_task_status(task_status_id)

        if person_id:
            person = persons_service.get_person(person_id)
        else:
            person = persons_service.get_current_user()

        comment = tasks_service.create_comment(
            object_id=task_id,
            object_type="Task",
            task_status_id=task_status_id,
            person_id=person["id"],
            text=comment,
        )

        status_changed = task_status_id != task["task_status_id"]
        new_data = {
            "task_status_id": task_status_id,
            "last_comment_date": comment["created_at"],
        }
        if status_changed:
            if task_status["is_retake"]:
                retake_count = task["retake_count"]
                if retake_count is None or retake_count == "NoneType":
                    retake_count = 0
                new_data["retake_count"] = retake_count + 1

            if task_status["is_done"]:
                new_data["end_date"] = datetime.datetime.now()
            else:
                new_data["end_date"] = None

            if (task_status["short_name"] == "wip"
                    and task["real_start_date"] is None):
                new_data["real_start_date"] = datetime.datetime.now()

        tasks_service.update_task(task_id, new_data)
        task = tasks_service.get_task_with_relations(task_id)

        notifications_service.create_notifications_for_task_and_comment(
            task, comment, change=status_changed)
        news_service.create_news_for_task_and_comment(task,
                                                      comment,
                                                      change=status_changed)

        comment["task_status"] = task_status
        comment["person"] = person
        return comment, 201
Exemplo n.º 8
0
 def get_allowed_comments_only(self, comments, person_id):
     allowed_comments = []
     for comment in comments:
         try:
             task = tasks_service.get_task_with_relations(
                 comment["object_id"], )
             if person_id in task["assignees"]:
                 allowed_comments.append(comment)
         except permissions.PermissionDenied:
             pass
         except KeyError:
             pass
     return allowed_comments
Exemplo n.º 9
0
 def test_multiple_task_assign_artist(self):
     self.generate_fixture_task()
     self.generate_fixture_shot_task()
     self.generate_fixture_user_cg_artist()
     task_id = str(self.task.id)
     shot_task_id = str(self.shot_task.id)
     person_id = str(self.user_cg_artist["id"])
     department_id = str(self.department.id)
     data = {"task_ids": [task_id, shot_task_id]}
     self.put("/actions/tasks/clear-assignation", data)
     self.log_in_cg_artist()
     self.put("/actions/persons/%s/assign" % person_id, data)
     task = tasks_service.get_task_with_relations(task_id)
     self.assertEqual(len(task["assignees"]), 0)
     task = tasks_service.get_task_with_relations(shot_task_id)
     self.assertEqual(len(task["assignees"]), 0)
     persons_service.add_to_department(department_id, person_id)
     self.put("/actions/persons/%s/assign" % person_id, data)
     task = tasks_service.get_task_with_relations(task_id)
     self.assertEqual(len(task["assignees"]), 0)
     task = tasks_service.get_task_with_relations(shot_task_id)
     self.assertEqual(len(task["assignees"]), 0)
Exemplo n.º 10
0
 def test_clear_assignation(self):
     task_id = self.task.id
     tasks_service.assign_task(self.task.id, self.person.id)
     tasks_service.clear_assignation(task_id)
     task = tasks_service.get_task_with_relations(task_id)
     self.assertEqual(len(task["assignees"]), 0)
Exemplo n.º 11
0
    def post(self, task_id):
        (task_status_id, comment, person_id, created_at,
         checklist) = self.get_arguments()

        task = tasks_service.get_task(task_id)
        user_service.check_project_access(task["project_id"])
        user_service.check_entity_access(task["entity_id"])
        task_status = tasks_service.get_task_status(task_status_id)

        if not permissions.has_manager_permissions():
            person_id = None
            created_at = None

        if person_id:
            person = persons_service.get_person(person_id)
        else:
            person = persons_service.get_current_user()

        comment = tasks_service.create_comment(object_id=task_id,
                                               object_type="Task",
                                               files=request.files,
                                               person_id=person["id"],
                                               task_status_id=task_status_id,
                                               text=comment,
                                               checklist=checklist,
                                               created_at=created_at)

        status_changed = task_status_id != task["task_status_id"]
        new_data = {
            "task_status_id": task_status_id,
            "last_comment_date": comment["created_at"],
        }
        if status_changed:
            if task_status["is_retake"]:
                retake_count = task["retake_count"]
                if retake_count is None or retake_count == "NoneType":
                    retake_count = 0
                new_data["retake_count"] = retake_count + 1

            if task_status["is_done"]:
                new_data["end_date"] = datetime.datetime.now()
            else:
                new_data["end_date"] = None

            if (task_status["short_name"] == "wip"
                    and task["real_start_date"] is None):
                new_data["real_start_date"] = datetime.datetime.now()

        tasks_service.update_task(task_id, new_data)
        if status_changed:
            events.emit(
                "task:status-changed", {
                    "task_id": task_id,
                    "new_task_status_id": new_data["task_status_id"],
                    "previous_task_status_id": task["task_status_id"]
                })

        task = tasks_service.get_task_with_relations(task_id)

        notifications_service.create_notifications_for_task_and_comment(
            task, comment, change=status_changed)
        news_service.create_news_for_task_and_comment(task,
                                                      comment,
                                                      change=status_changed)

        comment["task_status"] = task_status
        comment["person"] = person
        return comment, 201