示例#1
0
def member_management_upgrade_user():
    log = logger.new(user_name=request.headers.get("x-webauth-user"),
                     request_id=str(uuid.uuid4()))
    log.info('api', action='convert fid to uid entry')

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

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

    post_data = request.get_json()

    fid = post_data['fid']
    uid = post_data['uid']
    signatures_missed = post_data['sigsMissed']

    logger.info('backend',
                action="upgrade freshman-%s to %s sigsMissed: %s" %
                (fid, uid, signatures_missed))
    acct = FreshmanAccount.query.filter(FreshmanAccount.id == fid).first()

    new_acct = FreshmanEvalData(uid, signatures_missed)
    new_acct.eval_date = acct.eval_date

    db.session.add(new_acct)
    for fca in FreshmanCommitteeAttendance.query.filter(
            FreshmanCommitteeAttendance.fid == fid):
        db.session.add(MemberCommitteeAttendance(uid, fca.meeting_id))
        # XXX this might fail horribly #yoloswag
        db.session.delete(fca)

    for fts in FreshmanSeminarAttendance.query.filter(
            FreshmanSeminarAttendance.fid == fid):
        db.session.add(MemberSeminarAttendance(uid, fts.seminar_id))
        # XXX this might fail horribly #yoloswag
        db.session.delete(fts)

    for fhm in FreshmanHouseMeetingAttendance.query.filter(
            FreshmanHouseMeetingAttendance.fid == fid):
        db.session.add(
            MemberHouseMeetingAttendance(uid, fhm.meeting_id, fhm.excuse,
                                         fhm.attendance_status))
        # XXX this might fail horribly #yoloswag
        db.session.delete(fhm)

    if acct.onfloor_status:
        db.session.add(OnFloorStatusAssigned(uid, datetime.now()))

    if acct.room_number:
        ldap_set_roomnumber(uid, acct.room_number)

    # XXX this might fail horribly #yoloswag
    db.session.delete(acct)

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

    clear_onfloor_members_cache()

    return jsonify({"success": True}), 200
示例#2
0
def member_management_upgrade_user(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

    post_data = request.get_json()

    fid = post_data['fid']
    uid = post_data['uid']
    signatures_missed = post_data['sigsMissed']

    log.info('Upgrade freshman-{} to Account: {}'.format(fid, uid))

    acct = FreshmanAccount.query.filter(
        FreshmanAccount.id == fid).first()

    new_acct = FreshmanEvalData(uid, signatures_missed)
    new_acct.eval_date = acct.eval_date

    db.session.add(new_acct)
    for fca in FreshmanCommitteeAttendance.query.filter(FreshmanCommitteeAttendance.fid == fid):
        db.session.add(MemberCommitteeAttendance(uid, fca.meeting_id))
        db.session.delete(fca)

    for fts in FreshmanSeminarAttendance.query.filter(FreshmanSeminarAttendance.fid == fid):
        db.session.add(MemberSeminarAttendance(uid, fts.seminar_id))
        db.session.delete(fts)

    for fhm in FreshmanHouseMeetingAttendance.query.filter(FreshmanHouseMeetingAttendance.fid == fid):
        # Don't duplicate HM attendance records
        mhm = MemberHouseMeetingAttendance.query.filter(
            MemberHouseMeetingAttendance.meeting_id == fhm.meeting_id).first()
        if mhm is None:
            db.session.add(MemberHouseMeetingAttendance(
                uid, fhm.meeting_id, fhm.excuse, fhm.attendance_status))
        else:
            log.info('Duplicate house meeting attendance! fid: {}, uid: {}, id: {}'.format(
                fid,
                uid,
                fhm.meeting_id))
        db.session.delete(fhm)

    new_account = ldap_get_member(uid)
    if acct.onfloor_status:
        db.session.add(OnFloorStatusAssigned(uid, datetime.now()))
        ldap_set_onfloor(new_account)

    if acct.room_number:
        ldap_set_roomnumber(new_account, acct.room_number)

    db.session.delete(acct)

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

    clear_members_cache()

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