Compare commits

...

2 Commits

3 changed files with 22 additions and 5 deletions

View File

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

View File

@ -1,6 +1,7 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from enum import IntEnum from enum import IntEnum
from typing import Optional, Tuple from typing import Optional, Tuple
from flaschengeist.models import UtcDateTime
from werkzeug.exceptions import BadRequest, Conflict, NotFound from werkzeug.exceptions import BadRequest, Conflict, NotFound
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
@ -8,6 +9,7 @@ from sqlalchemy.orm.util import was_deleted
from flaschengeist import logger from flaschengeist import logger
from flaschengeist.database import db from flaschengeist.database import db
from flaschengeist.plugins import before_delete_user
from flaschengeist.utils.scheduler import scheduled from flaschengeist.utils.scheduler import scheduled
from . import EventPlugin from . import EventPlugin
@ -27,6 +29,19 @@ class NotifyType(IntEnum):
INVITATION_REJECTED = 0x11 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(): def update():
db.session.commit() db.session.commit()
@ -284,6 +299,7 @@ def assign_job(job: Job, user, value, is_backup=False):
service = Service.query.get((job.id, user.id_)) service = Service.query.get((job.id, user.id_))
if service: if service:
service.value = value service.value = value
service.is_backup = is_backup
else: else:
job.services.append(Service(user_=user, value=value, is_backup=is_backup, job_=job)) job.services.append(Service(user_=user, value=value, is_backup=is_backup, job_=job))
db.session.commit() db.session.commit()

View File

@ -22,12 +22,12 @@
"@quasar/quasar-ui-qcalendar": "^4.0.0-beta.10" "@quasar/quasar-ui-qcalendar": "^4.0.0-beta.10"
}, },
"devDependencies": { "devDependencies": {
"@flaschengeist/api": "^1.0.0-alpha.5", "@flaschengeist/api": "^1.0.0-alpha.6",
"@flaschengeist/types": "^1.0.0-alpha.8", "@flaschengeist/types": "^1.0.0-alpha.9",
"@quasar/app": "^3.2.3", "@quasar/app": "^3.2.3",
"quasar": "^2.3.3", "quasar": "^2.3.3",
"axios": "^0.24.0", "axios": "^0.24.0",
"prettier": "^2.4.1", "prettier": "^2.5.0",
"typescript": "^4.5.2", "typescript": "^4.5.2",
"pinia": "^2.0.4", "pinia": "^2.0.4",
"@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/eslint-plugin": "^5.4.0",
@ -37,8 +37,8 @@
"eslint-plugin-vue": "^8.1.1" "eslint-plugin-vue": "^8.1.1"
}, },
"peerDependencies": { "peerDependencies": {
"@flaschengeist/api": "^1.0.0-alpha.4", "@flaschengeist/api": "^1.0.0-alpha.6",
"@flaschengeist/users": "^1.0.0-alpha.1" "@flaschengeist/users": "^1.0.0-alpha.2"
}, },
"prettier": { "prettier": {
"singleQuote": true, "singleQuote": true,