Add chore expiry notification system with scheduling and tests
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m59s
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m59s
- Implemented `trigger_chore_expiry.py` script to manually trigger chore expiry notifications for users via the admin API. - Developed `chore_expiry_notification_scheduler.py` to handle the logic for sending notifications for chores expiring within the next 75 minutes. - Created utility functions in `schedule_utils.py` to determine scheduling and deadlines for chores. - Added comprehensive tests for the chore expiry notification system in `test_chore_expiry_notification_scheduler.py`, covering various scenarios including scheduled chores, confirmations, and user settings.
This commit is contained in:
@@ -247,3 +247,41 @@ def send_test_digest():
|
||||
return jsonify({'items_sent': items_sent}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e), 'code': 'SERVER_ERROR'}), 500
|
||||
|
||||
|
||||
@admin_api.route('/admin/test/trigger-chore-expiry', methods=['POST'])
|
||||
def trigger_test_chore_expiry():
|
||||
"""Trigger the chore expiry notification check for a specific user by email address.
|
||||
|
||||
Only active when DB_ENV is not 'production'. Requires admin authentication.
|
||||
Note: actual push delivery requires VAPID keys to be configured.
|
||||
"""
|
||||
if os.environ.get('DB_ENV') == 'production':
|
||||
return jsonify({'error': 'Not found', 'code': 'NOT_FOUND'}), 404
|
||||
|
||||
user_id = get_validated_user_id()
|
||||
if not user_id:
|
||||
return jsonify({'error': 'Unauthorized', 'code': 'UNAUTHORIZED'}), 401
|
||||
|
||||
caller_dict = users_db.get(Query().id == user_id)
|
||||
if not caller_dict or caller_dict.get('role') != 'admin':
|
||||
return jsonify({'error': 'Admin access required', 'code': 'ADMIN_REQUIRED'}), 403
|
||||
|
||||
data = request.get_json() or {}
|
||||
email = data.get('email', '').strip().lower()
|
||||
if not email:
|
||||
return jsonify({'error': 'email is required', 'code': 'MISSING_FIELDS'}), 400
|
||||
|
||||
target = users_db.get(Query().email == email)
|
||||
if not target:
|
||||
return jsonify({'error': 'User not found', 'code': 'USER_NOT_FOUND'}), 404
|
||||
|
||||
target_id = target.get('id')
|
||||
tz_str = target.get('timezone')
|
||||
|
||||
try:
|
||||
from utils.chore_expiry_notification_scheduler import send_chore_expiry_notifications_for_user
|
||||
chores_notified = send_chore_expiry_notifications_for_user(target_id, tz_str)
|
||||
return jsonify({'chores_notified': chores_notified}), 200
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e), 'code': 'SERVER_ERROR'}), 500
|
||||
|
||||
Reference in New Issue
Block a user