def validate_patch_lot_data(request, error_handler, **kwargs): data = validate_json_data(request) if request.context.status != 'draft': return validate_data(request, type(request.lot), True, data) default_status = type(request.lot).fields['status'].default if data.get('status') != default_status: raise_operation_error(request, error_handler, 'Can\'t update lot in current (draft) status') request.validated['data'] = {'status': default_status} request.context.status = default_status
def validate_patch_asset_data(request, error_handler, **kwargs): data = validate_json_data(request) editing_roles = request.content_configurator.available_statuses[ request.context.status]['editing_permissions'] if request.authenticated_role not in editing_roles: msg = 'Can\'t update {} in current ({}) status'.format( request.validated['resource_type'], request.context.status) raise_operation_error(request, error_handler, msg) default_status = type(request.asset).fields['status'].default if data.get('status') == default_status and data.get( 'status') != request.context.status: raise_operation_error( request, error_handler, 'Can\'t switch asset to {} status'.format(default_status)) return validate_data(request, type(request.asset), True, data)
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_change_lot_status(request, error_handler, **kwargs): '''Validate status changes using STATUS_CHANGES rules.''' current_status = request.context.status new_status = validate_json_data(request).get('status') auth_role = request.authenticated_role if not new_status or auth_role == 'Administrator': return if new_status in STATUS_CHANGES[current_status] and \ auth_role == STATUS_CHANGES[current_status][new_status]: request.validated['data'] = {'status': new_status} else: raise_operation_error( request, error_handler, 'Can\'t update lot in current ({}) status'.format(current_status))
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)
def validate_change_asset_status(request, error_handler, **kwargs): ''' Validate method that check status changes. ''' data = validate_json_data(request) asset = request.context for status in STATUS_CHANGES: if asset.status == status: new_status = data.get('status', False) auth_role = request.authenticated_role if new_status and new_status not in STATUS_CHANGES[status].keys(): raise_operation_error( request, error_handler, 'Can\'t update asset in current ({}) status'.format( asset.status)) elif new_status and auth_role != 'Administrator' and auth_role != STATUS_CHANGES[ status].get(new_status, ''): raise_operation_error( request, error_handler, 'Can\'t update asset in current ({}) status'.format( asset.status)) request.validated['data'] = {'status': status} request.context.status = status break
def validate_patch_asset_data(request, error_handler, **kwargs): data = validate_json_data(request) if request.context.status != 'draft': return validate_data(request, type(request.asset), True, data)