fix and add more notification
This commit is contained in:
parent
941841b1bb
commit
b4c3cfa365
|
@ -14,10 +14,9 @@ __version__ = pkg_resources.get_distribution("flaschengeist_events").version
|
|||
|
||||
|
||||
class EventPlugin(Plugin):
|
||||
#id = "dev.flaschengeist.events"
|
||||
#plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][EventPlugin.id])
|
||||
# id = "dev.flaschengeist.events"
|
||||
# provided resources
|
||||
#permissions = permissions.permissions
|
||||
# permissions = permissions.permissions
|
||||
models = models
|
||||
|
||||
# def __init__(self, cfg):
|
||||
|
@ -27,7 +26,12 @@ class EventPlugin(Plugin):
|
|||
|
||||
def load(self):
|
||||
from .routes import blueprint
|
||||
|
||||
self.blueprint = blueprint
|
||||
|
||||
def install(self):
|
||||
self.install_permissions(permissions.permissions)
|
||||
|
||||
@staticmethod
|
||||
def getPlugin() -> LocalProxy["EventPlugin"]:
|
||||
return LocalProxy(lambda: current_app.config["FG_PLUGINS"]["events"])
|
||||
|
|
|
@ -27,8 +27,11 @@ class NotifyType(IntEnum):
|
|||
INVITE = 0x01
|
||||
TRANSFER = 0x02
|
||||
# Invitation responsed 0x10..0x1F
|
||||
INVITATION_ACCEPTED = 0x10
|
||||
INVITATION_REJECTED = 0x11
|
||||
INVITATION_ACCEPTED = 0x11
|
||||
INVITATION_REJECTED = 0x12
|
||||
# Information responses 0x20..0x2F
|
||||
INFO_ACCEPTED = 0x21
|
||||
INFO_REJECTED = 0x22
|
||||
|
||||
|
||||
@before_delete_user
|
||||
|
@ -295,7 +298,7 @@ def delete_job(job: Job):
|
|||
db.session.commit()
|
||||
|
||||
|
||||
def assign_job(job: Job, user, value, is_backup=False):
|
||||
def assign_job(job: Job, user, value, is_backup=False, notify=False):
|
||||
assert value > 0
|
||||
service = Service.query.get((job.id, user.id_))
|
||||
if service:
|
||||
|
@ -303,10 +306,17 @@ def assign_job(job: Job, user, value, is_backup=False):
|
|||
service.is_backup = is_backup
|
||||
else:
|
||||
job.services.append(Service(user_=user, value=value, is_backup=is_backup, job_=job))
|
||||
if notify:
|
||||
EventPlugin.getPlugin().notify(
|
||||
user,
|
||||
f"You were assigned to a job\n{job.start.strftime('%d.%m.%Y')}",
|
||||
{"type": NotifyType.INFO_ACCEPTED, "event_id": job.event_id_},
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def unassign_job(job: Job = None, user=None, service=None, notify=False):
|
||||
_date = job.start.strftime("%d.%m.%Y")
|
||||
if service is None:
|
||||
assert job is not None and user is not None
|
||||
service = Service.query.get((job.id, user.id_))
|
||||
|
@ -320,17 +330,24 @@ def unassign_job(job: Job = None, user=None, service=None, notify=False):
|
|||
db.session.delete(service)
|
||||
db.session.commit()
|
||||
if notify:
|
||||
EventPlugin.plugin.notify(user, "Your assignmet was cancelled", {"event_id": event_id})
|
||||
EventPlugin.getPlugin().notify(
|
||||
user, f"Your assignmet was cancelled\n{_date}", {"type": NotifyType.INFO_REJECTED, "event_id": event_id}
|
||||
)
|
||||
|
||||
|
||||
def invite(job: Job, invitee, inviter, transferee=None):
|
||||
inv = Invitation(job_=job, inviter_=inviter, invitee_=invitee, transferee_=transferee)
|
||||
db.session.add(inv)
|
||||
update()
|
||||
_date = job.start.strftime("%d.%m.%Y")
|
||||
if transferee is None:
|
||||
EventPlugin.plugin.notify(invitee, _("Job invitation"), {"type": NotifyType.INVITE, "invitation": inv.id})
|
||||
EventPlugin.getPlugin().notify(
|
||||
invitee, _(f"Job invitation\n{_date}"), {"type": NotifyType.INVITE, "invitation": inv.id}
|
||||
)
|
||||
else:
|
||||
EventPlugin.plugin.notify(invitee, _("Job transfer"), {"type": NotifyType.TRANSFER, "invitation": inv.id})
|
||||
EventPlugin.getPlugin().notify(
|
||||
invitee, _(f"Job transfer\n{_date}"), {"type": NotifyType.TRANSFER, "invitation": inv.id}
|
||||
)
|
||||
return inv
|
||||
|
||||
|
||||
|
@ -362,7 +379,7 @@ def respond_invitation(invite: Invitation, accepted=True):
|
|||
raise Conflict
|
||||
|
||||
if not accepted:
|
||||
EventPlugin.plugin.notify(
|
||||
EventPlugin.getPlugin().notify(
|
||||
inviter,
|
||||
_("Invitation rejected"),
|
||||
{
|
||||
|
@ -381,7 +398,7 @@ def respond_invitation(invite: Invitation, accepted=True):
|
|||
raise Conflict
|
||||
unassign_job(job, invite.transferee_, service[0], True)
|
||||
assign_job(job, invite.invitee_, service[0].value)
|
||||
EventPlugin.plugin.notify(
|
||||
EventPlugin.getPlugin().notify(
|
||||
inviter,
|
||||
_("Invitation accepted"),
|
||||
{
|
||||
|
@ -402,7 +419,7 @@ def assign_backups():
|
|||
services = Service.query.filter(Service.is_backup == True).join(Job).filter(Job.start <= start).all()
|
||||
for service in services:
|
||||
if service.job_.start <= now or service.job_.is_full():
|
||||
EventPlugin.plugin.notify(
|
||||
EventPlugin.getPlugin().notify(
|
||||
service.user_,
|
||||
"Your backup assignment was cancelled.",
|
||||
{"event_id": service.job_.event_id_},
|
||||
|
@ -412,7 +429,7 @@ def assign_backups():
|
|||
else:
|
||||
service.is_backup = False
|
||||
logger.debug(f"Service not full, assigning backup. {service.serialize()}")
|
||||
EventPlugin.plugin.notify(
|
||||
EventPlugin.getPlugin().notify(
|
||||
service.user_,
|
||||
"Your backup assignment was accepted.",
|
||||
{"event_id": service.job_.event_id_},
|
||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -10,8 +10,11 @@ const EventTypes = {
|
|||
invite: 0x01,
|
||||
transfer: 0x02,
|
||||
invitation_response: 0x10,
|
||||
invitation_accepted: 0x10,
|
||||
invitation_rejected: 0x11,
|
||||
invitation_accepted: 0x11,
|
||||
invitation_rejected: 0x12,
|
||||
info: 0x20,
|
||||
info_accepted: 0x21,
|
||||
info_rejected: 0x22,
|
||||
};
|
||||
|
||||
function transpile(msg: FG_Plugin.Notification) {
|
||||
|
@ -29,7 +32,10 @@ function transpile(msg: FG_Plugin.Notification) {
|
|||
};
|
||||
|
||||
message.link = { name: 'events-requests' };
|
||||
} else if ((message.data.type & EventTypes._mask_) === EventTypes.invitation_response) {
|
||||
} else if (
|
||||
(message.data.type & EventTypes._mask_) === EventTypes.invitation_response ||
|
||||
(message.data.type & EventTypes._mask_) === EventTypes.info
|
||||
) {
|
||||
message.link = {
|
||||
name: 'events-single-view',
|
||||
params: { id: (<InvitationResponseData>message.data).event },
|
||||
|
|
Loading…
Reference in New Issue