Example #1
0
def update(slug):
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    source.update(request_data(), current_user)
    db.session.add(source)
    db.session.commit()
    return view(slug)
Example #2
0
def update(slug):
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    source.update(request_data(), current_user)
    db.session.add(source)
    db.session.commit()
    return view(slug)
Example #3
0
def crawl(slug):
    logging.debug('starting a crawl of %s' % slug)
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    crawl_source.delay(source.slug)
    logging.debug('started crawl')
    return jsonify({'status': 'ok'})
Example #4
0
def update(id):
    authz.require(authz.source_write(id))
    source = obj_or_404(Source.by_id(id))
    source.update(request_data())
    db.session.add(source)
    db.session.commit()
    return view(id)
Example #5
0
def update(id):
    authz.require(authz.source_write(id))
    source = obj_or_404(Source.by_id(id))
    source.update(request_data())
    db.session.add(source)
    db.session.commit()
    return view(id)
Example #6
0
def source_permissions_index(source=None):
    q = db.session.query(Permission)
    authz.require(authz.source_write(source))
    q = q.filter(Permission.resource_type == Permission.SOURCE)
    q = q.filter(Permission.resource_id == source)
    return jsonify({
        'total': q.count(),
        'results': q
    })
Example #7
0
def source_permissions_index(source=None):
    authz.require(authz.source_write(source))
    q = Permission.all()
    q = q.filter(Permission.resource_type == Permission.SOURCE)
    q = q.filter(Permission.resource_id == source)
    return jsonify({
        'total': q.count(),
        'results': q
    })
Example #8
0
def view(slug):
    authz.require(authz.source_read(slug))
    source = obj_or_404(Source.by_slug(slug))
    etag_cache_keygen(source)
    data = source.to_dict()
    data['can_write'] = authz.source_write(slug)
    if data['can_write']:
        data['users'] = [u.id for u in source.users]
        data['config'] = source.config
    return jsonify(data)
Example #9
0
def index():
    sources = []
    latest = set()
    for source in Source.all_by_user(current_user):
        data = source.to_dict()
        data['can_write'] = authz.source_write(source.slug)
        latest.add(data['updated_at'])
        sources.append(data)
    etag_cache_keygen(max(latest))
    return jsonify({'results': sources, 'total': len(sources)})
Example #10
0
def view(slug):
    authz.require(authz.source_read(slug) and authz.is_admin())
    source = obj_or_404(Source.by_slug(slug))
    etag_cache_keygen(source)
    data = source.to_dict()
    data['can_write'] = authz.source_write(slug)
    if data['can_write']:
        data['users'] = [u.id for u in source.users]
        data['config'] = source.config
    return jsonify(data)
Example #11
0
def index():
    sources = []
    latest = set()
    for source in Source.all_by_user(current_user):
        data = source.to_dict()
        data['can_write'] = authz.source_write(source.slug)
        latest.add(data['updated_at'])
        sources.append(data)
    if len(latest):
        etag_cache_keygen(max(latest))
    return jsonify({'results': sources, 'total': len(sources)})
Example #12
0
def permissions_save(collection=None, source=None):
    if collection is not None:
        authz.require(authz.collection_write(collection))
    if source is not None:
        authz.require(authz.source_write(source))

    resource_type = Permission.COLLECTION if collection else Permission.SOURCE
    resource_id = collection or source
    data = request_data()
    validate(data, 'permission.json#')

    role = Role.all().filter(Role.id == data['role']).first()
    if role is None:
        raise BadRequest()

    permission = Permission.grant_resource(resource_type, resource_id, role,
                                           data['read'], data['write'])
    db.session.commit()
    return jsonify({'status': 'ok', 'updated': permission})
Example #13
0
def permissions_save(watchlist=None, source=None):
    if watchlist is not None:
        authz.require(authz.watchlist_write(watchlist))
    if source is not None:
        authz.require(authz.source_write(source))

    resource_type = Permission.WATCHLIST if watchlist else Permission.SOURCE
    resource_id = watchlist or source
    data = request_data()
    validate(data, permissions_schema)

    role = db.session.query(Role).filter(Role.id == data['role']).first()
    if role is None:
        raise BadRequest()

    permission = Permission.grant_resource(resource_type, resource_id, role,
                                           data['read'], data['write'])
    db.session.commit()
    return jsonify({
        'status': 'ok',
        'updated': permission
    })
Example #14
0
def process(id):
    authz.require(authz.source_write(id))
    source = obj_or_404(Source.by_id(id))
    analyze_source.delay(source.id)
    return jsonify({'status': 'ok'})
Example #15
0
def process(slug):
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    process_collection.delay(source.slug)
    return jsonify({'status': 'ok'})
Example #16
0
def process(slug):
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    process_collection.delay(source.slug)
    return jsonify({'status': 'ok'})
Example #17
0
def crawl(slug):
    authz.require(authz.source_write(slug))
    source = obj_or_404(Source.by_slug(slug))
    crawl_source.delay(source.slug)
    return jsonify({'status': 'ok'})
Example #18
0
def process(id):
    authz.require(authz.source_write(id))
    source = obj_or_404(Source.by_id(id))
    analyze_source.delay(source.id)
    return jsonify({'status': 'ok'})