def extend_asset_logging_context(event):
    request = event.request
    if 'asset' in request.validated:
        params = dict()
        params['ASSET_REV'] = request.validated['asset'].rev
        params['ASSETID'] = request.validated['asset'].assetID
        params['ASSET_STATUS'] = request.validated['asset'].status
        update_logging_context(request, params)
def extend_lot_logging_context(event):
    request = event.request
    if 'lot' in request.validated:
        params = dict()
        params['LOT_REV'] = request.validated['lot'].rev
        params['LOTID'] = request.validated['lot'].lotID
        params['LOT_STATUS'] = request.validated['lot'].status
        update_logging_context(request, params)
Esempio n. 3
0
def lot_from_data(request, data, raise_error=True, create=True):
    lotType = data.get('lotType', DEFAULT_LOT_TYPE)
    model = request.registry.lotTypes.get(lotType)
    if model is None and raise_error:
        request.errors.add('body', 'lotType', 'Not implemented')
        request.errors.status = 415
        raise error_handler(request)
    update_logging_context(request, {'lot_type': lotType})
    if model is not None and create:
        model = model(data)
    return model
Esempio n. 4
0
def set_logging_context(event):
    request = event.request

    params = dict()
    params['ROLE'] = str(request.authenticated_role)
    if request.params:
        params['PARAMS'] = str(dict(request.params))
    if request.matchdict:
        for x, j in request.matchdict.items():
            params[x.upper()] = j
    update_logging_context(request, params)
Esempio n. 5
0
    def test_update_logging_context(self):
        request = mock.MagicMock()
        params = {"test_field": "test_value"}
        update_logging_context(request, params)
        self.assertEqual(request.logging_context, {'TEST_FIELD': 'test_value'})

        request.logging_context = {"A": 'b'}
        update_logging_context(request, params)
        self.assertEqual(request.logging_context, {
            'A': 'b',
            'TEST_FIELD': 'test_value'
        })
def validate_lot_data(request, error_handler, **kwargs):
    update_logging_context(request, {'lot_id': '__new__'})

    data = validate_json_data(request)

    model = request.lot_from_data(data, create=False)
    if not any([request.check_accreditation(acc) for acc in iter(str(model.create_accreditation))]):
        request.errors.add('lotType', 'accreditation',
                           'Broker Accreditation level does not permit lot creation')
        request.errors.status = 403
        raise error_handler(request.errors)

    data = validate_data(request, model, data=data)
    if data and data.get('mode', None) is None and request.check_accreditation('t'):
        request.errors.add('lotType', 'mode', 'Broker Accreditation level does not permit lot creation')
        request.errors.status = 403
        raise error_handler(request)
def validate_lot_data(request, error_handler, **kwargs):
    update_logging_context(request, {'lot_id': '__new__'})

    data = validate_json_data(request)
    model = request.lot_from_data(data, create=False)
    if not any([
            request.check_accreditation(acc)
            for acc in iter(str(model.create_accreditation))
    ]):
        request.errors.add(
            'body', 'accreditation',
            'Broker Accreditation level does not permit lot creation')
        request.errors.status = 403
        raise error_handler(request.errors)

    data = validate_data(request, model, data=data)
    if data and data.get('mode',
                         None) is None and request.check_accreditation('t'):
        request.errors.add(
            'body', 'mode',
            'Broker Accreditation level does not permit lot creation')
        request.errors.status = 403
        raise error_handler(request)
Esempio n. 8
0
def validate_file_upload(request, error_handler, **kwargs):
    update_logging_context(request, {'document_id': '__new__'})
    validate_document_data(request, error_handler, **kwargs)