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)
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'})
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)
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 })
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 })
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)
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)})
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)
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)})
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})
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 })
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'})
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'})
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'})