예제 #1
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()
예제 #2
0
def clear_active_members(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)

    if not ldap_is_eval_director(user_dict['account']):
        return "must be eval director", 403
    # Get the active group.
    members = ldap_get_active_members()

    # Clear the active group.
    for account in members:
        if account.uid != user_dict['username']:
            log.info('Remove {} from Active Status'.format(account.uid))
            ldap_set_inactive(account)
    return jsonify({"success": True}), 200
예제 #3
0
def clear_active_members():
    log = logger.new(request=request)

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

    if not ldap_is_eval_director(account):
        return "must be eval director", 403
    # Get the active group.
    members = ldap_get_active_members()

    # Clear the active group.
    for account in members:
        if account.uid != username:
            log.info('Remove {} from Active Status'.format(account.uid))
            ldap_set_inactive(account)
    return jsonify({"success": True}), 200
예제 #4
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()
예제 #5
0
def slideshow_spring_review(user_dict=None):
    log = logger.new(request=request, auth_dict=user_dict)

    if not ldap_is_eval_director(user_dict['account']):
        return redirect("/dashboard", code=302)

    post_data = request.get_json()
    uid = post_data['uid']
    status = post_data['status']

    log.info('Spring Eval for {}: {}'.format(uid, status))

    SpringEval.query.filter(
        SpringEval.uid == uid and
        SpringEval.active). \
        update(
        {
            'status': status
        })

    db.session.flush()
    db.session.commit()

    # Automate ldap group organizing
    account = ldap_get_member(uid)

    if status == "Passed":
        if ldap_is_intromember(account):
            ldap_set_not_intro_member(account)
    elif status == "Failed":
        if ldap_is_intromember(account):
            ldap_set_failed(account)
            ldap_set_inactive(account)
        else:
            ldap_set_bad_standing(account)

    return jsonify({"success": True}), 200
예제 #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