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