Esempio n. 1
0
 def emit_entity(self, collection, data):
     entity = Entity.save(data, [collection], merge=True)
     db.session.commit()
     log.info("Entity [%s]: %s", entity.id, entity.name)
     update_entity(entity)
     self.increment_count()
     return entity
Esempio n. 2
0
 def emit_entity(self, collection, data):
     entity = Entity.save(data, [collection], merge=True)
     db.session.commit()
     log.info("Entity [%s]: %s", entity.id, entity.name)
     update_entity(entity)
     self.increment_count()
     return entity
Esempio n. 3
0
def delete(id):
    entity = obj_or_404(Entity.by_id(id))
    check_authz(entity, authz.WRITE)
    entity.delete()
    db.session.commit()
    update_entity(entity)
    return jsonify({'status': 'ok'})
Esempio n. 4
0
def merge(id, other_id):
    entity = obj_or_404(Entity.by_id(id))
    check_authz(entity, authz.WRITE)
    other = obj_or_404(Entity.by_id(other_id))
    check_authz(other, authz.WRITE)
    entity.merge(other)
    db.session.commit()
    update_entity(entity)
    update_entity(other)
    return view(entity.id)
Esempio n. 5
0
def create():
    data = request_data()
    data.pop('id', None)
    data['collections'] = get_collections(data)
    for collection in data['collections']:
        authz.require(authz.collection_write(collection.id))
    entity = Entity.save(data)
    for collection in entity.collections:
        collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)
Esempio n. 6
0
def create():
    data = request_data()
    data.pop('id', None)
    data['collections'] = get_collections(data)
    for collection in data['collections']:
        authz.require(authz.collection_write(collection.id))
    entity = Entity.save(data)
    for collection in entity.collections:
        collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)
Esempio n. 7
0
def merge(id, other_id):
    _, entity = get_entity(id, request.authz.WRITE)
    _, other = get_entity(other_id, request.authz.WRITE)

    try:
        entity.merge(other)
    except ValueError as ve:
        raise BadRequest(ve.message)

    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    update_entity(other)
    return view(entity.id)
Esempio n. 8
0
def update(id):
    _, entity = get_entity(id, request.authz.WRITE)

    try:
        entity = Entity.save(request_data(),
                             entity.collection,
                             merge=arg_bool('merge'))
    except (ValueError, TypeError) as ve:
        raise BadRequest(ve.message)

    entity.collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)
Esempio n. 9
0
def update(id):
    entity = obj_or_404(Entity.by_id(id))
    check_authz(entity, authz.WRITE)
    data = request_data()
    data['id'] = entity.id
    possible_collections = authz.collections(authz.WRITE)
    possible_collections.extend([c.id for c in entity.collections])
    data['collections'] = [c for c in get_collections(data)
                           if c.id in possible_collections]
    entity = Entity.save(data, merge=arg_bool('merge'))
    for collection in entity.collections:
        collection.touch()
    db.session.commit()
    update_entity(entity)
    return view(entity.id)
Esempio n. 10
0
def update(collection_id):
    collection = obj_or_404(Collection.by_id(collection_id))
    request.authz.require(request.authz.collection_write(collection))
    data = request_data()
    entity, obj = get_entity(data.get('entity_id'), request.authz.WRITE)
    if obj.collection_id != collection_id:
        raise BadRequest("Entity does not belong to collection.")

    match, _ = get_entity(data.get('match_id'), request.authz.READ)
    judgement = data.get('judgement')
    if judgement not in EntityIdentity.JUDGEMENTS:
        raise BadRequest("Invalid judgement.")
    update_lead(entity, match, judgement, judge=request.authz.role)
    log_event(request)
    update_entity(obj)
    return jsonify({'status': 'ok'})
Esempio n. 11
0
def create():
    data = request_data()
    data.pop("id", None)
    collections = get_collections(data)
    for collection in collections:
        authz.require(authz.collection_write(collection.id))

    try:
        entity = Entity.save(data, collections)
    except ValueError as ve:
        raise BadRequest(ve.message)
    for collection in entity.collections:
        collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)
Esempio n. 12
0
def update(id):
    entity = obj_or_404(Entity.by_id(id))
    check_authz(entity, authz.WRITE)
    data = request_data()
    data["id"] = entity.id
    possible_collections = authz.collections(authz.WRITE)
    possible_collections.extend([c.id for c in entity.collections])
    collections = [c for c in get_collections(data) if c.id in possible_collections]
    try:
        entity = Entity.save(data, collections, merge=arg_bool("merge"))
    except ValueError as ve:
        raise BadRequest(ve.message)
    for collection in entity.collections:
        collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)
Esempio n. 13
0
def create():
    data = request_data()
    collection_id = data.get('collection_id')
    try:
        collection_id = int(collection_id)
    except (ValueError, TypeError) as ve:
        raise BadRequest("Invalid collection_id")
    collection = obj_or_404(Collection.by_id(collection_id))
    request.authz.require(request.authz.collection_write(collection.id))

    try:
        entity = Entity.save(data, collection)
    except (ValueError, TypeError) as ve:
        raise BadRequest(ve.message)

    entity.collection.touch()
    db.session.commit()
    log_event(request, entity_id=entity.id)
    update_entity(entity)
    return view(entity.id)