Change of the notification-reminder
Release Inventarsystem / release-docker (push) Successful in 2m15s
Release Inventarsystem / release-docker (push) Successful in 2m15s
This commit is contained in:
+29
-21
@@ -1160,8 +1160,8 @@ def _build_reminder_message(item_name, start_dt=None, end_dt=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_return_reminders():
|
def create_return_reminders_admin():
|
||||||
"""Create one-time reminders for day-1 and planned-end events."""
|
"""Create one-time reminders for day-1 and planned-end events for admins."""
|
||||||
now = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
|
now = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
|
||||||
one_day_ago = now - datetime.timedelta(days=1)
|
one_day_ago = now - datetime.timedelta(days=1)
|
||||||
|
|
||||||
@@ -1202,9 +1202,14 @@ def create_return_reminders():
|
|||||||
for borrow_doc in candidates:
|
for borrow_doc in candidates:
|
||||||
borrow_id = str(borrow_doc.get('_id'))
|
borrow_id = str(borrow_doc.get('_id'))
|
||||||
username = str(borrow_doc.get('User', '')).strip()
|
username = str(borrow_doc.get('User', '')).strip()
|
||||||
|
|
||||||
if not borrow_id or not username:
|
if not borrow_id or not username:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Falls der Benutzername verschlüsselt ist, hier entschlüsseln,
|
||||||
|
# damit der Admin den echten Namen/Ausweis lesen kann.
|
||||||
|
display_user = decrypt_text(username) if 'decrypt_text' in globals() else username
|
||||||
|
|
||||||
item_id = str(borrow_doc.get('Item', '')).strip()
|
item_id = str(borrow_doc.get('Item', '')).strip()
|
||||||
item_doc = item_docs.get(item_id, {})
|
item_doc = item_docs.get(item_id, {})
|
||||||
item_name = item_doc.get('Name') or f'Item {item_id}'
|
item_name = item_doc.get('Name') or f'Item {item_id}'
|
||||||
@@ -1215,30 +1220,33 @@ def create_return_reminders():
|
|||||||
if isinstance(start_dt, datetime.datetime) and start_dt <= one_day_ago:
|
if isinstance(start_dt, datetime.datetime) and start_dt <= one_day_ago:
|
||||||
_create_notification(
|
_create_notification(
|
||||||
db,
|
db,
|
||||||
audience='user',
|
audience='admin',
|
||||||
notif_type='return_day_1',
|
notif_type='admin_return_day_1',
|
||||||
title='Erinnerung: Rueckgabe nach 1 Tag',
|
title='Admin-Info: Ausleihe über 1 Tag aktiv',
|
||||||
message=_build_reminder_message(item_name, start_dt=start_dt, end_dt=end_dt),
|
message=f'Nutzer {display_user} hat das Medium "{item_name}" seit über einem Tag ausgeliehen.',
|
||||||
target_user=username,
|
target_user=None,
|
||||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'event': 'day_1'},
|
reference={'borrow_id': borrow_id, 'item_id': item_id, 'user': username, 'event': 'day_1'},
|
||||||
unique_key=f'reminder:day1:{borrow_id}',
|
unique_key=f'admin_reminder:day1:{borrow_id}',
|
||||||
severity='warning',
|
severity='info',
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(end_dt, datetime.datetime) and end_dt <= now:
|
if isinstance(end_dt, datetime.datetime) and end_dt <= now:
|
||||||
_create_notification(
|
_create_notification(
|
||||||
db,
|
db,
|
||||||
audience='user',
|
audience='admin',
|
||||||
notif_type='return_after_end',
|
notif_type='admin_return_after_end',
|
||||||
title='Erinnerung: Geplante Ausleihe ist beendet',
|
title='Admin-Info: Geplante Ausleihe überfällig',
|
||||||
message=_build_reminder_message(item_name, start_dt=start_dt, end_dt=end_dt),
|
message=f'Die Ausleihe von "{item_name}" durch {display_user} hat das geplante Enddatum überschritten.',
|
||||||
target_user=username,
|
target_user=None,
|
||||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'event': 'after_end'},
|
reference={'borrow_id': borrow_id, 'item_id': item_id, 'user': username, 'event': 'after_end'},
|
||||||
unique_key=f'reminder:end:{borrow_id}',
|
unique_key=f'admin_reminder:end:{borrow_id}',
|
||||||
severity='warning',
|
severity='warning',
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
app.logger.warning(f"Reminder creation failed: {exc}")
|
if 'app' in globals():
|
||||||
|
app.logger.warning(f"Admin reminder creation failed: {exc}")
|
||||||
|
else:
|
||||||
|
print(f"Admin reminder creation failed: {exc}")
|
||||||
finally:
|
finally:
|
||||||
if client:
|
if client:
|
||||||
client.close()
|
client.close()
|
||||||
@@ -3618,7 +3626,7 @@ def generate_test_ausleihen():
|
|||||||
|
|
||||||
test_ausleihungen = [
|
test_ausleihungen = [
|
||||||
{
|
{
|
||||||
"User": user_val_1,
|
"User": encrypt_text(user_val_1),
|
||||||
"Item": str(item1_res.inserted_id),
|
"Item": str(item1_res.inserted_id),
|
||||||
"Status": "active",
|
"Status": "active",
|
||||||
"DueDate": due_date_stufe1,
|
"DueDate": due_date_stufe1,
|
||||||
@@ -3626,7 +3634,7 @@ def generate_test_ausleihen():
|
|||||||
"LastUpdated": current_time
|
"LastUpdated": current_time
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"User": user_val_2,
|
"User": encrypt_text(user_val_2),
|
||||||
"Item": str(item2_res.inserted_id),
|
"Item": str(item2_res.inserted_id),
|
||||||
"Status": "active",
|
"Status": "active",
|
||||||
"DueDate": due_date_stufe2,
|
"DueDate": due_date_stufe2,
|
||||||
@@ -3634,7 +3642,7 @@ def generate_test_ausleihen():
|
|||||||
"LastUpdated": due_date_stufe2
|
"LastUpdated": due_date_stufe2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"User": user_val_3,
|
"User": encrypt_text(user_val_3),
|
||||||
"Item": str(item3_res.inserted_id),
|
"Item": str(item3_res.inserted_id),
|
||||||
"Status": "active",
|
"Status": "active",
|
||||||
"DueDate": due_date_frisch,
|
"DueDate": due_date_frisch,
|
||||||
|
|||||||
Reference in New Issue
Block a user