Skip to content

Commit dcfe27b

Browse files
authored
Merge pull request #283 from ComputerScienceHouse/hide-stuff
Hide sigs from frosh and sort by names by default
2 parents f6e0300 + 61bef0d commit dcfe27b

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

packet/routes/shared.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,28 @@ def freshman_packet(packet_id, info=None):
3434
if info['uid'] not in map(lambda sig: sig.freshman_username, packet.fresh_signatures):
3535
can_sign = False
3636

37+
# The current user's freshman signature on this packet
38+
fresh_sig = list(filter(
39+
lambda sig: sig.freshman_username == info['ritdn'] if info else '',
40+
packet.fresh_signatures
41+
))
42+
3743
return render_template('packet.html',
3844
info=info,
3945
packet=packet,
4046
can_sign=can_sign,
4147
did_sign=packet.did_sign(info['uid'], app.config['REALM'] == 'csh'),
4248
required=packet.signatures_required(),
4349
received=packet.signatures_received(),
44-
upper=packet.upper_signatures)
50+
upper=packet.upper_signatures,
51+
fresh_sig=fresh_sig)
4552

4653

4754
def packet_sort_key(packet):
4855
"""
4956
Utility function for generating keys for sorting packets
5057
"""
51-
return packet.signatures_received_result.total, packet.did_sign_result
58+
return packet.freshman.name, -packet.signatures_received_result.total, not packet.did_sign_result
5259

5360

5461
@app.route('/packets/')
@@ -65,7 +72,7 @@ def packets(info=None):
6572
packet.signatures_received_result = packet.signatures_received()
6673
packet.signatures_required_result = packet.signatures_required()
6774

68-
open_packets.sort(key=packet_sort_key, reverse=True)
75+
open_packets.sort(key=packet_sort_key)
6976

7077
return render_template('active_packets.html', info=info, packets=open_packets)
7178

packet/templates/active_packets.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
<div class="col-xs-10">
88
<h4 class="page-title">Active Packets</h4>
99
</div>
10+
{% if info.is_upper %}
1011
<div class="col-xs-2">
1112
<select id="sig-filter" class="form-control">
1213
<option>Total</option>
1314
<option>Upperclassmen</option>
1415
<option>Freshmen</option>
1516
</select>
1617
</div>
18+
{% endif %}
1719
</div>
1820
</div>
1921
<div id="eval-blocks">
@@ -27,9 +29,11 @@ <h4 class="page-title">Active Packets</h4>
2729
<thead>
2830
<tr>
2931
<th>Name</th>
32+
{% if info.is_upper %}
3033
<th>Signatures</th>
3134
<th>Signatures</th>
3235
<th>Signatures</th>
36+
{% endif %}
3337
{% if can_sign %}
3438
<th>Sign</th>
3539
{% endif %}
@@ -47,6 +51,7 @@ <h4 class="page-title">Active Packets</h4>
4751
height="25"/> {{ get_rit_name(packet.freshman_username) }}
4852
</a>
4953
</td>
54+
{% if info.is_upper %}
5055
<td data-sort="{{ packet.signatures_received_result.member_total }}">
5156
{% if packet.signatures_received_result.member_total == packet.signatures_required_result.member_total %}
5257
💯 {# 100% emoji #}
@@ -71,15 +76,16 @@ <h4 class="page-title">Active Packets</h4>
7176
{{ packet.signatures_required_result.total }}
7277
{% endif %}
7378
</td>
79+
{% endif %}
7480
{% if can_sign %}
7581
<td class="sign-packet" align="right" data-priority="1">
76-
{% if not packet.did_sign_result and info.uid != packet.freshman_username %}
82+
{% if not packet.did_sign_result and info.ritdn != packet.freshman_username %}
7783
<button class="btn btn-sm btn-primary sign-button"
7884
data-packet_id="{{ packet.id }}"
7985
data-freshman_name="{{ get_rit_name(packet.freshman_username) }}">
8086
Sign
8187
</button>
82-
{% elif info.uid != packet.freshman_username %}
88+
{% elif info.ritdn != packet.freshman_username %}
8389
<button class="btn btn-sm btn-primary signed-button"
8490
disabled="disabled"><i
8591
class="fa fa-check"></i>&nbsp;Signed

packet/templates/packet.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3>{{ get_rit_name(packet.freshman_username) }}</h3>
2020
class="fa fa-check"></i>&nbsp;Signed
2121
</button>
2222
{% endif %}
23-
{% if info.realm == "csh" %}
23+
{% if info.realm == "csh" and info.is_upper %}
2424
<a class="btn btn-primary"
2525
style="float: right; margin-right: 5px"
2626
href="{{ url_for('packet_graphs', packet_id=packet.id) }}">
@@ -29,6 +29,7 @@ <h3>{{ get_rit_name(packet.freshman_username) }}</h3>
2929
{% endif %}
3030
</div>
3131
</div>
32+
{% if info.is_upper or packet.freshman_username == info.ritdn %}
3233
<div class="row">
3334
<div class="col ml-1 mb-1">
3435
<h6>Signatures: <span class="badge badge-secondary">{{ received.total }}/{{ required.total }}</span>
@@ -103,18 +104,24 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
103104
</div>
104105
</div>
105106
</div>
107+
{% endif %}
108+
{% if info.is_upper or packet.freshman_username == info.ritdn or can_sign %}
106109
<div class="card mb-2">
107110
<div class="card-header">
108111
<b>On-Floor Freshmen Signatures</b>
112+
{% if info.is_upper or packet.freshman_username == info.ritdn %}
109113
<b class="signature-count">{{ received.fresh }}/{{ required.fresh }}</b>
114+
{% else %}
115+
<b>Signed</b>
116+
{% endif %}
110117
</div>
111118
<div class="card-body table-fill">
112119
<div class="table-responsive">
113120
<table class="table table-striped no-bottom-margin" data-module="table"
114121
data-searchable="true" data-sort-column="3" data-sort-order="asc"
115122
data-length-changable="true" data-paginated="false">
116123
<tbody>
117-
{% for sig in packet.fresh_signatures %}
124+
{% for sig in (packet.fresh_signatures if info.is_upper or packet.freshman_username == info.ritdn else fresh_sig) %}
118125
<tr {% if sig.signed %}style="background-color: #4caf505e" {% endif %}>
119126
<td>
120127
<img class="eval-user-img" alt="{{ sig.freshman_username }}"
@@ -136,6 +143,8 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
136143
</div>
137144
</div>
138145
</div>
146+
{% endif %}
147+
{% if info.is_upper or packet.freshman_username == info.ritdn %}
139148
<div class="card mb-2">
140149
<div class="card-header">
141150
<b>Alumni & Advisor Signatures</b>
@@ -178,6 +187,7 @@ <h5>Upperclassmen Score - {{ '%0.2f' % upper_score }}%</h5>
178187
</div>
179188
</div>
180189
</div>
190+
{% endif %}
181191
</div>
182192
</div>
183193
</div>

packet/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any:
3131
'realm': 'intro',
3232
'uid': uid,
3333
'onfloor': is_freshman_on_floor(uid),
34-
'admin': False # It's always false if frosh
34+
'admin': False, # It's always false if frosh
35+
'ritdn': uid,
36+
'is_upper': False, # Always fals in intro realm
3537
}
3638
else:
3739
member = ldap.get_member(uid)
@@ -40,6 +42,8 @@ def wrapped_function(*args: list, **kwargs: dict) -> Any:
4042
'uid': uid,
4143
'admin': ldap.is_evals(member),
4244
'groups': ldap.get_groups(member),
45+
'ritdn': member.ritdn,
46+
'is_upper': not is_frosh(),
4347
}
4448

4549
kwargs['info'] = info
@@ -258,3 +262,15 @@ def sync_with_ldap() -> None:
258262
db.session.add(sig)
259263

260264
db.session.commit()
265+
266+
267+
@auth.oidc_auth('app')
268+
def is_frosh() -> bool:
269+
"""
270+
Check if the current user is a freshman.
271+
"""
272+
if app.config['REALM'] == 'csh':
273+
username = str(session['userinfo'].get('preferred_username', ''))
274+
return ldap.is_intromember(ldap.get_member(username))
275+
# Always true for the intro realm
276+
return True

0 commit comments

Comments
 (0)