feat(backend): Remove deleted user from all futur services

This commit is contained in:
Ferdinand Thiessen 2021-12-02 21:30:42 +01:00
parent 81c33ece8c
commit 7baa274d02
2 changed files with 16 additions and 0 deletions

View File

@ -20,3 +20,4 @@ class EventPlugin(Plugin):
def __init__(self, cfg):
super(EventPlugin, self).__init__(cfg)
from . import routes
from .event_controller import clear_services

View File

@ -1,6 +1,7 @@
from datetime import datetime, timedelta, timezone
from enum import IntEnum
from typing import Optional, Tuple
from flaschengeist.models import UtcDateTime
from werkzeug.exceptions import BadRequest, Conflict, NotFound
from sqlalchemy.exc import IntegrityError
@ -8,6 +9,7 @@ from sqlalchemy.orm.util import was_deleted
from flaschengeist import logger
from flaschengeist.database import db
from flaschengeist.plugins import before_delete_user
from flaschengeist.utils.scheduler import scheduled
from . import EventPlugin
@ -27,6 +29,19 @@ class NotifyType(IntEnum):
INVITATION_REJECTED = 0x11
@before_delete_user
def clear_services(user):
"""
This is called when an user got deleted so it cleans future services.
It removes the deleted user from all future events.
"""
logger.debug(f"Clear deleted user {user.userid} from future events.")
_, jobs = get_jobs(user, UtcDateTime.current_utc())
for job in jobs:
job.services = list(filter(lambda s: s.user_ != user, job.services))
db.session.commit()
def update():
db.session.commit()