Exemple #1
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
Exemple #2
0
def remove_person(person_id, force=True):
    person = Person.get(person_id)
    if force:
        for comment in Comment.get_all_by(person_id=person_id):
            remove_comment(comment.id)
        comments = Comment.query.filter(
            Comment.acknowledgements.contains(person)
        )
        for comment in comments:
            comment.acknowledgements = [
                member
                for member in comment.acknowledgements
                if str(member.id) != person_id
            ]
            comment.save()
        ApiEvent.delete_all_by(user_id=person_id)
        Notification.delete_all_by(person_id=person_id)
        SearchFilter.delete_all_by(person_id=person_id)
        DesktopLoginLog.delete_all_by(person_id=person_id)
        LoginLog.delete_all_by(person_id=person_id)
        Subscription.delete_all_by(person_id=person_id)
        TimeSpent.delete_all_by(person_id=person_id)
        for project in Project.query.filter(Project.team.contains(person)):
            project.team = [
                member
                for member in project.team
                if str(member.id) != person_id
            ]
            project.save()
        for task in Task.query.filter(Task.assignees.contains(person)):
            task.assignees = [
                assignee
                for assignee in task.assignees
                if str(assignee.id) != person_id
            ]
            task.save()
        for task in Task.get_all_by(assigner_id=person_id):
            task.update({"assigner_id": None})
        for output_file in OutputFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})
        for working_file in WorkingFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})
        for task in WorkingFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})

    try:
        person.delete()
        events.emit("person:delete", {"person_id": person.id})
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to given person."
        )

    return person.serialize_safe()
Exemple #3
0
def remove_sequence(sequence_id, force=False):
    """
    Remove a sequence and all related shots.
    """
    sequence = get_sequence_raw(sequence_id)
    if force:
        for shot in Entity.get_all_by(parent_id=sequence_id):
            remove_shot(shot.id, force=True)
        Subscription.delete_all_by(entity_id=sequence_id)
    try:
        sequence.delete()
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to this sequence.")
    return sequence.serialize(obj_type="Sequence")
Exemple #4
0
def subscribe_to_task(person_id, task_id):
    """
    Add a subscription entry for given person and task.
    """
    subscription = get_task_subscription_raw(person_id, task_id)
    if subscription is None:
        subscription = Subscription.create(person_id=person_id, task_id=task_id)
    return subscription.serialize()
Exemple #5
0
def get_task_subscription_raw(person_id, task_id):
    """
    Return subscription matching given person and task.
    """
    try:
        subscription = Subscription.get_by(person_id=person_id, task_id=task_id)
        return subscription
    except StatementError:
        return None
Exemple #6
0
    def generate_fixture_subscription(self, task_id=None):
        task = self.task
        if task_id is not None:
            task = Task.get(task_id)

        self.subscription = Subscription.create(person_id=self.user["id"],
                                                task_id=task.id,
                                                entity_id=task.entity_id,
                                                task_type_id=task.task_type_id)
        return self.subscription.serialize()
def get_sequence_subscriptions(task):
    """
    Return all sequence subscriptions for given task. It returns something only
    if the task is related to a shot of which the sequence has a subscription.
    """
    sequence_subscriptions = []
    entity = Entity.get(task["entity_id"])
    if entity is not None and entity.parent_id is not None:
        sequence_subscriptions = Subscription.get_all_by(
            task_type_id=task["task_type_id"], entity_id=entity.parent_id)
    return sequence_subscriptions
Exemple #8
0
def subscribe_to_sequence(person_id, sequence_id, task_type_id):
    """
    Add a subscription entry for given person, sequence and task type.
    """
    subscription = get_sequence_subscription_raw(person_id, sequence_id,
                                                 task_type_id)
    if subscription is None:
        subscription = Subscription.create(person_id=person_id,
                                           entity_id=sequence_id,
                                           task_type_id=task_type_id)
    return subscription.serialize()
Exemple #9
0
def get_sequence_subscription_raw(person_id, sequence_id, task_type_id):
    """
    Return subscription matching given person, sequence and task type.
    """
    try:
        subscription = Subscription.get_by(person_id=person_id,
                                           entity_id=sequence_id,
                                           task_type_id=task_type_id)
        return subscription
    except StatementError:
        return None
Exemple #10
0
def remove_sequence(sequence_id, force=False):
    """
    Remove a sequence and all related shots.
    """
    sequence = get_sequence_raw(sequence_id)
    if force:
        for shot in Entity.get_all_by(parent_id=sequence_id):
            remove_shot(shot.id, force=True)
        Subscription.delete_all_by(entity_id=sequence_id)
        ScheduleItem.delete_all_by(object_id=sequence_id)
    try:
        sequence.delete()
        events.emit(
            "sequence:delete",
            {"sequence_id": sequence_id},
            project_id=str(sequence.project_id),
        )
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to this sequence.")
    clear_sequence_cache(sequence_id)
    return sequence.serialize(obj_type="Sequence")
Exemple #11
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
Exemple #12
0
def get_task_subscriptions(task):
    """
    Return all notification subscriptions related to given task.
    """
    return Subscription.get_all_by(task_id=task["id"])
Exemple #13
0
 def pre_delete(self, entity):
     if shots_service.is_sequence(entity):
         Subscription.delete_all_by(entity_id=entity["id"])
     return entity