def test_search_permissions(self): anno = Annotation(text='Foobar', permissions={'read': []}) anno.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 1) res = Annotation.search(_user_id='bob') h.assert_equal(len(res), 1) anno = Annotation(text='Foobar', permissions={'read': ['bob']}) anno.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 1) res = Annotation.search(_user_id='alice') h.assert_equal(len(res), 1) res = Annotation.search(_user_id='bob') h.assert_equal(len(res), 2)
def test_search_permissions(self): anno = Annotation(text='Foobar', permissions={'read': []}) anno.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 1) res = Annotation.search(_user_id='bob') h.assert_equal(len(res), 1) anno = Annotation(text='Foobar', permissions={'read': ['bob']}) anno.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 1) res = Annotation.search(_user_id='alice') h.assert_equal(len(res), 1) res = Annotation.search(_user_id='bob') h.assert_equal(len(res), 2)
def index(): uid = current_user_id() if uid: if not auth.verify_request(request): return _failed_auth_response() annotations = Annotation.search(_user_id=uid) else: annotations = Annotation.search() return jsonify(annotations)
def index(): uid = current_user_id() if uid: if not auth.verify_request(request): return _failed_auth_response() annotations = Annotation.search(_user_id=uid) else: annotations = Annotation.search() return jsonify(annotations)
def test_search(self): uri1 = u'http://xyz.com' uri2 = u'urn:uuid:xxxxx' user1 = u'levin' user2 = u'anna' anno1 = Annotation(uri=uri1, text=uri1, user=user1) anno2 = Annotation(uri=uri1, text=uri1 + uri1, user=user2) anno3 = Annotation(uri=uri2, text=uri2, user=user1) anno1.save() anno2.save() anno3.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 3) # ordering (most recent first) h.assert_equal(res[0]['text'], uri2) res = Annotation.count() h.assert_equal(res, 3) res = Annotation.search(limit=1) h.assert_equal(len(res), 1) res = Annotation.count(limit=1) h.assert_equal(res, 3) res = Annotation.search(uri=uri1) h.assert_equal(len(res), 2) h.assert_equal(res[0]['uri'], uri1) h.assert_equal(res[0]['id'], anno2.id) res = Annotation.search(user=user1) h.assert_equal(len(res), 2) h.assert_equal(res[0]['user'], user1) h.assert_equal(res[0]['id'], anno3.id) res = Annotation.search(user=user1, uri=uri2) h.assert_equal(len(res), 1) h.assert_equal(res[0]['user'], user1) h.assert_equal(res[0]['id'], anno3.id) res = Annotation.count(user=user1, uri=uri2) h.assert_equal(res, 1)
def test_search(self): uri1 = u'http://xyz.com' uri2 = u'urn:uuid:xxxxx' user1 = u'levin' user2 = u'anna' anno1 = Annotation(uri=uri1, text=uri1, user=user1) anno2 = Annotation(uri=uri1, text=uri1 + uri1, user=user2) anno3 = Annotation(uri=uri2, text=uri2, user=user1) anno1.save() anno2.save() anno3.save() annotator.es.refresh(timesleep=0.01) res = Annotation.search() h.assert_equal(len(res), 3) # ordering (most recent first) h.assert_equal(res[0]['text'], uri2) res = Annotation.count() h.assert_equal(res, 3) res = Annotation.search(limit=1) h.assert_equal(len(res), 1) res = Annotation.count(limit=1) h.assert_equal(res, 3) res = Annotation.search(uri=uri1) h.assert_equal(len(res), 2) h.assert_equal(res[0]['uri'], uri1) h.assert_equal(res[0]['id'], anno2.id) res = Annotation.search(user=user1) h.assert_equal(len(res), 2) h.assert_equal(res[0]['user'], user1) h.assert_equal(res[0]['id'], anno3.id) res = Annotation.search(user=user1, uri=uri2) h.assert_equal(len(res), 1) h.assert_equal(res[0]['user'], user1) h.assert_equal(res[0]['id'], anno3.id) res = Annotation.count(user=user1, uri=uri2) h.assert_equal(res, 1)
def home(): _require_user('to see your profile') bookmarklet = render_template('bookmarklet.js', root=current_app.config['ROOT_URL']) annotations = Annotation.search(user=g.user.username, limit=20) return render_template('user/home.html', user=g.user, bookmarklet=bookmarklet, annotations=annotations)
def home(): _require_user('to see your profile') bookmarklet = render_template('bookmarklet.js', root=current_app.config['ROOT_URL']) annotations = Annotation.search(user=g.user.username, limit=20) return render_template('user/home.html', user=g.user, bookmarklet=bookmarklet, annotations=annotations)
def search_annotations(): kwargs = dict(request.args.items()) uid = current_user_id() if uid: if not auth.verify_request(request): return _failed_auth_response() results = Annotation.search(**kwargs) results = filter(lambda a: authz.authorize(a, 'read', uid), results) total = Annotation.count(**kwargs) return jsonify({ 'total': total, 'rows': results, })
def search_annotations(): kwargs = dict(request.args.items()) uid = current_user_id() if uid: if not auth.verify_request(request): return _failed_auth_response() results = Annotation.search(**kwargs) results = filter(lambda a: authz.authorize(a, 'read', uid), results) total = Annotation.count(**kwargs) return jsonify({ 'total': total, 'rows': results, })