Exemple #1
0
def acquisitionFrameworkHandler(request, *, acquisition_framework, info_role):

    # Test des droits d'édition du acquisition framework si modification
    if acquisition_framework.id_acquisition_framework is not None:
        user_cruved = cruved_scope_for_user_in_module(
            id_role=info_role.id_role,
            module_code="METADATA",
        )[0]
        af_cruved = acquisition_framework.get_object_cruved(
            info_role, user_cruved)
        #verification des droits d'édition pour le acquisition framework
        if not af_cruved['U']:
            raise InsufficientRightsError(
                "User {} has no right in acquisition_framework {}".format(
                    info_role.id_role,
                    acquisition_framework.id_acquisition_framework),
                403,
            )
    else:
        acquisition_framework.id_digitizer = info_role.id_role

    acquisitionFrameworkSchema = AcquisitionFrameworkSchema()
    acquisition_framework, errors = acquisitionFrameworkSchema.load(
        request.get_json(), instance=acquisition_framework)
    if bool(errors):
        raise BadRequest(errors)

    DB.session.add(acquisition_framework)
    DB.session.commit()

    return acquisition_framework
Exemple #2
0
def acquisitionFrameworkHandler(request, *, acquisition_framework, info_role):

    # Test des droits d'édition du acquisition framework si modification
    if acquisition_framework.id_acquisition_framework is not None:
        user_cruved = get_scopes_by_action(module_code="META_DATA")

        #verification des droits d'édition pour le acquisition framework
        if not acquisition_framework.has_instance_permission(user_cruved['U']):
            raise InsufficientRightsError(
                "User {} has no right in acquisition_framework {}".format(
                    g.current_user,
                    acquisition_framework.id_acquisition_framework),
                403,
            )
    else:
        acquisition_framework.id_digitizer = info_role.id_role

    acquisitionFrameworkSchema = AcquisitionFrameworkSchema(only=[
        "cor_af_actor", "cor_volets_sinp", "cor_objectifs", "cor_territories"
    ],
                                                            unknown=EXCLUDE)
    try:
        acquisition_framework = acquisitionFrameworkSchema.load(
            request.get_json(), instance=acquisition_framework)
    except ValidationError as error:
        log.exception(error)
        raise BadRequest(error.messages)

    DB.session.add(acquisition_framework)
    DB.session.commit()

    return acquisition_framework