Skip to content

Commit 471f908

Browse files
authored
Merge pull request #54 from ComputerScienceHouse/develop
Hotfix 1.0.2a
2 parents db0b9b6 + 8cc2852 commit 471f908

File tree

8 files changed

+101
-14
lines changed

8 files changed

+101
-14
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ignored-argument-names = _.*
8383
max-locals = 15
8484
max-returns = 6
8585
max-branches = 12
86-
max-statements = 50
86+
max-statements = 55
8787
max-parents = 7
8888
max-attributes = 10
8989
min-public-methods = 2

conditional/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from conditional.blueprints.conditional import conditionals_bp
2525
from conditional.blueprints.member_management import member_management_bp
2626
from conditional.blueprints.slideshow import slideshow_bp
27+
from conditional.blueprints.cache_management import cache_bp
2728

2829
app.register_blueprint(dashboard_bp)
2930
app.register_blueprint(attendance_bp)
@@ -35,6 +36,7 @@
3536
app.register_blueprint(conditionals_bp)
3637
app.register_blueprint(member_management_bp)
3738
app.register_blueprint(slideshow_bp)
39+
app.register_blueprint(cache_bp)
3840

3941
logger.info('conditional started')
4042

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import structlog
2+
3+
from conditional.util.ldap import ldap_is_eval_director
4+
from conditional.util.ldap import ldap_get_housing_points
5+
from conditional.util.ldap import ldap_get_active_members
6+
from conditional.util.ldap import ldap_get_intro_members
7+
from conditional.util.ldap import ldap_get_non_alumni_members
8+
from conditional.util.ldap import ldap_get_onfloor_members
9+
from conditional.util.ldap import ldap_get_current_students
10+
from conditional.util.ldap import ldap_get_name
11+
12+
from flask import Blueprint, request, redirect
13+
14+
logger = structlog.get_logger()
15+
cache_bp = Blueprint('cache_bp', __name__)
16+
17+
18+
@cache_bp.route('/clearcache')
19+
def clear_cache():
20+
user_name = request.headers.get('x-webauth-user')
21+
22+
if not ldap_is_eval_director(user_name):
23+
return redirect("/dashboard")
24+
25+
logger.info('api', action='purge system cache')
26+
27+
ldap_get_housing_points.cache_clear()
28+
ldap_get_active_members.cache_clear()
29+
ldap_get_intro_members.cache_clear()
30+
ldap_get_non_alumni_members.cache_clear()
31+
ldap_get_onfloor_members.cache_clear()
32+
ldap_get_current_students.cache_clear()
33+
ldap_get_name.cache_clear()
34+
return "cache cleared", 200
35+
36+
37+
def clear_housing_points_cache():
38+
ldap_get_housing_points.cache_clear()
39+
40+
41+
def clear_active_members_cache():
42+
ldap_get_active_members.cache_clear()
43+
44+
45+
def clear_intro_members_cache():
46+
ldap_get_intro_members.cache_clear()
47+
48+
49+
def clear_non_alumni_cache():
50+
ldap_get_non_alumni_members.cache_clear()
51+
52+
53+
def clear_onfloor_members_cache():
54+
ldap_get_onfloor_members.cache_clear()
55+
56+
57+
def clear_current_students_cache():
58+
ldap_get_current_students.cache_clear()
59+
60+
61+
def clear_user_cache(username):
62+
ldap_get_name(username).cache_clear()

conditional/blueprints/dashboard.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from conditional.util.ldap import ldap_get_housing_points
1010
from conditional.util.ldap import ldap_is_intromember
1111
from conditional.util.ldap import ldap_get_name
12+
from conditional.util.ldap import ldap_get_active_members
13+
from conditional.util.ldap import ldap_get_intro_members
1214

1315
from conditional.models.models import FreshmanEvalData
1416
from conditional.models.models import MemberCommitteeAttendance
@@ -63,6 +65,26 @@ def get_freshman_data(user_name):
6365
return freshman
6466

6567

68+
def get_voting_members():
69+
voting_list = []
70+
active_members = [x['uid'][0].decode('utf-8') for x
71+
in ldap_get_active_members()]
72+
intro_members = [x['uid'][0].decode('utf-8') for x
73+
in ldap_get_intro_members()]
74+
passed_fall = FreshmanEvalData.query.filter(
75+
FreshmanEvalData.freshman_eval_result == "Passed"
76+
).distinct()
77+
78+
for intro_member in passed_fall:
79+
voting_list.append(intro_member.uid)
80+
81+
for active_member in active_members:
82+
if active_member not in intro_members:
83+
voting_list.append(active_member)
84+
85+
return voting_list
86+
87+
6688
@dashboard_bp.route('/dashboard/')
6789
def display_dashboard():
6890
log = logger.new(user_name=request.headers.get("x-webauth-user"),
@@ -73,6 +95,8 @@ def display_dashboard():
7395

7496
user_name = request.headers.get('x-webauth-user')
7597

98+
can_vote = get_voting_members()
99+
logger.info('backend', action=can_vote)
76100
data = dict()
77101
data['username'] = user_name
78102
data['name'] = ldap_get_name(user_name)
@@ -81,7 +105,7 @@ def display_dashboard():
81105
# On-Floor Status
82106
data['onfloor'] = ldap_is_onfloor(user_name)
83107
# Voting Status
84-
data['voting'] = ldap_is_active(user_name) # FIXME: unimplemented
108+
data['voting'] = bool(user_name in can_vote)
85109

86110
# freshman shit
87111
if ldap_is_intromember(user_name):

conditional/blueprints/member_management.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from conditional.models.models import OnFloorStatusAssigned
2222
from conditional.models.models import SpringEval
2323

24+
from conditional.blueprints.cache_management import clear_active_members_cache
25+
from conditional.blueprints.cache_management import clear_onfloor_members_cache
26+
2427
from conditional.util.ldap import ldap_is_eval_director
2528
from conditional.util.ldap import ldap_is_financial_director
2629
from conditional.util.ldap import ldap_set_roomnumber
@@ -261,6 +264,7 @@ def member_management_edituser(uid):
261264
{
262265
'active': False
263266
})
267+
clear_active_members_cache()
264268
else:
265269
logger.info('backend', action="edit freshman account %s room: %s onfloor: %s eval_date: %s" %
266270
(uid, post_data['roomNumber'], post_data['onfloorStatus'],
@@ -454,4 +458,7 @@ def member_management_upgrade_user():
454458

455459
db.session.flush()
456460
db.session.commit()
461+
462+
clear_onfloor_members_cache()
463+
457464
return jsonify({"success": True}), 200

conditional/templates/intro_evals.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ <h6 class="eval-uid">{{m['uid']}}</h6>
2828
<div class="text-center">
2929
{% if m['signatures_missed'] > 0 %}
3030
<div class="eval-info-label danger">Signatures Missed: {{m['signatures_missed']}}</div>
31+
{% elif m['signatures_missed'] == 65535 %}
32+
<div class="eval-info-label warning">Packet Not Yet Complete</div>
3133
{% else %}
3234
<div class="eval-info-label success">Signatures Missed: {{m['signatures_missed']}}</div>
3335
{% endif %}

conditional/util/ldap.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,4 @@ def ldap_set_inactive(username):
240240

241241
@lru_cache(maxsize=1024)
242242
def ldap_get_name(username):
243-
first = __ldap_get_field__(username, 'givenName')
244-
if first is None:
245-
first = ""
246-
else:
247-
first = first.decode('utf-8')
248-
last = __ldap_get_field__(username, 'sn')
249-
if last is None:
250-
last = ""
251-
else:
252-
last = last.decode('utf-8')
253-
return "{first} {last}".format(first=first, last=last)
243+
return __ldap_get_field__(username, 'cn').decode('utf-8')

frontend/stylesheets/partials/_global.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141

4242
.warning {
43-
background-color: #ff3207;
43+
background-color: #fb3;
4444
}
4545

4646
.success {

0 commit comments

Comments
 (0)