Compare commits

..

2 Commits

4 changed files with 37 additions and 14 deletions

View File

@ -33,6 +33,7 @@ class Plugin:
blueprint = None # You have to override
permissions = [] # You have to override
id = "dev.flaschengeist.plugin" # You have to override
name = "plugin" # You have to override
models = None # You have to override
@ -94,7 +95,7 @@ class Plugin:
db.session.commit()
def notify(self, user, text: str, data=None):
n = Notification(text=text, data=data, plugin=self.name, user_=user)
n = Notification(text=text, data=data, plugin=self.id, user_=user)
db.session.add(n)
db.session.commit()

View File

@ -11,6 +11,7 @@ from . import permissions, models
class EventPlugin(Plugin):
name = "events"
id = "dev.flaschengeist.events"
plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.name])
permissions = permissions.permissions
blueprint = Blueprint(name, __name__)

View File

@ -153,8 +153,9 @@ def delete_event(event_id):
Raises:
NotFound if not found
"""
event = get_event(event_id)
logger.info(f"{type(event)} {event.__str__}")
event = get_event(event_id, True)
for job in event.jobs:
delete_job(job)
db.session.delete(event)
db.session.commit()
@ -202,17 +203,15 @@ def update():
def delete_job(job: Job):
for service in job.services:
unassign_job(service=service, notify=True)
db.session.delete(job)
db.session.commit()
def assign_to_job(job: Job, user, value):
def assign_job(job: Job, user, value):
assert value > 0
service = Service.query.get((job.id, user.id_))
if value < 0:
if not service:
raise BadRequest
db.session.delete(service)
else:
if service:
service.value = value
else:
@ -221,6 +220,25 @@ def assign_to_job(job: Job, user, value):
db.session.commit()
def unassign_job(job: Job = None, user=None, service=None, notify=False):
if service is None:
assert(job is not None and user is not None)
service = Service.query.get((job.id, user.id_))
else:
user = service.user_
if not service:
raise BadRequest
event_id = service.job_.event_id_
db.session.delete(service)
db.session.commit()
if notify:
EventPlugin.plugin.notify(
user, "Your assignmet was cancelled", {"event_id": event_id}
)
@scheduled
def assign_backups():
logger.debug("Notifications")

View File

@ -415,7 +415,10 @@ def update_job(event_id, job_id, current_session: Session):
user != current_session.user_ and not current_session.user_.has_permission(permissions.ASSIGN_OTHER)
):
raise Forbidden
event_controller.assign_to_job(job, user, value)
if value > 0:
event_controller.assign_job(job, user, value)
else:
event_controller.unassign_job(job, user, notify=user != current_session.user_)
except (KeyError, ValueError):
raise BadRequest