From c721f251043c45717f3dea0e411a7d793f3b1dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 1 May 2023 22:06:24 +0200 Subject: [PATCH] delete unnecessary notifications --- .../flaschengeist_events/event_controller.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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):