Compare commits
No commits in common. "f7e07fdadec4ffdd0490ff08a5dfd033e7e1badc" and "2dabd1dd34de907c801809eedc1216817604249c" have entirely different histories.
f7e07fdade
...
2dabd1dd34
|
@ -33,7 +33,6 @@ 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
|
||||||
|
|
||||||
|
@ -95,7 +94,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.id, user_=user)
|
n = Notification(text=text, data=data, plugin=self.name, user_=user)
|
||||||
db.session.add(n)
|
db.session.add(n)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ 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,9 +153,8 @@ def delete_event(event_id):
|
||||||
Raises:
|
Raises:
|
||||||
NotFound if not found
|
NotFound if not found
|
||||||
"""
|
"""
|
||||||
event = get_event(event_id, True)
|
event = get_event(event_id)
|
||||||
for job in event.jobs:
|
logger.info(f"{type(event)} {event.__str__}")
|
||||||
delete_job(job)
|
|
||||||
db.session.delete(event)
|
db.session.delete(event)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -203,42 +202,25 @@ 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_job(job: Job, user, value):
|
def assign_to_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 service:
|
if value < 0:
|
||||||
service.value = value
|
if not service:
|
||||||
|
raise BadRequest
|
||||||
|
db.session.delete(service)
|
||||||
else:
|
else:
|
||||||
service = Service(user_=user, value=value, job_=job)
|
if service:
|
||||||
db.session.add(service)
|
service.value = value
|
||||||
|
else:
|
||||||
|
service = Service(user_=user, value=value, job_=job)
|
||||||
|
db.session.add(service)
|
||||||
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,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)
|
user != current_session.user_ and not current_session.user_.has_permission(permissions.ASSIGN_OTHER)
|
||||||
):
|
):
|
||||||
raise Forbidden
|
raise Forbidden
|
||||||
if value > 0:
|
event_controller.assign_to_job(job, user, value)
|
||||||
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