Пример #1
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
Пример #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
Пример #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 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