From 61bef0dbf98f081a512f1c6d4ecc979fe0ba10a9 Mon Sep 17 00:00:00 2001 From: Max Meinhold Date: Mon, 16 Aug 2021 04:50:08 +0000 Subject: [PATCH] Hide sigs from frosh and sort by names by default --- packet/routes/shared.py | 13 ++++++++++--- packet/templates/active_packets.html | 10 ++++++++-- packet/templates/packet.html | 14 ++++++++++++-- packet/utils.py | 18 +++++++++++++++++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/packet/routes/shared.py b/packet/routes/shared.py index 5b872786..3508faa6 100644 --- a/packet/routes/shared.py +++ b/packet/routes/shared.py @@ -34,6 +34,12 @@ def freshman_packet(packet_id, info=None): if info['uid'] not in map(lambda sig: sig.freshman_username, packet.fresh_signatures): can_sign = False + # The current user's freshman signature on this packet + fresh_sig = list(filter( + lambda sig: sig.freshman_username == info['ritdn'] if info else '', + packet.fresh_signatures + )) + return render_template('packet.html', info=info, packet=packet, @@ -41,14 +47,15 @@ def freshman_packet(packet_id, info=None): did_sign=packet.did_sign(info['uid'], app.config['REALM'] == 'csh'), required=packet.signatures_required(), received=packet.signatures_received(), - upper=packet.upper_signatures) + upper=packet.upper_signatures, + fresh_sig=fresh_sig) def packet_sort_key(packet): """ Utility function for generating keys for sorting packets """ - return packet.signatures_received_result.total, packet.did_sign_result + return packet.freshman.name, -packet.signatures_received_result.total, not packet.did_sign_result @app.route('/packets/') @@ -65,7 +72,7 @@ def packets(info=None): packet.signatures_received_result = packet.signatures_received() packet.signatures_required_result = packet.signatures_required() - open_packets.sort(key=packet_sort_key, reverse=True) + open_packets.sort(key=packet_sort_key) return render_template('active_packets.html', info=info, packets=open_packets) diff --git a/packet/templates/active_packets.html b/packet/templates/active_packets.html index 2be6984d..343649a9 100644 --- a/packet/templates/active_packets.html +++ b/packet/templates/active_packets.html @@ -7,6 +7,7 @@

Active Packets

+ {% if info.is_upper %}
+ {% endif %}
@@ -27,9 +29,11 @@

Active Packets

Name + {% if info.is_upper %} Signatures Signatures Signatures + {% endif %} {% if can_sign %} Sign {% endif %} @@ -47,6 +51,7 @@

Active Packets

height="25"/> {{ get_rit_name(packet.freshman_username) }} + {% if info.is_upper %} {% if packet.signatures_received_result.member_total == packet.signatures_required_result.member_total %} 💯 {# 100% emoji #} @@ -71,15 +76,16 @@

Active Packets

{{ packet.signatures_required_result.total }} {% endif %} + {% endif %} {% if can_sign %} - {% if not packet.did_sign_result and info.uid != packet.freshman_username %} + {% if not packet.did_sign_result and info.ritdn != packet.freshman_username %} - {% elif info.uid != packet.freshman_username %} + {% elif info.ritdn != packet.freshman_username %} {% endif %} - {% if info.realm == "csh" %} + {% if info.realm == "csh" and info.is_upper %} @@ -29,6 +29,7 @@

{{ get_rit_name(packet.freshman_username) }}

{% endif %}
+ {% if info.is_upper or packet.freshman_username == info.ritdn %}
Signatures: {{ received.total }}/{{ required.total }} @@ -103,10 +104,16 @@
Upperclassmen Score - {{ '%0.2f' % upper_score }}%
+ {% endif %} + {% if info.is_upper or packet.freshman_username == info.ritdn or can_sign %}
On-Floor Freshmen Signatures + {% if info.is_upper or packet.freshman_username == info.ritdn %} {{ received.fresh }}/{{ required.fresh }} + {% else %} + Signed + {% endif %}
@@ -114,7 +121,7 @@
Upperclassmen Score - {{ '%0.2f' % upper_score }}%
data-searchable="true" data-sort-column="3" data-sort-order="asc" data-length-changable="true" data-paginated="false"> - {% for sig in packet.fresh_signatures %} + {% for sig in (packet.fresh_signatures if info.is_upper or packet.freshman_username == info.ritdn else fresh_sig) %} {{ sig.freshman_username }}Upperclassmen Score - {{ '%0.2f' % upper_score }}%
+ {% endif %} + {% if info.is_upper or packet.freshman_username == info.ritdn %}
Alumni & Advisor Signatures @@ -178,6 +187,7 @@
Upperclassmen Score - {{ '%0.2f' % upper_score }}%
+ {% endif %} diff --git a/packet/utils.py b/packet/utils.py index ea4693b3..75c98023 100644 --- a/packet/utils.py +++ b/packet/utils.py @@ -31,7 +31,9 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any: 'realm': 'intro', 'uid': uid, 'onfloor': is_freshman_on_floor(uid), - 'admin': False # It's always false if frosh + 'admin': False, # It's always false if frosh + 'ritdn': uid, + 'is_upper': False, # Always fals in intro realm } else: member = ldap.get_member(uid) @@ -40,6 +42,8 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any: 'uid': uid, 'admin': ldap.is_evals(member), 'groups': ldap.get_groups(member), + 'ritdn': member.ritdn, + 'is_upper': not is_frosh(), } kwargs['info'] = info @@ -258,3 +262,15 @@ def sync_with_ldap() -> None: db.session.add(sig) db.session.commit() + + +@auth.oidc_auth('app') +def is_frosh() -> bool: + """ + Check if the current user is a freshman. + """ + if app.config['REALM'] == 'csh': + username = str(session['userinfo'].get('preferred_username', '')) + return ldap.is_intromember(ldap.get_member(username)) + # Always true for the intro realm + return True