Compare commits
2 Commits
2dabd1dd34
...
f7e07fdade
Author | SHA1 | Date |
---|---|---|
Ferdinand Thiessen | f7e07fdade | |
Ferdinand Thiessen | 3d833fb6af |
|
@ -33,6 +33,7 @@ class Plugin:
|
||||||
|
|
||||||
blueprint = None # You have to override
|
blueprint = None # You have to override
|
||||||
permissions = [] # You have to override
|
permissions = [] # You have to override
|
||||||
|
id = "dev.flaschengeist.plugin" # You have to override
|
||||||
name = "plugin" # You have to override
|
name = "plugin" # You have to override
|
||||||
models = None # You have to override
|
models = None # You have to override
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ class Plugin:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def notify(self, user, text: str, data=None):
|
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.add(n)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from . import permissions, models
|
||||||
|
|
||||||
class EventPlugin(Plugin):
|
class EventPlugin(Plugin):
|
||||||
name = "events"
|
name = "events"
|
||||||
|
id = "dev.flaschengeist.events"
|
||||||
plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.name])
|
plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.name])
|
||||||
permissions = permissions.permissions
|
permissions = permissions.permissions
|
||||||
blueprint = Blueprint(name, __name__)
|
blueprint = Blueprint(name, __name__)
|
||||||
|
|
|
@ -153,8 +153,9 @@ def delete_event(event_id):
|
||||||
Raises:
|
Raises:
|
||||||
NotFound if not found
|
NotFound if not found
|
||||||
"""
|
"""
|
||||||
event = get_event(event_id)
|
event = get_event(event_id, True)
|
||||||
logger.info(f"{type(event)} {event.__str__}")
|
for job in event.jobs:
|
||||||
|
delete_job(job)
|
||||||
db.session.delete(event)
|
db.session.delete(event)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -202,17 +203,15 @@ def update():
|
||||||
|
|
||||||
|
|
||||||
def delete_job(job: Job):
|
def delete_job(job: Job):
|
||||||
|
for service in job.services:
|
||||||
|
unassign_job(service=service, notify=True)
|
||||||
db.session.delete(job)
|
db.session.delete(job)
|
||||||
db.session.commit()
|
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_))
|
service = Service.query.get((job.id, user.id_))
|
||||||
if value < 0:
|
|
||||||
if not service:
|
|
||||||
raise BadRequest
|
|
||||||
db.session.delete(service)
|
|
||||||
else:
|
|
||||||
if service:
|
if service:
|
||||||
service.value = value
|
service.value = value
|
||||||
else:
|
else:
|
||||||
|
@ -221,6 +220,25 @@ def assign_to_job(job: Job, user, value):
|
||||||
db.session.commit()
|
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
|
@scheduled
|
||||||
def assign_backups():
|
def assign_backups():
|
||||||
logger.debug("Notifications")
|
logger.debug("Notifications")
|
||||||
|
|
|
@ -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)
|
user != current_session.user_ and not current_session.user_.has_permission(permissions.ASSIGN_OTHER)
|
||||||
):
|
):
|
||||||
raise Forbidden
|
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):
|
except (KeyError, ValueError):
|
||||||
raise BadRequest
|
raise BadRequest
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue