diff options
author | Max Meinhold <mxmeinhold@gmail.com> | 2021-08-19 20:53:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-19 20:53:12 -0400 |
commit | dcfe27bfa3a0e2a3afc325e1cf037ce3bd15ea10 (patch) | |
tree | e679c7c7955c06c7cb28a1bb4284d2e2df8d790d | |
parent | f6e030036d5490790e19897be9e97e03db2ff35d (diff) | |
parent | 61bef0dbf98f081a512f1c6d4ecc979fe0ba10a9 (diff) |
Merge pull request #283 from ComputerScienceHouse/hide-stuff
Hide sigs from frosh and sort by names by default
-rw-r--r-- | packet/routes/shared.py | 13 | ||||
-rw-r--r-- | packet/templates/active_packets.html | 10 | ||||
-rw-r--r-- | packet/templates/packet.html | 14 | ||||
-rw-r--r-- | packet/utils.py | 18 |
4 files changed, 47 insertions, 8 deletions
diff --git a/packet/routes/shared.py b/packet/routes/shared.py index 5b87278..3508faa 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 2be6984..343649a 100644 --- a/packet/templates/active_packets.html +++ b/packet/templates/active_packets.html @@ -7,6 +7,7 @@ <div class="col-xs-10"> <h4 class="page-title">Active Packets</h4> </div> + {% if info.is_upper %} <div class="col-xs-2"> <select id="sig-filter" class="form-control"> <option>Total</option> @@ -14,6 +15,7 @@ <option>Freshmen</option> </select> </div> + {% endif %} </div> </div> <div id="eval-blocks"> @@ -27,9 +29,11 @@ <thead> <tr> <th>Name</th> + {% if info.is_upper %} <th>Signatures</th> <th>Signatures</th> <th>Signatures</th> + {% endif %} {% if can_sign %} <th>Sign</th> {% endif %} @@ -47,6 +51,7 @@ height="25"/> {{ get_rit_name(packet.freshman_username) }} </a> </td> + {% if info.is_upper %} <td data-sort="{{ packet.signatures_received_result.member_total }}"> {% if packet.signatures_received_result.member_total == packet.signatures_required_result.member_total %} 💯 {# 100% emoji #} @@ -71,15 +76,16 @@ {{ packet.signatures_required_result.total }} {% endif %} </td> + {% endif %} {% if can_sign %} <td class="sign-packet" align="right" data-priority="1"> - {% if not packet.did_sign_result and info.uid != packet.freshman_username %} + {% if not packet.did_sign_result and info.ritdn != packet.freshman_username %} <button class="btn btn-sm btn-primary sign-button" data-packet_id="{{ packet.id }}" data-freshman_name="{{ get_rit_name(packet.freshman_username) }}"> Sign </button> - {% elif info.uid != packet.freshman_username %} + {% elif info.ritdn != packet.freshman_username %} <button class="btn btn-sm btn-primary signed-button" disabled="disabled"><i class="fa fa-check"></i> Signed diff --git a/packet/templates/packet.html b/packet/templates/packet.html index c7ddd5a..f2bb98a 100644 --- a/packet/templates/packet.html +++ b/packet/templates/packet.html @@ -20,7 +20,7 @@ class="fa fa-check"></i> Signed </button> {% endif %} - {% if info.realm == "csh" %} + {% if info.realm == "csh" and info.is_upper %} <a class="btn btn-primary" style="float: right; margin-right: 5px" href="{{ url_for('packet_graphs', packet_id=packet.id) }}"> @@ -29,6 +29,7 @@ {% endif %} </div> </div> + {% if info.is_upper or packet.freshman_username == info.ritdn %} <div class="row"> <div class="col ml-1 mb-1"> <h6>Signatures: <span class="badge badge-secondary">{{ received.total }}/{{ required.total }}</span> @@ -103,10 +104,16 @@ </div> </div> </div> + {% endif %} + {% if info.is_upper or packet.freshman_username == info.ritdn or can_sign %} <div class="card mb-2"> <div class="card-header"> <b>On-Floor Freshmen Signatures</b> + {% if info.is_upper or packet.freshman_username == info.ritdn %} <b class="signature-count">{{ received.fresh }}/{{ required.fresh }}</b> + {% else %} + <b>Signed</b> + {% endif %} </div> <div class="card-body table-fill"> <div class="table-responsive"> @@ -114,7 +121,7 @@ data-searchable="true" data-sort-column="3" data-sort-order="asc" data-length-changable="true" data-paginated="false"> <tbody> - {% 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) %} <tr {% if sig.signed %}style="background-color: #4caf505e" {% endif %}> <td> <img class="eval-user-img" alt="{{ sig.freshman_username }}" @@ -136,6 +143,8 @@ </div> </div> </div> + {% endif %} + {% if info.is_upper or packet.freshman_username == info.ritdn %} <div class="card mb-2"> <div class="card-header"> <b>Alumni & Advisor Signatures</b> @@ -178,6 +187,7 @@ </div> </div> </div> + {% endif %} </div> </div> </div> diff --git a/packet/utils.py b/packet/utils.py index ea4693b..75c9802 100644 --- a/packet/utils.py +++ b/packet/utils.py @@ -31,7 +31,9 @@ def before_request(func: WrappedFunc) -> WrappedFunc: '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 before_request(func: WrappedFunc) -> WrappedFunc: '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 |