예제 #1
0
def update_casting(entity_id, casting):
    """
    Update casting for given entity. Casting is an array of dictionaries made of
    two fields: `asset_id` and `nb_occurences`.
    """
    entity = entities_service.get_entity_raw(entity_id)
    entity.update({"entities_out": []})
    for cast in casting:
        if "asset_id" in cast and "nb_occurences" in cast:
            create_casting_link(
                entity.id,
                cast["asset_id"],
                nb_occurences=cast["nb_occurences"],
                label=cast.get("label", ""),
            )
    entity_id = str(entity.id)
    if shots_service.is_shot(entity.serialize()):
        events.emit(
            "shot:casting-update",
            {"shot_id": entity_id},
            project_id=str(entity.project_id),
        )
    else:
        events.emit(
            "asset:casting-update",
            {"asset_id": entity_id},
            project_id=str(entity.project_id),
        )
    return casting
예제 #2
0
def update_casting(entity_id, casting):
    """
    Update casting for given entity. Casting is an array of dictionaries made of
    two fields: `asset_id` and `nb_occurences`.
    """

    entity = entities_service.get_entity_raw(entity_id)
    entity_dict = entity.serialize(relations=True)
    if shots_service.is_episode(entity_dict):
        assets = _extract_removal(entity_dict, casting)
        for asset_id in assets:
            _remove_asset_from_episode_shots(asset_id, entity_id)
    entity.update({"entities_out": [], "entities_out_length": 0})
    for cast in casting:
        if "asset_id" in cast and "nb_occurences" in cast:
            create_casting_link(
                entity.id,
                cast["asset_id"],
                nb_occurences=cast["nb_occurences"],
                label=cast.get("label", ""),
            )
            if shots_service.is_episode(entity_dict):
                events.emit(
                    "asset:update",
                    {"asset_id": cast["asset_id"]},
                    project_id=entity.project_id,
                )

    entity_id = str(entity.id)
    nb_entities_out = len(casting)
    entity.update({"nb_entities_out": nb_entities_out})
    entity_dict = entity.serialize()
    if shots_service.is_shot(entity_dict):
        refresh_shot_casting_stats(entity_dict)
        events.emit(
            "shot:casting-update",
            {
                "shot_id": entity_id,
                "nb_entities_out": nb_entities_out
            },
            project_id=str(entity.project_id),
        )
    elif shots_service.is_episode(entity_dict):
        events.emit(
            "episode:casting-update",
            {
                "episode_id": entity_id,
                "nb_entities_out": nb_entities_out
            },
            project_id=str(entity.project_id),
        )
    else:
        events.emit(
            "asset:casting-update",
            {"asset_id": entity_id},
            project_id=str(entity.project_id),
        )
    return casting
예제 #3
0
def _check_retake_capping(task_status, task):
    if task_status["is_retake"]:
        project = projects_service.get_project(task["project_id"])
        project_max_retakes = project["max_retakes"] or 0
        if project_max_retakes > 0:
            entity = entities_service.get_entity_raw(task["entity_id"])
            entity = entities_service.get_entity(task["entity_id"])
            entity_data = entity.get("data", {}) or {}
            entity_max_retakes = entity_data.get("max_retakes", None)
            max_retakes = int(entity_max_retakes or project["max_retakes"])
            if task["retake_count"] >= max_retakes and max_retakes > 0:
                raise WrongParameterException(
                    "No more retakes allowed on this task")
    return True
예제 #4
0
    def import_row(self, row, project_id):
        asset_key = slugify("%s%s" % (row["Asset Type"], row["Asset"]))
        if row.get("Episode") == "MP":
            row["Episode"] = ""
        target_key = slugify(
            "%s%s%s" % (row.get("Episode", ""), row["Parent"], row["Name"])
        )
        occurences = 1
        if len(row["Occurences"]) > 0:
            occurences = int(row["Occurences"])

        asset_id = self.asset_map.get(asset_key, None)
        target_id = self.shot_map.get(target_key, None)
        label = slugify(row.get("Label", "fixed"))
        if target_id is None:
            target_id = self.asset_map.get(target_key, None)

        if asset_id is not None and target_id is not None:
            entity = entities_service.get_entity_raw(target_id)
            link = breakdown_service.get_entity_link_raw(target_id, asset_id)
            if link is None:
                breakdown_service.create_casting_link(
                    target_id, asset_id, occurences, label
                )
                entity.update({"nb_entities_out": entity.nb_entities_out + 1})
            else:
                link.update({"nb_occurences": occurences, "label": label})
            entity_id = str(entity.id)
            if shots_service.is_shot(entity.serialize()):
                breakdown_service.refresh_shot_casting_stats(
                    entity.serialize()
                )
                events.emit(
                    "shot:casting-update",
                    {
                        "shot_id": entity_id,
                        "nb_entities_out": entity.nb_entities_out,
                    },
                    project_id=str(entity.project_id),
                )
            else:
                events.emit(
                    "asset:casting-update",
                    {"asset_id": entity_id},
                    project_id=str(entity.project_id),
                )
예제 #5
0
def add_asset_instance_to_entity(entity_id, asset_id, description=""):
    entity = entities_service.get_entity_raw(entity_id)
    instance = AssetInstance.query \
        .filter(AssetInstance.entity_type_id == entity.entity_type_id) \
        .filter(AssetInstance.entity_id == entity_id) \
        .filter(AssetInstance.asset_id == asset_id) \
        .order_by(desc(AssetInstance.number)) \
        .first()

    number = 1
    if instance is not None:
        number = instance.number + 1

    return AssetInstance.create(asset_id=asset_id,
                                entity_id=entity_id,
                                entity_type_id=entity.entity_type_id,
                                number=number,
                                description=description).serialize()
예제 #6
0
def get_entity_casting(entity_id):
    """
    Get entities related to entity as external entities.
    """
    entity = entities_service.get_entity_raw(entity_id)
    return Entity.serialize_list(entity.entities_out, obj_type="Asset")
예제 #7
0
 def test_get_entity_raw(self):
     entity = entities_service.get_entity_raw(self.asset.id)
     self.assertEquals(entity.id, self.asset.id)
예제 #8
0
def check_metadata_department_access(entity, new_data={}):
    """
    Return true if current user is a manager and has a task assigned for this
    project or is a supervisor and is allowed to modify data accorded to
    his departments
    """
    is_allowed = False
    if permissions.has_admin_permissions() or (
        permissions.has_manager_permissions()
        and check_belong_to_project(entity["project_id"])
    ):
        is_allowed = True
    elif permissions.has_supervisor_permissions() and check_belong_to_project(
        entity["project_id"]
    ):
        # checks that the supervisor only modifies columns
        # for which he is authorized
        allowed_columns = set(["data"])
        if len(set(new_data.keys()) - allowed_columns) == 0:
            user_departments = persons_service.get_current_user(
                relations=True
            )["departments"]
            if user_departments == []:
                is_allowed = True
            else:
                entity_type = None
                if shots_service.is_shot(entity):
                    entity_type = "Shot"
                elif assets_service.is_asset(
                    entities_service.get_entity_raw(entity["id"])
                ):
                    entity_type = "Asset"
                elif edits_service.is_edit(entity):
                    entity_type = "Edit"
                if entity_type:
                    descriptors = [
                        descriptor
                        for descriptor in projects_service.get_metadata_descriptors(
                            entity["project_id"]
                        )
                        if descriptor["entity_type"] == entity_type
                    ]
                    found_and_in_departments = False
                    for descriptor_name in new_data["data"].keys():
                        found_and_in_departments = False
                        for descriptor in descriptors:
                            if descriptor["field_name"] == descriptor_name:
                                found_and_in_departments = (
                                    len(
                                        set(descriptor["departments"])
                                        & set(user_departments)
                                    )
                                    > 0
                                )
                                break
                        if not found_and_in_departments:
                            break
                    if found_and_in_departments:
                        is_allowed = True

    if not is_allowed:
        raise permissions.PermissionDenied
    return is_allowed