Exemple #1
0
def test_list_kind(db_conn, follows_table):
    """
    Expect to get follows by kind.
    """

    follows_table.insert([{
        'user_id': 'JFldl93k',
        'created': r.now(),
        'modified': r.now(),
        'entity': {
            'kind': 'card',
            'id': 'JFlsjFm',
        },
    }, {
        'user_id': 'abcd1234',
        'created': r.now(),
        'modified': r.now(),
        'entity': {
            'kind': 'card',
            'id': 'JFlsjFm',
        },
    }, {
        'user_id': 'abcd1234',
        'created': r.now(),
        'modified': r.now(),
        'entity': {
            'kind': 'unit',
            'id': 'u39Fdjf0',
        },
    }]).run(db_conn)

    assert len(list_follows({'kind': 'card'}, db_conn)) == 2
    assert len(list_follows({'kind': 'unit'}, db_conn)) == 1
Exemple #2
0
def get_follows_route(request):
    """
    Get a list of the users follows.
    """

    db_conn = request['db_conn']

    current_user = get_current_user(request)
    if not current_user:
        return abort(401)

    params = dict(**request['params'])
    params['user_id'] = current_user['id']

    follows = list_follows(params, db_conn)

    output = {
        'follows':
        [deliver_follow(follow, access='private') for follow in follows]
    }

    # TODO-3 SPLITUP should this be a different endpoint?
    if 'entities' in request['params']:
        entities = flush_entities(db_conn,
                                  [follow['entity'] for follow in follows])
        output['entities'] = [
            entity.deliver() if entity else None for entity in entities
        ]

    return 200, output
Exemple #3
0
def get_user_route(request, user_id):
    """
    Get the user by their ID.
    """

    db_conn = request['db_conn']
    user = get_user({'id': user_id}, db_conn)
    current_user = get_current_user(request)
    # Posts if in request params
    # Sets if in request params and allowed
    # Follows if in request params and allowed
    if not user:
        return abort(404)

    data = {}
    data['user'] = deliver_user(user,
                                access='private' if current_user
                                and user['id'] == current_user['id'] else None)

    # TODO-2 SPLITUP create new endpoints for these instead
    if 'posts' in request['params']:
        data['posts'] = [
            post.deliver()
            for post in get_posts_facade(db_conn, user_id=user['id'])
        ]
    if ('sets' in request['params']
            and user['settings']['view_sets'] == 'public'):
        data['sets'] = [
            set_.deliver()
            for set_ in list_user_sets_entity(user['id'], {}, db_conn)
        ]
    if ('follows' in request['params']
            and user['settings']['view_follows'] == 'public'):
        data['follows'] = [
            deliver_follow(follow)
            for follow in list_follows({'user_id': user['id']}, db_conn)
        ]
    if 'avatar' in request['params']:
        size = int(request['params']['avatar'])
        data['avatar'] = get_avatar(user['email'], size if size else None)

    return 200, data