def sign(signer_username, freshman_username): if not valid_signature(signer_username, freshman_username): return False packet = get_freshman(freshman_username).current_packet() upper_signature = UpperSignature.query.filter( UpperSignature.member == signer_username, UpperSignature.packet == packet).first() fresh_signature = FreshSignature.query.filter( FreshSignature.freshman_username == signer_username, FreshSignature.packet == packet).first() if upper_signature: if ldap_is_intromember(ldap_get_member(signer_username)): return False upper_signature.signed = True elif fresh_signature: # Make sure only on floor freshmen can sign packets freshman_signer = get_freshman(signer_username) if freshman_signer and not freshman_signer.onfloor: return False fresh_signature.signed = True else: db.session.add(MiscSignature(packet=packet, member=signer_username)) db.session.commit() clear_cache() return True
def wrapped_function(*args, **kwargs): if app.config["REALM"] == "csh": username = str(session["userinfo"].get("preferred_username", "")) if ldap_is_intromember(ldap_get_member(username)): app.logger.warn("Stopped intro member {} from accessing upperclassmen packet".format(username)) return redirect(app.config["PROTOCOL"] + app.config["PACKET_INTRO"], code=301) return func(*args, **kwargs)
def wrapped_function(*args, **kwargs): if app.config['REALM'] == 'csh': username = str(session['userinfo'].get('preferred_username', '')) if ldap_is_intromember(ldap_get_member(username)): app.logger.warn( 'Stopped intro member {} from accessing upperclassmen packet' .format(username)) return redirect(app.config['PROTOCOL'] + app.config['PACKET_INTRO'], code=301) return func(*args, **kwargs)
def create_new_packets(base_date: date, freshmen_list: dict): packet_start_time = time(hour=19) packet_end_time = time(hour=21) start = datetime.combine(base_date, packet_start_time) end = datetime.combine(base_date, packet_end_time) + timedelta(days=14) print('Fetching data from LDAP...') all_upper = list( filter( lambda member: not ldap_is_intromember(member) and not ldap_is_on_coop(member), ldap_get_active_members())) rtp = ldap_get_active_rtps() three_da = ldap_get_3das() webmaster = ldap_get_webmasters() c_m = ldap_get_constitutional_maintainers() w_m = ldap_get_wiki_maintainers() drink = ldap_get_drink_admins() # Packet starting notifications packets_starting_notification(start) # Create the new packets and the signatures for each freshman in the given CSV print('Creating DB entries and sending emails...') for freshman in Freshman.query.filter( Freshman.rit_username.in_(freshmen_list)).all(): packet = Packet(freshman=freshman, start=start, end=end) db.session.add(packet) send_start_packet_mail(packet) packet_starting_notification(packet) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid) sig.eboard = ldap_get_eboard_role(member) sig.active_rtp = member.uid in rtp sig.three_da = member.uid in three_da sig.webmaster = member.uid in webmaster sig.c_m = member.uid in c_m sig.w_m = member.uid in w_m sig.drink_admin = member.uid in drink db.session.add(sig) for onfloor_freshman in Freshman.query.filter_by(onfloor=True).filter( Freshman.rit_username != freshman.rit_username).all(): db.session.add( FreshSignature(packet=packet, freshman=onfloor_freshman)) db.session.commit()
def sign(signer_username, freshman_username): if signer_username == freshman_username: return False freshman_signed = Freshman.query.filter_by( rit_username=freshman_username).first() if freshman_signed is None: return False packet = freshman_signed.current_packet() if packet is None or not packet.is_open(): return False upper_signature = UpperSignature.query.filter( UpperSignature.member == signer_username, UpperSignature.packet == packet).first() fresh_signature = FreshSignature.query.filter( FreshSignature.freshman_username == signer_username, FreshSignature.packet == packet).first() if upper_signature: if ldap_is_intromember(ldap_get_member(signer_username)): return False upper_signature.signed = True elif fresh_signature: # Make sure only on floor freshmen can sign packets freshman_signer = Freshman.query.filter_by( rit_username=signer_username).first() if freshman_signer and not freshman_signer.onfloor: return False fresh_signature.signed = True else: db.session.add(MiscSignature(packet=packet, member=signer_username)) db.session.commit() # Clear functions that read signatures cache get_number_signed.cache_clear() get_signatures.cache_clear() get_upperclassmen_percent.cache_clear() return True
def sync_with_ldap(): print('Fetching data from LDAP...') all_upper = { member.uid: member for member in filter( lambda member: not ldap_is_intromember(member) and not ldap_is_on_coop(member), ldap_get_active_members()) } rtp = ldap_get_active_rtps() three_da = ldap_get_3das() webmaster = ldap_get_webmasters() c_m = ldap_get_constitutional_maintainers() w_m = ldap_get_wiki_maintainers() drink = ldap_get_drink_admins() print('Applying updates to the DB...') for packet in Packet.query.filter(Packet.end > datetime.now()).all(): # Update the role state of all UpperSignatures for sig in filter(lambda sig: sig.member in all_upper, packet.upper_signatures): sig.eboard = ldap_get_eboard_role(all_upper[sig.member]) sig.active_rtp = sig.member in rtp sig.three_da = sig.member in three_da sig.webmaster = sig.member in webmaster sig.c_m = sig.member in c_m sig.w_m = sig.member in w_m sig.drink_admin = sig.member in drink # Migrate UpperSignatures that are from accounts that are not active anymore for sig in filter(lambda sig: sig.member not in all_upper, packet.upper_signatures): UpperSignature.query.filter_by(packet_id=packet.id, member=sig.member).delete() if sig.signed: sig = MiscSignature(packet=packet, member=sig.member) db.session.add(sig) # Migrate MiscSignatures that are from accounts that are now active members for sig in filter(lambda sig: sig.member in all_upper, packet.misc_signatures): MiscSignature.query.filter_by(packet_id=packet.id, member=sig.member).delete() sig = UpperSignature(packet=packet, member=sig.member, signed=True) sig.eboard = ldap_get_eboard_role(all_upper[sig.member]) sig.active_rtp = sig.member in rtp sig.three_da = sig.member in three_da sig.webmaster = sig.member in webmaster sig.c_m = sig.member in c_m sig.w_m = sig.member in w_m sig.drink_admin = sig.member in drink db.session.add(sig) # Create UpperSignatures for any new active members # pylint: disable=cell-var-from-loop upper_sigs = set(map(lambda sig: sig.member, packet.upper_signatures)) for member in filter(lambda member: member not in upper_sigs, all_upper): sig = UpperSignature(packet=packet, member=member) sig.eboard = ldap_get_eboard_role(all_upper[sig.member]) sig.active_rtp = sig.member in rtp sig.three_da = sig.member in three_da sig.webmaster = sig.member in webmaster sig.c_m = sig.member in c_m sig.w_m = sig.member in w_m sig.drink_admin = sig.member in drink db.session.add(sig) db.session.commit()