feat(backend): Remove deleted user from all futur services
This commit is contained in:
parent
81c33ece8c
commit
7baa274d02
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue