Esempio n. 1
0
 def post(self, project_id):
     user_service.check_manager_project_access(project_id)
     task_ids = request.json
     task_ids = deletion_service.remove_tasks(project_id, task_ids)
     for task_id in task_ids:
         tasks_service.clear_task_cache(task_id)
     return task_ids, 200
Esempio n. 2
0
def remove_shot(shot_id, force=False):
    """
    Remove given shot from database. If it has tasks linked to it, it marks
    the shot as canceled. Deletion can be forced.
    """
    shot = get_shot_raw(shot_id)
    is_tasks_related = Task.query.filter_by(entity_id=shot_id).count() > 0

    if is_tasks_related and not force:
        shot.update({"canceled": True})
        clear_shot_cache(shot_id)
        events.emit("shot:update", {"shot_id": shot_id})
    else:
        from zou.app.services import tasks_service

        tasks = Task.query.filter_by(entity_id=shot_id).all()
        for task in tasks:
            deletion_service.remove_task(task.id, force=True)
            tasks_service.clear_task_cache(str(task.id))

        EntityVersion.delete_all_by(entity_id=shot_id)
        Subscription.delete_all_by(entity_id=shot_id)
        shot.delete()
        clear_shot_cache(shot_id)
        events.emit("shot:delete", {"shot_id": shot_id})

    deleted_shot = shot.serialize(obj_type="Shot")
    return deleted_shot
Esempio n. 3
0
    def import_entry(self, data):
        task = Task.get_by(shotgun_id=data["shotgun_id"])

        if task is None:
            task = Task.get_by(
                name=data["name"],
                project_id=data["project_id"],
                task_type_id=data["task_type_id"],
                entity_id=data["entity_id"],
            )

        if task is None:
            task = Task(**data)
            task.save()
            current_app.logger.info("Task created: %s" % task)
        else:
            existing_task = Task.get_by(
                name=data["name"],
                project_id=data["project_id"],
                task_type_id=data["task_type_id"],
                entity_id=data["entity_id"],
            )

            if existing_task is not None:
                data.pop("name", None)
                data.pop("project_id", None)
                data.pop("task_type_id", None)
                data.pop("entity_id", None)

            task.update(data)
            tasks_service.clear_task_cache(str(task.id))
            current_app.logger.info("Task updated: %s" % task)

        return task
Esempio n. 4
0
def remove_task(task_id, force=False):
    """
    Remove given task. Force deletion if the task has some comments and files
    related. This will lead to the deletion of all of them.
    """
    from zou.app.services import tasks_service

    task = Task.get(task_id)
    if force:
        working_files = WorkingFile.query.filter_by(task_id=task_id)
        for working_file in working_files:
            output_files = OutputFile.query.filter_by(
                source_file_id=working_file.id)
            for output_file in output_files:
                output_file.delete()
            working_file.delete()

        comments = Comment.query.filter_by(object_id=task_id)
        for comment in comments:
            notifications = Notification.query.filter_by(comment_id=comment.id)
            for notification in notifications:
                notification.delete()
            news_list = News.query.filter_by(comment_id=comment.id)
            for news in news_list:
                news.delete()
            comment.delete()

        subscriptions = Subscription.query.filter_by(task_id=task_id)
        for subscription in subscriptions:
            subscription.delete()

        preview_files = PreviewFile.query.filter_by(task_id=task_id)
        for preview_file in preview_files:
            remove_preview_file(preview_file)

        time_spents = TimeSpent.query.filter_by(task_id=task_id)
        for time_spent in time_spents:
            time_spent.delete()

        notifications = Notification.query.filter_by(task_id=task_id)
        for notification in notifications:
            notification.delete()

        news_list = News.query.filter_by(task_id=task.id)
        for news in news_list:
            news.delete()

    task.delete()
    tasks_service.clear_task_cache(task_id)
    task_serialized = task.serialize()
    events.emit(
        "task:delete",
        {
            "task_id": task_id,
            "entity_id": task_serialized["entity_id"],
            "task_type_id": task_serialized["task_type_id"],
        },
        project_id=task_serialized["project_id"],
    )
    return task_serialized
Esempio n. 5
0
def remove_asset(asset_id, force=False):
    asset = get_asset_raw(asset_id)
    is_tasks_related = Task.query.filter_by(entity_id=asset_id).count() > 0

    if is_tasks_related and not force:
        asset.update({"canceled": True})
        clear_asset_cache(str(asset_id))
        events.emit(
            "asset:update",
            {"asset_id": asset_id},
            project_id=str(asset.project_id),
        )
    else:
        from zou.app.services import tasks_service

        tasks = Task.query.filter_by(entity_id=asset_id).all()
        for task in tasks:
            deletion_service.remove_task(task.id, force=True)
            tasks_service.clear_task_cache(str(task.id))
        asset.delete()
        clear_asset_cache(str(asset_id))
        events.emit(
            "asset:delete",
            {"asset_id": asset_id},
            project_id=str(asset.project_id),
        )
    deleted_asset = asset.serialize(obj_type="Asset")
    return deleted_asset
Esempio n. 6
0
 def delete(self, project_id, task_type_id):
     """
     Delete all tasks for a given task type and project.
     ---
     tags:
     - Tasks
     description: It's mainly used when tasks are created by mistake at the beginning of the project.
     parameters:
       - in: path
         name: project_id
         required: True
         schema:
             type: UUID
             example: a24a6ea4-ce75-4665-a070-57453082c25
       - in: path
         name: task_type_id
         required: True
         schema:
             type: UUID
             example: a24a6ea4-ce75-4665-a070-57453082c25
     responses:
         204:
             description: All tasks for given task type and project deleted
     """
     permissions.check_admin_permissions()
     projects_service.get_project(project_id)
     task_ids = deletion_service.remove_tasks_for_project_and_task_type(
         project_id, task_type_id)
     for task_id in task_ids:
         tasks_service.clear_task_cache(task_id)
     return "", 204
Esempio n. 7
0
 def delete(self, project_id, task_type_id):
     permissions.check_admin_permissions()
     projects_service.get_project(project_id)
     task_ids = deletion_service.remove_tasks_for_project_and_task_type(
         project_id, task_type_id)
     for task_id in task_ids:
         tasks_service.clear_task_cache(task_id)
     return "", 204
Esempio n. 8
0
 def check_read_permissions(self, instance):
     if permissions.has_admin_permissions():
         return True
     else:
         comment = self.get_model_or_404(instance["id"])
         task_id = str(comment.object_id)
         task = tasks_service.get_task(task_id)
         if task is None:
             tasks_service.clear_task_cache(task_id)
             task = tasks_service.get_task(task_id)
         return user_service.check_project_access(task["project_id"])
Esempio n. 9
0
    def delete(self, instance_id):
        """
        Delete a model corresponding at given ID and return it as a JSON
        object.
        """
        parser = reqparse.RequestParser()
        parser.add_argument("force", default=False, type=bool)
        args = parser.parse_args()

        instance = self.get_model_or_404(instance_id)

        try:
            instance_dict = instance.serialize()
            self.check_delete_permissions(instance_dict)
            deletion_service.remove_task(instance_id, force=args["force"])
            tasks_service.clear_task_cache(instance_id)
            self.post_delete(instance_dict)

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

        return "", 204
Esempio n. 10
0
def remove_edit(edit_id, force=False):
    """
    Remove given edit from database. If it has tasks linked to it, it marks
    the edit as canceled. Deletion can be forced.
    """
    edit = get_edit_raw(edit_id)
    is_tasks_related = Task.query.filter_by(entity_id=edit_id).count() > 0

    if is_tasks_related and not force:
        edit.update({"canceled": True})
        clear_edit_cache(edit_id)
        events.emit(
            "edit:update",
            {"edit_id": edit_id},
            project_id=str(edit.project_id),
        )
    else:
        from zou.app.services import tasks_service

        tasks = Task.query.filter_by(entity_id=edit_id).all()
        for task in tasks:
            deletion_service.remove_task(task.id, force=True)
            tasks_service.clear_task_cache(str(task.id))

        EntityVersion.delete_all_by(entity_id=edit_id)
        Subscription.delete_all_by(entity_id=edit_id)
        EntityLink.delete_all_by(entity_in_id=edit_id)
        edit.delete()
        clear_edit_cache(edit_id)
        events.emit(
            "edit:delete",
            {"edit_id": edit_id},
            project_id=str(edit.project_id),
        )

    deleted_edit = edit.serialize(obj_type="Edit")
    return deleted_edit
Esempio n. 11
0
def check_comment_access(comment_id):
    """
    Return true if current user can have access to a comment.
    """
    if permissions.has_admin_permissions():
        return True
    else:
        comment = tasks_service.get_comment(comment_id)
        person_id = comment["person_id"]
        task_id = comment["object_id"]
        task = tasks_service.get_task(task_id)
        if task is None:
            tasks_service.clear_task_cache(task_id)
            task = tasks_service.get_task(task_id)
        check_project_access(task["project_id"])
        check_entity_access(task["entity_id"])

        if (
            permissions.has_supervisor_permissions()
            or permissions.has_manager_permissions()
        ):
            return True
        elif permissions.has_client_permissions():
            current_user = persons_service.get_current_user()
            project = projects_service.get_project(task["project_id"])
            if project.get("is_clients_isolated", False):
                if not comment["person_id"] == current_user["id"]:
                    raise permissions.PermissionDenied
            if persons_service.get_person(person_id)["role"] == "client":
                return True
            else:
                raise permissions.PermissionDenied
        elif persons_service.get_person(person_id)["role"] == "client":
            raise permissions.PermissionDenied

        return True
Esempio n. 12
0
 def post(self, project_id):
     """
     Delete tasks matching id list given in parameter.
     ---
     tags:
     - Tasks
     description: See it as a way to batch delete tasks.
     parameters:
       - in: path
         name: project_id
         required: True
         schema:
             type: UUID
             example: a24a6ea4-ce75-4665-a070-57453082c25
     responses:
         200:
             description: Tasks matching id list given in parameter deleted
     """
     user_service.check_manager_project_access(project_id)
     task_ids = request.json
     task_ids = deletion_service.remove_tasks(project_id, task_ids)
     for task_id in task_ids:
         tasks_service.clear_task_cache(task_id)
     return task_ids, 200
Esempio n. 13
0
 def post_update(self, instance_dict):
     tasks_service.clear_task_cache(instance_dict["id"])
Esempio n. 14
0
 def delete_func(self, entity):
     deletion_service.remove_task(entity.id)
     tasks_service.clear_task_cache(str(entity.id))