"BugFix: Check user availability before staffsheet update"

This commit is contained in:
Doug Le Tough 2018-03-14 13:16:13 +01:00
parent 914d5c89b3
commit 0d221e6cc3

View File

@ -566,6 +566,18 @@ def save_staff_slot(turn_id, slot_id, user_id):
return True return True
return False return False
def check_user_availability(turn_id, user_id):
""" Check if user is available for this turn """
turn_start, turn_end = Tetawebapp_turns.query.filter(Tetawebapp_turns.id==turn_id).with_entities(Tetawebapp_turns.start_time, Tetawebapp_turns.end_time).first()
user_turns = Tetawebapp_staffs.query.filter(Tetawebapp_staffs.user_id==user_id).with_entities(Tetawebapp_staffs.turn_id).all()
for turn in user_turns:
t_start, t_end = Tetawebapp_staffs.query.filter(Tetawebapp_turns.id==turn[0]).with_entities(Tetawebapp_turns.start_time, Tetawebapp_turns.end_time).first()
if t_start <= turn_start and t_end > turn_start:
return False
if t_start >= turn_start and t_start < turn_end:
return False
return True
######################################################################## ########################################################################
# Role # Role
######################################################################## ########################################################################
@ -943,6 +955,7 @@ def update_staff_slot(TURN_ID, SLOT_ID):
user_id = session['user_id'] user_id = session['user_id']
user_name = get_user_name(user_id) user_name = get_user_name(user_id)
if user_name != None: if user_name != None:
if check_user_availability(turn_id, user_id):
if (save_staff_slot(turn_id, slot_id, user_id)): if (save_staff_slot(turn_id, slot_id, user_id)):
return user_name return user_name
return "KO" return "KO"