diff --git a/backend/flaschengeist_events/event_controller.py b/backend/flaschengeist_events/event_controller.py index a3853c4..802a1d2 100644 --- a/backend/flaschengeist_events/event_controller.py +++ b/backend/flaschengeist_events/event_controller.py @@ -1,7 +1,8 @@ from datetime import datetime, timedelta, timezone from enum import IntEnum -from typing import Optional, Tuple -from flaschengeist.models import UtcDateTime +from typing import Optional, Tuple, Union +from flaschengeist.controller import userController +from flaschengeist.models import Notification, UtcDateTime from flaschengeist.models.user import User from werkzeug.exceptions import BadRequest, Conflict, NotFound @@ -364,9 +365,21 @@ def get_invitations(user: User): ).all() +def cleanup_notifications(inv: Invitation): + notifications = tuple( + filter( + lambda notification: notification.data.get("invitation") == inv.id, EventPlugin.getPlugin().notifications + ) + ) + for notification in notifications: + db.session.delete(notification) + db.session.commit() + + def cancel_invitation(inv: Invitation): db.session.delete(inv) db.session.commit() + cleanup_notifications(inv) def respond_invitation(invite: Invitation, accepted=True):