Compare commits

..

No commits in common. "f7e07fdadec4ffdd0490ff08a5dfd033e7e1badc" and "2dabd1dd34de907c801809eedc1216817604249c" have entirely different histories.

4 changed files with 14 additions and 37 deletions

View File

@ -33,7 +33,6 @@ 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
@ -95,7 +94,7 @@ class Plugin:
db.session.commit()
def notify(self, user, text: str, data=None):
n = Notification(text=text, data=data, plugin=self.id, user_=user)
n = Notification(text=text, data=data, plugin=self.name, user_=user)
db.session.add(n)
db.session.commit()

View File

@ -11,7 +11,6 @@ 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,9 +153,8 @@ def delete_event(event_id):
Raises:
NotFound if not found
"""
event = get_event(event_id, True)
for job in event.jobs:
delete_job(job)
event = get_event(event_id)
logger.info(f"{type(event)} {event.__str__}")
db.session.delete(event)
db.session.commit()
@ -203,42 +202,25 @@ 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_job(job: Job, user, value):
assert value > 0
def assign_to_job(job: Job, user, value):
service = Service.query.get((job.id, user.id_))
if service:
service.value = value
if value < 0:
if not service:
raise BadRequest
db.session.delete(service)
else:
service = Service(user_=user, value=value, job_=job)
db.session.add(service)
if service:
service.value = value
else:
service = Service(user_=user, value=value, job_=job)
db.session.add(service)
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,10 +415,7 @@ 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
if value > 0:
event_controller.assign_job(job, user, value)
else:
event_controller.unassign_job(job, user, notify=user != current_session.user_)
event_controller.assign_to_job(job, user, value)
except (KeyError, ValueError):
raise BadRequest