예제 #1
0
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
예제 #2
0
def view(id):
    authz.require(authz.watchlist_read(id))
    watchlist = obj_or_404(Watchlist.by_id(id))
    etag_cache_keygen(watchlist)
    return jsonify(watchlist)
예제 #3
0
def view(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.watchlist_read(entity.watchlist_id))
    return jsonify(entity)