Skip to content

Commit 699958c

Browse files
committed
Add current student pruning
1 parent 16bed12 commit 699958c

File tree

5 files changed

+120
-21
lines changed

5 files changed

+120
-21
lines changed

conditional/blueprints/housing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from conditional.util.ldap import ldap_get_member
1212
from conditional.util.ldap import ldap_get_roomnumber
1313
from conditional.util.ldap import ldap_get_current_students
14-
from conditional.util.ldap import _ldap_add_member_to_group as ldap_add_member_to_group
14+
from conditional.util.ldap import ldap_set_active
1515

1616
from conditional.util.flask import render_template
1717

@@ -119,7 +119,7 @@ def change_room_numbers(rmnumber):
119119
account = ldap_get_member(occupant)
120120
account.roomNumber = rmnumber
121121
log.info('api', action='%s assigned to room %s' % (occupant, rmnumber))
122-
ldap_add_member_to_group(account, "active")
122+
ldap_set_active(account)
123123
log.info('api', action='%s marked as active because of room assignment' % occupant)
124124
# Delete any old occupants that are no longer in room.
125125
for old_occupant in [account for account in current_students

conditional/blueprints/member_management.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
from conditional.util.ldap import ldap_set_active
3434
from conditional.util.ldap import ldap_set_inactive
3535
from conditional.util.ldap import ldap_set_housingpoints
36+
from conditional.util.ldap import ldap_set_current_student
37+
from conditional.util.ldap import ldap_set_non_current_student
3638
from conditional.util.ldap import ldap_get_active_members
3739
from conditional.util.ldap import ldap_get_member
40+
from conditional.util.ldap import ldap_get_current_students
3841
from conditional.util.ldap import _ldap_add_member_to_group as ldap_add_member_to_group
3942
from conditional.util.ldap import _ldap_remove_member_from_group as ldap_remove_member_from_group
4043
from conditional.util.ldap import _ldap_is_member_of_group as ldap_is_member_of_group
@@ -549,7 +552,7 @@ def introductory_project_submit():
549552
def get_member(uid):
550553
log = logger.new(user_name=request.headers.get("x-webauth-user"),
551554
request_id=str(uuid.uuid4()))
552-
log.info('api', action="get %s's information" & uid)
555+
log.info('api', action="get {}'s information".format(uid))
553556

554557
username = request.headers.get('x-webauth-user')
555558
account = ldap_get_member(username)
@@ -583,9 +586,32 @@ def clear_active_members():
583586
# Clear the active group.
584587
for account in members:
585588
log.info('api', action='remove %s from active status' % account.uid)
586-
ldap_remove_member_from_group(account, 'active')
589+
ldap_set_inactive(account)
587590
return jsonify({"success": True}), 200
588591

592+
593+
@member_management_bp.route('/manage/current/<uid>', methods=['POST', 'DELETE'])
594+
def remove_current_student(uid):
595+
log = logger.new(user_name=request.headers.get("x-webauth-user"),
596+
request_id=str(uuid.uuid4()))
597+
598+
599+
username = request.headers.get('x-webauth-user')
600+
account = ldap_get_member(username)
601+
602+
if not ldap_is_eval_director(account):
603+
return "must be eval director", 403
604+
605+
member = ldap_get_member(uid)
606+
if request.method == 'DELETE':
607+
log.info('api', action='remove {} from current_student'.format(uid))
608+
ldap_set_non_current_student(member)
609+
elif request.method == 'POST':
610+
log.info('api', action='add {} to current_student'.format(uid))
611+
ldap_set_current_student(member)
612+
return jsonify({"success": True}), 200
613+
614+
589615
@member_management_bp.route('/manage/new', methods=['GET'])
590616
def new_year():
591617
log = logger.new(user_name=request.headers.get("x-webauth-user"),
@@ -598,6 +624,10 @@ def new_year():
598624
if not ldap_is_eval_director(account):
599625
return "must be eval director", 403
600626

627+
current_students = ldap_get_current_students()
628+
629+
601630
return render_template(request,
602631
'new_year.html',
603-
username=username)
632+
username=username,
633+
current_students=current_students)

conditional/templates/new_year.html

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,43 @@
77
<div id="new-welcome">
88
<h3 class="page-title">Welcome!</h3>
99
<p>Is it that time of year already? Before we get started, please <strong>be careful and ready everything before continuing</strong>. Some actions taken on the next few steps can be detrimental if followed in the middle of the year. Once you are ready to proceed, click 'Begin' below.</p>
10-
<a href="#" data-module="newYear" data-step="welcome" class="btn btn-primary btn-new-next center-block"><span class="glyphicon glyphicon-chevron-down"></span> Begin</a>
10+
<a href="#" data-module="newYear" data-step="welcome" class="btn btn-primary btn-new-next center-block"><span class="glyphicon glyphicon-ok"></span> Begin</a>
1111
</div>
1212
<div id="new-clear" style="display: none;">
1313
<h3 class="page-title">Clear Active Members and Floor Roster</h3>
1414
<p>This is the scary part. In order to get everything ready for next year, we need to clear everyone from Active status and then clear the housing board. Once we get a fresh start, we will forward you onto the housing page to fill out the new housing board.</p>
1515
<a href="#" data-module="newYear" data-step="clear" class="btn btn-primary btn-new-next center-block"><span class="glyphicon glyphicon-erase"></span> Clear Active Group and Housing Board</a>
1616
</div>
17+
<div id="new-current" style="display: none;">
18+
<h3 class="page-title">Prune Current Students Group</h3>
19+
<p>Take a second and scroll down the list, remove anyone who has graduated. Anyone in this list who is in good standing can become active, so it is important it is correct.</p>
20+
<table class="table table-striped no-bottom-margin" data-module="table" data-searchable="true" data-sort-column="0" data-sort-order="asc" data-length-changable="true">
21+
<thead>
22+
<tr>
23+
<th>Name</th>
24+
<th>Remove</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
{% for student in current_students %}
29+
<tr>
30+
<td id="row-{{student.uid}}">{{student.displayName}}</td>
31+
<td width=100px>
32+
<a href="#" data-module="newYear" data-uid="{{student.uid}}">
33+
<span id="rem-{{student.uid}}" class="glyphicon glyphicon-remove red align-center" style="width: 100%"></span>
34+
<span id="add-{{student.uid}}" class="glyphicon glyphicon-plus green align-center" style="width: 100%; display: none;"></span>
35+
</a>
36+
</td>
37+
</tr>
38+
{% endfor %}
39+
</tbody>
40+
</table>
41+
<a href="#" data-module="newYear" data-step="current" class="btn btn-primary btn-new-next center-block"><span class="glyphicon glyphicon-ok"></span> Next Step</a>
42+
</div>
1743
<div id="new-housing" style="display: none;">
1844
<h3 class="page-title">That was easy!</h3>
1945
<p>The next and final step is to go through and populate the housing board, the button below will even take you there. Just a note: adding people will automatically mark them as active, since they will be charged dues.</p>
2046
<a href="/housing" class="btn btn-primary btn-new-next center-block"><span class="glyphicon glyphicon-ok"></span> Onward and Upward!</a>
2147
</div>
2248
</div>
23-
24-
<div class="modal fade" id="loadingModal" tabindex="-1" role="dialog" aria-hidden="true">
25-
<div class="vertical-alignment-helper">
26-
<div class="modal-dialog vertical-align-center">
27-
<div class="modal-content">
28-
SPIN...
29-
</div>
30-
</div>
31-
</div>
32-
</div>
3349
{% endblock %}

conditional/util/ldap.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ def ldap_set_inactive(account):
121121
ldap_get_member.cache_clear()
122122

123123

124+
def ldap_set_current_student(account):
125+
_ldap_add_member_to_group(account, 'current_student')
126+
ldap_get_current_students.cache_clear()
127+
ldap_get_member.cache_clear()
128+
129+
130+
def ldap_set_non_current_student(account):
131+
_ldap_remove_member_from_group(account, 'current_student')
132+
ldap_get_current_students.cache_clear()
133+
ldap_get_member.cache_clear()
134+
135+
124136
def ldap_get_roomnumber(account):
125137
try:
126138
return account.roomNumber

frontend/javascript/modules/newYear.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import FetchUtil from '../utils/fetchUtil';
2+
import Exception from "../exceptions/exception";
3+
import FetchException from "../exceptions/fetchException";
4+
import sweetAlert from "../../../node_modules/bootstrap-sweetalert/dev/sweetalert.es6.js"; // eslint-disable-line max-len
25

36
export default class NewYear {
47
constructor(link) {
58
this.link = link;
69
this.step = this.link.dataset.step;
10+
this.uid = this.link.dataset.uid;
711

812
this.endpoints = {
913
housing: '/housing',
10-
active: '/manage/active'
14+
active: '/manage/active',
15+
current: '/manage/current/'
1116
};
1217

1318
this.render();
@@ -17,7 +22,7 @@ export default class NewYear {
1722
e.preventDefault();
1823

1924
if (this.step === "welcome") {
20-
$('#new-welcome').fadeOut(function() {
25+
$('#new-welcome').fadeOut(() => {
2126
$("#new-clear").fadeIn();
2227
});
2328
} else if (this.step === "clear") {
@@ -28,11 +33,47 @@ export default class NewYear {
2833
fetch(this.endpoints.housing, {
2934
method: 'DELETE'
3035
})
31-
.then($('#new-clear').fadeOut(function() {
32-
$("#new-housing").fadeIn();
36+
.then($('#new-clear').fadeOut(() => {
37+
$("#new-current").fadeIn();
3338
})
34-
);
39+
).catch(error => {
40+
sweetAlert("Uh oh...", "We're having trouble submitting that " +
41+
"action right now. Please try again later.", "error");
42+
throw new Exception(FetchException.REQUEST_FAILED, error);
43+
});
3544
});
45+
} else if (this.uid) {
46+
if ($('#rem-' + this.uid).is(":visible")) {
47+
fetch(this.endpoints.current + this.uid, {
48+
method: 'DELETE'
49+
}).then(() => {
50+
$('#rem-' + this.uid).hide();
51+
$('#add-' + this.uid).show();
52+
var userRow = $('#row-' + this.uid)[0];
53+
userRow.style.setProperty("text-decoration", "line-through");
54+
}).catch(error => {
55+
sweetAlert("Uh oh...", "We're having trouble submitting that " +
56+
"action right now. Please try again later.", "error");
57+
throw new Exception(FetchException.REQUEST_FAILED, error);
58+
});
59+
} else {
60+
fetch(this.endpoints.current + this.uid, {
61+
method: 'POST'
62+
}).then(() => {
63+
$('#add-' + this.uid).hide();
64+
$('#rem-' + this.uid).show();
65+
var lineRow = $('#row-' + this.uid)[0];
66+
lineRow.style.setProperty("text-decoration", "none");
67+
}).catch(error => {
68+
sweetAlert("Uh oh...", "We're having trouble submitting that " +
69+
"action right now. Please try again later.", "error");
70+
throw new Exception(FetchException.REQUEST_FAILED, error);
71+
});
72+
}
73+
} else if (this.step === "current") {
74+
$('#new-current').fadeOut(function() {
75+
$("#new-housing").fadeIn();
76+
});
3677
}
3778
});
3879
}

0 commit comments

Comments
 (0)