def update(id): collection = get_db_collection(id, request.authz.WRITE) data = parse_request(CollectionSchema) collection.update(data) db.session.commit() update_collection(collection) return serialize_data(collection, CollectionSchema)
def create(): require(not request.authz.in_maintenance, settings.PASSWORD_LOGIN) data = parse_request(RoleCreateSchema) try: email = Role.SIGNATURE.loads(data.get('code'), max_age=Role.SIGNATURE_MAX_AGE) except BadSignature: return jsonify({ 'status': 'error', 'message': gettext('Invalid code') }, status=400) role = Role.by_email(email) if role is not None: return jsonify( { 'status': 'error', 'message': gettext('Email is already registered') }, status=409) role = Role.load_or_create(foreign_id='password:{}'.format(email), type=Role.USER, name=data.get('name') or email, email=email) role.set_password(data.get('password')) db.session.add(role) update_role(role) db.session.commit() # Let the serializer return more info about this user request.authz.id = role.id return serialize_data(role, RoleSchema, status=201)
def create(): require(request.authz.logged_in) data = parse_request(CollectionSchema) role = Role.by_id(request.authz.id) sync = get_flag('sync') collection = create_collection(data, role=role, sync=sync) return serialize_data(collection, CollectionSchema)
def update(id): collection = get_db_collection(id, request.authz.WRITE) data = parse_request(CollectionSchema) sync = get_flag('sync') collection.update(data) db.session.commit() data = update_collection(collection, sync=sync) return serialize_data(data, CollectionSchema)
def create(): data = parse_request(EntityCreateSchema) collection = get_db_collection(data['collection_id'], request.authz.WRITE) entity = Entity.create(data, collection) db.session.commit() data = update_entity(entity) update_collection(collection) return serialize_data(data, CombinedSchema)
def record(document_id, index): enable_cache() document = get_db_document(document_id) if not document.supports_records: raise BadRequest("This document does not have records.") record = DocumentRecord.by_index(document.id, index) if record is None: raise NotFound("No such record: %s" % index) return serialize_data(record, RecordSchema)
def update(id): entity = get_db_entity(id, request.authz.WRITE) data = parse_request(EntityUpdateSchema) if get_flag('merge'): props = merge_data(data.get('properties'), entity.data) data['properties'] = props entity.update(data) db.session.commit() data = update_entity(entity, sync=get_flag('sync', True)) return serialize_data(data, CombinedSchema)
def update(id): role = obj_or_404(Role.by_id(id)) require(request.authz.session_write) require(check_editable(role, request.authz)) data = parse_request(RoleSchema) role.update(data) db.session.add(role) db.session.commit() update_role(role) return serialize_data(role, RoleSchema)
def update(id): entity = get_db_entity(id, request.authz.WRITE) data = parse_request(EntityUpdateSchema) if as_bool(request.args.get('merge')): props = merge_data(data.get('properties'), entity.data) data['properties'] = props entity.update(data) db.session.commit() data = update_entity(entity) update_collection(entity.collection) return serialize_data(data, CombinedSchema)
def merge(id, other_id): entity = get_db_entity(id, request.authz.WRITE) other = get_db_entity(other_id, request.authz.WRITE) try: entity.merge(other) except ValueError as ve: raise BadRequest(ve.message) db.session.commit() data = update_entity(entity) update_entity(other) update_collection(entity.collection) return serialize_data(data, CombinedSchema)
def merge(id, other_id): entity = get_db_entity(id, request.authz.WRITE) other = get_db_entity(other_id, request.authz.WRITE) try: entity.merge(other) except ValueError as ve: raise BadRequest(ve.message) db.session.commit() sync = get_flag('sync', True) data = update_entity(entity, sync=sync) update_entity(other, sync=sync) return serialize_data(data, CombinedSchema)
def view(document_id): enable_cache() data = get_index_document(document_id) document = get_db_document(document_id) data['headers'] = document.headers # TODO: should this be it's own API? Probably so, but for that it would # be unclear if we should JSON wrap it, or serve plain with the correct # MIME type? if Document.SCHEMA_HTML in document.model.names: data['html'] = sanitize_html(document.body_raw, document.source_url) if Document.SCHEMA_TEXT in document.model.names: data['text'] = document.body_text if Document.SCHEMA_IMAGE in document.model.names: data['text'] = document.body_text return serialize_data(data, CombinedSchema)
def view(id): role = obj_or_404(Role.by_id(id)) require(check_editable(role, request.authz)) return serialize_data(role, RoleSchema)
def view(id): entity = get_index_entity(id, request.authz.READ) return serialize_data(entity, CombinedSchema)
def create(): data = parse_request(EntityCreateSchema) collection = get_db_collection(data['collection_id'], request.authz.WRITE) data = create_entity(data, collection, sync=get_flag('sync', True)) return serialize_data(data, CombinedSchema)
def view(id): collection = get_index_collection(id) return serialize_data(collection, CollectionSchema)
def view(id): collection = get_index_collection(id) record_audit(Audit.ACT_COLLECTION, id=id) return serialize_data(collection, CollectionSchema)
def view(id): entity = get_index_entity(id, request.authz.READ) record_audit(Audit.ACT_ENTITY, id=id) return serialize_data(entity, CombinedSchema)
def view(id): require(request.authz.logged_in) alert = obj_or_404(Alert.by_id(id, role_id=request.authz.id)) return serialize_data(alert, AlertSchema)
def create(): require(request.authz.session_write) data = parse_request(AlertSchema) alert = Alert.create(data, request.authz.id) db.session.commit() return serialize_data(alert, AlertSchema)