def remove_connection_route(user_id, connection_id):
    entry = user.findUserByID(user_id)
    connection = user.findUserByID(connection_id)
    if entry is None or connection is None:
        return '', HTTP_404_NOT_FOUND

    try:
        ## TODO: improve specificity of errors
        user.remove_user_connection(connection)
        return '{}', HTTP_200_OK
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
def remove_connection_route(user_id, connection_id):
    entry = user.findUserByID(user_id)
    connection = user.findUserByID(connection_id)
    if entry is None or connection is None:
        return '', HTTP_404_NOT_FOUND

    try:
        ## TODO: improve specificity of errors
        user.remove_user_connection(connection)
        return '{}', HTTP_200_OK
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
def userEdges(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    suggested_connections = []
    pending_connections = []
    pending_connections_messages = {}

    if user_id == 'me':
        suggested_connection_users = user.get_suggested_connections(entry)
        suggested_connections = user.get_basic_info_from_users(suggested_connection_users)

        pending_connection_ids = map(lambda connection : ObjectId(connection['user']),
                                     user.get_pending_connections(entry))

        pending_connections = user.get_basic_info_from_ids(pending_connection_ids)

        map(lambda connection: pending_connections_messages.update({connection['user']:connection['message']}),
            user.get_pending_connections(entry))

    connection_ids = map(ObjectId, user.get_connections(entry))
    connections = user.get_basic_info_from_ids(connection_ids)

    annotated = {'connections': connections,
                 'suggestedConnections': suggested_connections,
                 'pendingConnections': pending_connections,
                 'pendingConnectionsMessages': pending_connections_messages,
                 'associations': []}

    return jsonify(**annotated)
def put_projects(user_id):
    """
    Example request:

    PUT
    {
    "projects":[{
            "date": "May 2015",
            "title": "some project title",
            "description": "some project description",
            "details": [{
                "title": "some project detail title",
                "description": "some project detail description"
                        }],
            "people":["54b797090adfa96230c2c1bb"]
        }]
    }

    returns status 200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_projects(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
def put_projects(user_id):
    """
    Example request:

    PUT
    {
    "projects":[{
            "date": "May 2015",
            "title": "some project title",
            "description": "some project description",
            "details": [{
                "title": "some project detail title",
                "description": "some project detail description"
                        }],
            "people":["54b797090adfa96230c2c1bb"]
        }]
    }

    returns status 200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_projects(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
Beispiel #6
0
def get_details(startup_object, current_user_id):
    qa = startup_object.qa
    if not is_owner(current_user_id, startup_object):
        # get only answered messages
        qa = filter(lambda q: q['status'] == Startup.question_status['ANSWERED'], qa)

    for qa_item in qa:
        asker_user = user.findUserByID(ObjectId(qa_item['asker']))
        qa_item['asker'] = utils.jsonFields(asker_user, user.User.basic_info_fields, response=False)

    all_people_needed = set()
    annotated_wall = []
    for wall_item in startup_object.wall:
        all_people_needed.add(wall_item['user'])
        annotated_wall_item = wall_item.copy()
        annotated_wall_item['user'] = str(annotated_wall_item['user'])
        annotated_wall.append(annotated_wall_item)

    users = {}
    for basic_info in user.get_basic_info_from_ids(list(all_people_needed)):
        users[basic_info['_id']] = basic_info

    for wall_item in annotated_wall:
        wall_item['user'] = utils.jsonFields(users[wall_item['user']], user.User.basic_info_fields, response=False)

    people_info = user.get_basic_info_from_ids(map(ObjectId, startup_object.people))
    return {'qa': qa, 'wall': annotated_wall, 'people': people_info, 'overview': startup_object.overview}
Beispiel #7
0
def post_wall(startup_object, request, current_user_id):
    msg = {'user': current_user_id, 'message': request['message'], 'date': datetime.datetime.utcnow(), 'id': str(ObjectId())}
    startup_object.wall.insert(0, msg)

    database_wrapper.save_entity(startup_object)

    msg['user'] = utils.jsonFields(user.findUserByID(current_user_id), user.User.basic_info_fields, response=False)
    return msg
def get_user_details(user_id):
    try:
        entry = user.findUserByID(user_id)
        if entry is None:
            return '', HTTP_404_NOT_FOUND
        return user.get_user_details(entry, user_id == 'me')
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
def get_user_details(user_id):
    try:
        entry = user.findUserByID(user_id)
        if entry is None:
            return '', HTTP_404_NOT_FOUND
        return user.get_user_details(entry, user_id == 'me')
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
def delete_basic_user_info(user_id, attribute):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    try:
        entry[attribute] = None
        database_wrapper.save_entity(entry)
    except:
        print sys.exc_info()[0]
        return jsonify(error='Invalid key or field cannot be deleted'), HTTP_400_BAD_REQUEST
        #return empty response with 200 status ok
    return '', HTTP_200_OK
Beispiel #11
0
def user_basic_info(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    req = request.get_json()
    try:
        utils.mergeFrom(req, entry, user.User.basic_info_fields, require=False)
        database_wrapper.save_entity(entry)
    except:
        return jsonify(error='Invalid key'), HTTP_400_BAD_REQUEST
    return '', HTTP_200_OK
def user_basic_info(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    req = request.get_json()
    try:
        utils.mergeFrom(req, entry, user.User.basic_info_fields, require=False)
        database_wrapper.save_entity(entry)
    except:
        return jsonify(error='Invalid key'), HTTP_400_BAD_REQUEST
    return '', HTTP_200_OK
Beispiel #13
0
def delete_basic_user_info(user_id, attribute):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    try:
        entry[attribute] = None
        database_wrapper.save_entity(entry)
    except:
        print sys.exc_info()[0]
        return jsonify(error='Invalid key or field cannot be deleted'
                       ), HTTP_400_BAD_REQUEST
        #return empty response with 200 status ok
    return '', HTTP_200_OK
Beispiel #14
0
def put_skills(user_id):
    """
    Example request:

    PUT
    {
    "skills":["javascript"]
    }

    returns STATUS_200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_skills(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
def put_skills(user_id):
    """
    Example request:

    PUT
    {
    "skills":["javascript"]
    }

    returns STATUS_200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_skills(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
Beispiel #16
0
def put_interests(user_id):
    """
    Example request:

    PUT
    {
     "interests":[{"title":"some title", "description":"some description"},
               {"title":"some title 2", "description":"some description 2"}]
    }

    returns STATUS_200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_interests(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
def put_interests(user_id):
    """
    Example request:

    PUT
    {
     "interests":[{"title":"some title", "description":"some description"},
               {"title":"some title 2", "description":"some description 2"}]
    }

    returns STATUS_200_OK when successful
    """
    req = request.get_json()
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    if user.put_interests(entry, req):
        return '', HTTP_200_OK
    else:
        return '', HTTP_400_BAD_REQUEST
Beispiel #18
0
def add_connection_route(user_id):
    req = request.get_json()

    # TODO: have some system so friend requests are sent
    connection_id = req.get('user')
    connection_message = req.get('message')

    if connection_id is None:
        return jsonify(error='missing field \'user\''), HTTP_400_BAD_REQUEST

    other_user = user.findUserByID(connection_id)

    if other_user is None:
        return jsonify(error='bad user'), HTTP_400_BAD_REQUEST

    try:
        ## TODO: improve specificity of errors
        user.handle_connection(other_user, connection_message)
        return '{}', HTTP_200_OK
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
def add_connection_route(user_id):
    req = request.get_json()

    # TODO: have some system so friend requests are sent
    connection_id = req.get('user')
    connection_message = req.get('message')

    if connection_id is None:
        return jsonify(error='missing field \'user\''), HTTP_400_BAD_REQUEST

    other_user = user.findUserByID(connection_id)

    if other_user is None:
        return jsonify(error='bad user'), HTTP_400_BAD_REQUEST

    try:
        ## TODO: improve specificity of errors
        user.handle_connection(other_user, connection_message)
        return '{}', HTTP_200_OK
    except Exception as e:
        return jsonify(error=str(e)), HTTP_500_INTERNAL_SERVER_ERROR
Beispiel #20
0
def userEdges(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND

    suggested_connections = []
    pending_connections = []
    pending_connections_messages = {}

    if user_id == 'me':
        suggested_connection_users = user.get_suggested_connections(entry)
        suggested_connections = user.get_basic_info_from_users(
            suggested_connection_users)

        pending_connection_ids = map(
            lambda connection: ObjectId(connection['user']),
            user.get_pending_connections(entry))

        pending_connections = user.get_basic_info_from_ids(
            pending_connection_ids)

        map(
            lambda connection: pending_connections_messages.update(
                {connection['user']: connection['message']}),
            user.get_pending_connections(entry))

    connection_ids = map(ObjectId, user.get_connections(entry))
    connections = user.get_basic_info_from_ids(connection_ids)

    annotated = {
        'connections': connections,
        'suggestedConnections': suggested_connections,
        'pendingConnections': pending_connections,
        'pendingConnectionsMessages': pending_connections_messages,
        'associations': []
    }

    return jsonify(**annotated)
Beispiel #21
0
def activate_user(user_id):
    user = findUserByID(user_id)
    user["permissionLevel"] = Auth.USER
    user.save()
    return basic_user_with_email(user)
Beispiel #22
0
def userBasicInfo(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    return user.get_basic_info_with_security(entry)
def userBasicInfo(user_id):
    entry = user.findUserByID(user_id)
    if entry is None:
        return '', HTTP_404_NOT_FOUND
    return user.get_basic_info_with_security(entry)
def activate_user(user_id):
    user = findUserByID(user_id)
    user["permissionLevel"] = Auth.USER
    user.save()
    return basic_user_with_email(user)
def elevate_user_to_admin(user_id):
    user_to_elevate = findUserByID(user_id)
    user_to_elevate["permissionLevel"] = Auth.ADMIN
    user_to_elevate.save()
    return user_to_elevate
Beispiel #26
0
def elevate_user_to_admin(user_id):
    user_to_elevate = findUserByID(user_id)
    user_to_elevate["permissionLevel"] = Auth.ADMIN
    user_to_elevate.save()
    return user_to_elevate