def handle_annotation_event(message, sockets, session): id_ = message['annotation_id'] annotation = storage.fetch_annotation(session, id_) # FIXME: It isn't really nice to try and get the userid from the fetched # annotation or otherwise get it from the maybe-already serialized # annotation dict, to then only access the database for the nipsa flag once. # We do this because the event action is `delete` at which point we can't # load the annotation from the database. Handling annotation deletions is # a known problem and will be fixed in the future. userid = None if annotation: userid = annotation.userid else: userid = message.get('annotation_dict', {}).get('userid') nipsa_service = NipsaService(session) user_nipsad = nipsa_service.is_flagged(userid) for socket in sockets: reply = _generate_annotation_event(message, socket, annotation, user_nipsad) if reply is None: continue socket.send_json(reply)
def test_is_flagged_returns_false_for_unflagged_userids(self, db_session): svc = NipsaService(db_session) assert not svc.is_flagged('acct:[email protected]') assert not svc.is_flagged('acct:[email protected]')
def test_is_flagged_returns_true_for_flagged_userids(self, db_session): svc = NipsaService(db_session) assert svc.is_flagged('acct:[email protected]') assert svc.is_flagged('acct:[email protected]')