示例#1
0
    def post(self, task_id, comment_id):
        """
        Add a preview to given task.
        ---
        tags:
        - Tasks
        description: "Revision is automatically set: it is equal to last revision + 1."
        parameters:
          - in: path
            name: task_id
            required: True
            schema:
                type: UUID
                example: a24a6ea4-ce75-4665-a070-57453082c25
          - in: path
            name: comment_id
            required: True
            schema:
                type: UUID
                example: a24a6ea4-ce75-4665-a070-57453082c25
        responses:
            201:
                description: Preview added to given task
        """
        task = tasks_service.get_task(task_id)
        user_service.check_project_access(task["project_id"])
        user_service.check_entity_access(task["entity_id"])

        comment = tasks_service.get_comment(comment_id)
        tasks_service.get_task_status(comment["task_status_id"])
        person = persons_service.get_current_user()
        preview_file = tasks_service.add_preview_file_to_comment(
            comment_id, person["id"], task_id)
        return preview_file, 201
示例#2
0
    def post(self, task_id, comment_id):
        task = tasks_service.get_task(task_id)
        user_service.check_project_access(task["project_id"])

        comment = tasks_service.get_comment(comment_id)
        tasks_service.get_task_status(comment["task_status_id"])
        person = persons_service.get_current_user()
        preview_file = tasks_service.add_preview_file_to_comment(
            comment_id, person["id"], task_id)
        return preview_file, 201
示例#3
0
def send_comment_notification(person_id, author_id, comment, task):
    """
    Send a notification emali telling that a new comment was posted to person
    matching given person id.
    """
    person = persons_service.get_person(person_id)
    if (person["notifications_enabled"]
            or person["notifications_slack_enabled"]):
        task_status = tasks_service.get_task_status(task["task_status_id"])
        task_status_name = task_status["short_name"].upper()
        (author, task_name, task_url) = get_task_descriptors(author_id, task)
        subject = "[Kitsu] %s - %s commented on %s" % (
            task_status_name,
            author["first_name"],
            task_name,
        )
        if len(comment["text"]) > 0:
            email_message = """<p><strong>%s</strong> wrote a comment on <a href="%s">%s</a> and set the status to <strong>%s</strong>.</p>

<p><em>%s</em></p>
""" % (
                author["full_name"],
                task_url,
                task_name,
                task_status_name,
                comment["text"],
            )
            slack_message = """*%s* wrote a comment on <%s|%s> and set the status to *%s*.

_%s_
""" % (
                author["full_name"],
                task_url,
                task_name,
                task_status_name,
                comment["text"],
            )

        else:
            email_message = """<p><strong>%s</strong> changed status of <a href="%s">%s</a> to <strong>%s</strong>.</p>
""" % (
                author["full_name"],
                task_url,
                task_name,
                task_status_name,
            )
            slack_message = """*%s* changed status of <%s|%s> to *%s*.
""" % (
                author["full_name"],
                task_url,
                task_name,
                task_status_name,
            )
        messages = {
            "email_message": email_message,
            "slack_message": slack_message,
        }
        send_notification(person_id, subject, messages)

    return True
示例#4
0
    def post(self, task_id, comment_id):
        is_movie = self.get_arguments()

        task = tasks_service.get_task(task_id)
        if not permissions.has_manager_permissions():
            user_service.check_assigned(task_id)

        comment = tasks_service.get_comment(comment_id)
        task_status = tasks_service.get_task_status(comment.task_status_id)
        person = persons_service.get_current_user()

        if not task_status["is_reviewable"]:
            return {
                "error":
                "Comment status is not reviewable, you cannot link a "
                "preview to it."
            }, 400

        revision = tasks_service.get_next_preview_revision(task_id)
        preview = files_service.create_preview_file(task["name"], revision,
                                                    task["id"], person["id"],
                                                    is_movie)
        comment.update({"preview_file_id": preview["id"]})
        events.emit("preview:add", {
            "comment_id": comment_id,
            "task_id": task_id,
            "preview": preview
        })

        return preview, 201
示例#5
0
    def get(self, task_id):
        task = tasks_service.get_task(task_id)
        if not permissions.has_manager_permissions():
            user_service.check_has_task_related(task["project_id"])

        result = task
        task_type = tasks_service.get_task_type(task["task_type_id"])
        result["task_type"] = task_type
        assigner = persons_service.get_person(task["assigner_id"])
        result["assigner"] = assigner
        project = projects_service.get_project(task["project_id"])
        result["project"] = project
        task_status = tasks_service.get_task_status(task["task_status_id"])
        result["task_status"] = task_status
        entity = tasks_service.get_entity(task["entity_id"])
        result["entity"] = entity
        if entity["parent_id"] is not None:
            sequence = shots_service.get_sequence(entity["parent_id"])
            result["sequence"] = sequence
            if sequence["parent_id"] is not None:
                episode = shots_service.get_episode(sequence["parent_id"])
                result["episode"] = episode
        entity_type = tasks_service.get_entity_type(entity["entity_type_id"])
        result["entity_type"] = entity_type
        assignees = []
        for assignee_id in task["assignees"]:
            assignees.append(persons_service.get_person(assignee_id))
        result["persons"] = assignees
        result["type"] = "Task"

        return result, 200
示例#6
0
    def post(self, task_id):
        (task_status_id, comment, person_id) = self.get_arguments()

        task = tasks_service.get_task(task_id)
        if not permissions.has_manager_permissions():
            user_service.check_assigned(task_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"]

        tasks_service.update_task(task_id, {"task_status_id": task_status_id})

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

        comment["task_status"] = task_status
        comment["person"] = person
        events.emit("comment:new", {"id": comment["id"]})
        return comment, 201
示例#7
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
示例#8
0
def send_comment_notification(person_id, author_id, comment, task):
    """
    Send a notification emali telling that a new comment was posted to person
    matching given person id.
    """
    person = persons_service.get_person_raw(person_id)
    if person.notifications_enabled:
        task_status = tasks_service.get_task_status(task["task_status_id"])
        (author, task_name, task_url) = get_task_descriptors(author_id, task)
        subject = "[Kitsu] %s - %s commented on %s" % (
            task_status["short_name"],
            author["first_name"],
            task_name
        )
        message = """%s wrote a comment on %s and changed the status to %s:

"%s"

To reply connect to this URL:
%s
%s
""" % (
            author["full_name"],
            task_name,
            task_status["short_name"],
            comment["text"],
            task_url,
            get_signature()
        )
        return send_notification(person_id, subject, message)
    else:
        return True
示例#9
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
示例#10
0
    def post(self, task_id, comment_id):
        is_movie = self.get_arguments()

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

        comment = tasks_service.get_comment_raw(comment_id)
        task_status = tasks_service.get_task_status(
            comment.task_status_id
        )
        person = persons_service.get_current_user()

        if not task_status["is_reviewable"]:
            return {
                "error": "Comment status is not reviewable, you cannot link a "
                         "preview to it."
            }, 400

        revision = tasks_service.get_next_preview_revision(task_id)
        preview = files_service.create_preview_file(
            task["name"],
            revision,
            task["id"],
            person["id"],
            is_movie
        )
        comment.update({"preview_file_id": preview["id"]})

        return preview, 201
示例#11
0
def send_reply_notification(person_id, author_id, comment, task, reply):
    """
    Send a notification email telling that a new reply was posted to person
    matching given person id.
    """
    person = persons_service.get_person(person_id)
    if (person["notifications_enabled"]
            or person["notifications_slack_enabled"]):
        task_status = tasks_service.get_task_status(task["task_status_id"])
        project = projects_service.get_project(task["project_id"])
        (author, task_name, task_url) = get_task_descriptors(author_id, task)
        subject = "[Kitsu] %s replied on %s" % (
            author["first_name"],
            task_name,
        )
        email_message = """<p><strong>%s</strong> wrote a reply on <a href="%s">%s</a>.</p>

<p><em>%s</em></p>
""" % (
            author["full_name"],
            task_url,
            task_name,
            reply["text"],
        )
        slack_message = """*%s* wrote a reply on <%s|%s>.

_%s_
""" % (
            author["full_name"],
            task_url,
            task_name,
            reply["text"],
        )

        discord_message = """*%s* wrote a reply on [%s](%s).

_%s_
""" % (
            author["full_name"],
            task_name,
            task_url,
            reply["text"],
        )

        messages = {
            "email_message": email_message,
            "slack_message": slack_message,
            "mattermost_message": {
                "message": slack_message,
                "project_name": project["name"],
            },
            "discord_message": discord_message,
        }
        send_notification(person_id, subject, messages)
    return True
示例#12
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
示例#13
0
def _run_status_automation(automation, task, person_id):
    is_automation_to_run = (
        task["task_type_id"] == automation["in_task_type_id"]
        and task["task_status_id"] == automation["in_task_status_id"])
    if not is_automation_to_run:
        return

    priorities = projects_service.get_task_type_priority_map(
        task["project_id"], automation["entity_type"].capitalize())
    in_priority = priorities.get(automation["in_task_type_id"], 0) or 0
    out_priority = priorities.get(automation["out_task_type_id"], 0) or 0
    is_rollback = (priorities is not None
                   and automation["out_field_type"] != "ready_for"
                   and in_priority > out_priority)
    if is_rollback:  # Do not apply rollback to avoid change cycles.
        return

    if automation["out_field_type"] == "status":
        tasks_to_update = tasks_service.get_tasks_for_entity_and_task_type(
            task["entity_id"], automation["out_task_type_id"])
        if len(tasks_to_update) > 0:
            task_to_update = tasks_to_update[0]
            task_type = tasks_service.get_task_type(
                automation["in_task_type_id"])
            task_status = tasks_service.get_task_status(
                automation["in_task_status_id"])
            create_comment(
                person_id,
                task_to_update["id"],
                automation["out_task_status_id"],
                "Change triggered by %s set to %s" % (
                    task_type["name"],
                    task_status["name"],
                ),
                [],
                {},
                None,
            )
    elif automation["out_field_type"] == "ready_for":
        try:
            asset = assets_service.update_asset(
                task["entity_id"],
                {"ready_for": automation["out_task_type_id"]},
            )
            breakdown_service.refresh_casting_stats(asset)
        except AssetNotFoundException:
            pass
示例#14
0
    def get(self, task_id):
        task = tasks_service.get_task(task_id)
        if not permissions.has_manager_permissions():
            user_service.check_has_task_related(task["project_id"])

        task_type = tasks_service.get_task_type(task["task_type_id"])
        project = projects_service.get_project(task["project_id"])
        task_status = tasks_service.get_task_status(task["task_status_id"])
        entity = entities_service.get_entity(task["entity_id"])
        entity_type = entities_service.get_entity_type(
            entity["entity_type_id"])
        assignees = []
        for assignee_id in task["assignees"]:
            assignees.append(persons_service.get_person(assignee_id))

        task.update({
            "entity": entity,
            "task_type": task_type,
            "task_status": task_status,
            "project": project,
            "entity_type": entity_type,
            "persons": assignees,
            "type": "Task"
        })

        try:
            assigner = persons_service.get_person(task["assigner_id"])
            task["assigner"] = assigner
        except PersonNotFoundException:
            pass

        if entity["parent_id"] is not None:
            sequence = shots_service.get_sequence(entity["parent_id"])
            task["sequence"] = sequence
            if sequence["parent_id"] is not None:
                episode = shots_service.get_episode(sequence["parent_id"])
                task["episode"] = episode

        return task, 200
示例#15
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"]

        tasks_service.update_task(
            task_id,
            {"task_status_id": task_status_id}
        )

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

        comment["task_status"] = task_status
        comment["person"] = person
        return comment, 201
示例#16
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