def status(): return jsonify({ 'logged_in': authz.logged_in(), 'api_key': request.auth_role.api_key if authz.logged_in() else None, 'role': request.auth_role, 'roles': list(request.auth_roles), 'permissions': { 'watchlists': { 'read': authz.watchlists(authz.READ), 'write': authz.watchlists(authz.WRITE) }, 'sources': { 'read': authz.sources(authz.READ), 'write': authz.sources(authz.WRITE) } }, 'logout': url_for('.logout') })
def index(): watchlist_ids = authz.watchlists(authz.READ) filter_lists = request.args.getlist("watchlist") if len(filter_lists): try: filter_lists = [int(f) for f in filter_lists] watchlist_ids = [l for l in watchlist_ids if l in filter_lists] except ValueError: raise BadRequest() prefix = request.args.get("prefix") q = Entity.by_lists(watchlist_ids, prefix=prefix) return jsonify(Pager(q))
def entity_watchlists(q, aggs, args, filters): """ Filter entities, facet for watchlists. """ entities = args.getlist('entity') watchlists = [] readable = authz.watchlists(authz.READ) for watchlist_id in args.getlist('watchlist'): if authz.watchlist_read(watchlist_id): watchlists.append(watchlist_id) flt = { 'or': [ { 'terms': {'entities.watchlist_id': watchlists} }, { 'and': [ { 'terms': {'entities.watchlist_id': readable}, 'terms': {'entities.entity_id': entities}, } ] } ] } aggs['entities'] = { 'nested': { 'path': 'entities' }, 'aggs': { 'inner': { 'filter': flt, 'aggs': { 'entities': { 'terms': {'field': 'entity_id', 'size': 100} } } } } } return q
def index(): q = Watchlist.all(watchlist_ids=authz.watchlists(authz.READ)) q = q.order_by(Watchlist.label.asc()) return jsonify(Pager(q).to_dict())
def suggest(): watchlists = authz.watchlists(authz.READ) prefix = request.args.get("prefix") results = Entity.suggest_prefix(prefix, watchlists) return jsonify({"results": results})