Ejemplo n.º 1
0
def change_room_numbers(rmnumber):
    log = logger.new(request=request)

    username = request.headers.get('x-webauth-user')
    account = ldap_get_member(username)
    update = request.get_json()

    if not ldap_is_eval_director(account):
        return "must be eval director", 403

    # Get the current list of people living on-floor.
    current_students = ldap_get_current_students()

    # Set the new room number for each person in the list.

    for occupant in update["occupants"]:
        if occupant != "":
            account = ldap_get_member(occupant)
            account.roomNumber = rmnumber
            log.info('{} assigned to room {}'.format(occupant, rmnumber))
            ldap_set_active(account)
            log.info('{} marked as active because of room assignment'.format(
                occupant))
    # Delete any old occupants that are no longer in room.
        for old_occupant in [
                account for account in current_students
                if ldap_get_roomnumber(account) == str(rmnumber)
                and account.uid not in update["occupants"]
        ]:
            log.info('{} removed from room {}'.format(old_occupant.uid,
                                                      old_occupant.roomNumber))
            old_occupant.roomNumber = None

    return jsonify({"success": True}), 200
Ejemplo n.º 2
0
def member_management_make_user_active(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)

    if not ldap_is_current_student(user_dict['account']) or ldap_is_active(user_dict['account']):
        return "must be current student and not active", 403

    ldap_set_active(user_dict['account'])
    log.info("Make user {} active".format(user_dict['username']))

    clear_members_cache()
    return jsonify({"success": True}), 200
Ejemplo n.º 3
0
def edit_uid(uid, flask_request, username):
    log = logger.new(request=flask_request, auth_dict={'username': username})
    post_data = flask_request.get_json()
    account = ldap_get_member(uid)
    active_member = post_data['activeMember']

    current_account = ldap_get_member(username)
    if ldap_is_eval_director(current_account):
        room_number = post_data['roomNumber']
        onfloor_status = post_data['onfloorStatus']
        housing_points = post_data['housingPoints']
        log.info('Edit {} - Room: {} On-Floor: {} Points: {}'.format(
            uid,
            post_data['roomNumber'],
            post_data['onfloorStatus'],
            post_data['housingPoints']))

        ldap_set_roomnumber(account, room_number)
        if onfloor_status:
            # If a OnFloorStatusAssigned object exists, don't make another
            if not ldap_is_member_of_group(account, "onfloor"):
                db.session.add(OnFloorStatusAssigned(uid, datetime.now()))
                ldap_add_member_to_group(account, "onfloor")
        else:
            for ofs in OnFloorStatusAssigned.query.filter(OnFloorStatusAssigned.uid == uid):
                db.session.delete(ofs)
            db.session.flush()
            db.session.commit()

            if ldap_is_member_of_group(account, "onfloor"):
                ldap_remove_member_from_group(account, "onfloor")
        ldap_set_housingpoints(account, housing_points)

    # Only update if there's a diff
    log.info('Set {} Active: {}'.format(uid, active_member))
    if ldap_is_active(account) != active_member:
        if active_member:
            ldap_set_active(account)
        else:
            ldap_set_inactive(account)

        if active_member:
            db.session.add(SpringEval(uid))
        else:
            SpringEval.query.filter(
                SpringEval.uid == uid and
                SpringEval.active).update(
                {
                    'active': False
                })
        clear_members_cache()
Ejemplo n.º 4
0
def member_management_make_user_active():
    log = logger.new(request=request)

    uid = request.headers.get('x-webauth-user')
    account = ldap_get_member(uid)

    if not ldap_is_current_student(account) or ldap_is_active(account):
        return "must be current student and not active", 403

    ldap_set_active(account)
    log.info("Make user {} active".format(uid))

    clear_members_cache()
    return jsonify({"success": True}), 200
Ejemplo n.º 5
0
def edit_uid(uid, user_name, post_data):
    active_member = post_data['activeMember']

    if ldap_is_eval_director(user_name):
        logger.info('backend',
                    action="edit %s room: %s onfloor: %s housepts %s" %
                    (uid, post_data['roomNumber'], post_data['onfloorStatus'],
                     post_data['housingPoints']))
        room_number = post_data['roomNumber']
        onfloor_status = post_data['onfloorStatus']
        housing_points = post_data['housingPoints']

        ldap_set_roomnumber(uid, room_number)
        if onfloor_status:
            # If a OnFloorStatusAssigned object exists, don't make another
            if not ldap_is_member_of_group(uid, "onfloor"):
                db.session.add(OnFloorStatusAssigned(uid, datetime.now()))
                ldap_add_member_to_group(uid, "onfloor")
        else:
            for ofs in OnFloorStatusAssigned.query.filter(
                    OnFloorStatusAssigned.uid == uid):
                db.session.delete(ofs)
            db.session.flush()
            db.session.commit()

            if ldap_is_member_of_group(uid, "onfloor"):
                ldap_remove_member_from_group(uid, "onfloor")
        ldap_set_housingpoints(uid, housing_points)

    # Only update if there's a diff
    logger.info('backend', action="edit %s active: %s" % (uid, active_member))
    if ldap_is_active(uid) != active_member:
        if active_member:
            ldap_set_active(uid)
        else:
            ldap_set_inactive(uid)

        if active_member:
            db.session.add(SpringEval(uid))
        else:
            SpringEval.query.filter(SpringEval.uid == uid
                                    and SpringEval.active).update(
                                        {'active': False})
        clear_active_members_cache()
Ejemplo n.º 6
0
def member_management_edituser(uid):
    log = logger.new(user_name=request.headers.get("x-webauth-user"),
                     request_id=str(uuid.uuid4()))
    log.info('api', action='edit uid user')

    user_name = request.headers.get('x-webauth-user')

    if not ldap_is_eval_director(user_name) and not ldap_is_financial_director(
            user_name):
        return "must be eval director", 403

    post_data = request.get_json()

    if not uid.isdigit():
        active_member = post_data['activeMember']

        if ldap_is_eval_director(user_name):
            logger.info(
                'backend',
                action="edit %s room: %s onfloor: %s housepts %s" %
                (uid, post_data['roomNumber'], post_data['onfloorStatus'],
                 post_data['housingPoints']))
            room_number = post_data['roomNumber']
            onfloor_status = post_data['onfloorStatus']
            housing_points = post_data['housingPoints']

            ldap_set_roomnumber(uid, room_number)
            if onfloor_status:
                ldap_add_member_to_group(uid, "onfloor")
            else:
                ldap_remove_member_from_group(uid, "onfloor")
            ldap_set_housingpoints(uid, housing_points)

        # Only update if there's a diff
        logger.info('backend',
                    action="edit %s active: %s" % (uid, active_member))
        if ldap_is_active(uid) != active_member:
            if active_member:
                ldap_set_active(uid)
            else:
                ldap_set_inactive(uid)

            if active_member:
                db.session.add(SpringEval(uid))
            else:
                SpringEval.query.filter(SpringEval.uid == uid
                                        and SpringEval.active).update(
                                            {'active': False})
            clear_active_members_cache()
    else:
        logger.info(
            'backend',
            action="edit freshman account %s room: %s onfloor: %s eval_date: %s"
            % (uid, post_data['roomNumber'], post_data['onfloorStatus'],
               post_data['evalDate']))

        name = post_data['name']
        room_number = post_data['roomNumber']
        onfloor_status = post_data['onfloorStatus']
        eval_date = post_data['evalDate']

        FreshmanAccount.query.filter(FreshmanAccount.id == uid).update({
            'name':
            name,
            'eval_date':
            datetime.strptime(eval_date, "%Y-%m-%d"),
            'onfloor_status':
            onfloor_status,
            'room_number':
            room_number
        })

    db.session.flush()
    db.session.commit()
    return jsonify({"success": True}), 200