Skip to content

Commit eaafd4d

Browse files
committed
Endpoints for clearing active group and rooms
1 parent 894cb9e commit eaafd4d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

conditional/blueprints/housing.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +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
1415

1516
from conditional.util.flask import render_template
1617

@@ -118,6 +119,8 @@ def change_room_numbers(rmnumber):
118119
account = ldap_get_member(occupant)
119120
account.roomNumber = rmnumber
120121
log.info('api', action='%s assigned to room %s' % (occupant, rmnumber))
122+
ldap_add_member_to_group(account, "active")
123+
log.info('api', action='%s marked as active because of room assignment' % occupant)
121124
# Delete any old occupants that are no longer in room.
122125
for old_occupant in [account for account in current_students
123126
if ldap_get_roomnumber(account) == str(rmnumber)
@@ -138,3 +141,24 @@ def get_occupants(rmnumber):
138141
occupants = [account.uid for account in current_students
139142
if ldap_get_roomnumber(account) == str(rmnumber)]
140143
return jsonify({"room": rmnumber, "occupants": occupants}), 200
144+
145+
146+
@housing_bp.route('/housing', methods=['DELETE'])
147+
def clear_all_rooms():
148+
log = logger.new(user_name=request.headers.get("x-webauth-user"),
149+
request_id=str(uuid.uuid4()))
150+
log.info('api', action='clear all room numbers')
151+
152+
username = request.headers.get('x-webauth-user')
153+
account = ldap_get_member(username)
154+
155+
if not ldap_is_eval_director(account):
156+
return "must be eval director", 403
157+
# Get list of current students.
158+
current_students = ldap_get_current_students()
159+
160+
# Find the current occupants and clear them.
161+
for occupant in current_students:
162+
log.info('api', action='remove room %s from %s' % (occupant.roomNumber, occupant.uid))
163+
occupant.roomNumber = None
164+
return jsonify({"success": True}), 200

conditional/blueprints/member_management.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,23 @@ def get_member(uid):
565565
}
566566

567567
return jsonify(account_dict), 200
568+
569+
@member_management_bp.route('/manage/active', methods=['DELETE'])
570+
def clear_active_members():
571+
log = logger.new(user_name=request.headers.get("x-webauth-user"),
572+
request_id=str(uuid.uuid4()))
573+
log.info('api', action='clear active group')
574+
575+
username = request.headers.get('x-webauth-user')
576+
account = ldap_get_member(username)
577+
578+
if not ldap_is_eval_director(account):
579+
return "must be eval director", 403
580+
# Get the active group.
581+
members = ldap_get_active_members()
582+
583+
# Clear the active group.
584+
for account in members:
585+
log.info('api', action='remove %s from active status' % account.uid)
586+
ldap_remove_member_from_group(account, 'active')
587+
return jsonify({"success": True}), 200

0 commit comments

Comments
 (0)