Skip to content

Commit

Permalink
fix CustomEventParticipantNotification for placeholder (#1231)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix Rindt <felix@ephios.de>
  • Loading branch information
jeriox and felixrindt committed Mar 16, 2024
1 parent 5137a83 commit b8e4e61
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions ephios/core/services/notifications/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,29 +530,31 @@ class CustomEventParticipantNotification(AbstractNotificationHandler):
@classmethod
def send(cls, event: Event, content: str):
participants = set()
notifications = []
responsible_users = get_users_with_perms(
event, with_superusers=False, only_with_perms_in=["change_event"]
)
for shift in event.shifts.all():
participants.update(shift.get_participants())
notifications = []
for participant in participants:
user = participant.user if isinstance(participant, LocalUserParticipant) else None
if user in responsible_users:
continue
notifications.append(
Notification(
slug=cls.slug,
user=user,
data={
"email": participant.email,
"event_id": event.id,
"content": content,
"event_title": event.title,
"event_url": participant.reverse_event_detail(event),
},
for participation in AbstractParticipation.objects.filter(
shift__event=event, state=AbstractParticipation.States.CONFIRMED
):
participant = participation.participant
if participant not in participants:
participants.add(participant)
user = participant.user if isinstance(participant, LocalUserParticipant) else None
if user in responsible_users:
continue
notifications.append(
Notification(
slug=cls.slug,
user=user,
data={
"email": participant.email,
"participation_id": participation.id,
"event_id": event.id,
"content": content,
},
)
)
)
for responsible in responsible_users:
notifications.append(
Notification(
Expand All @@ -562,17 +564,15 @@ def send(cls, event: Event, content: str):
"email": responsible.email,
"event_id": event.id,
"content": content,
"event_title": event.title,
},
)
)
Notification.objects.bulk_create(notifications)

@classmethod
def get_subject(cls, notification):
return _("Information for your participation at {title}").format(
title=notification.data.get("event_title")
)
event = Event.objects.get(pk=notification.data.get("event_id"))
return _("Information regarding {title}").format(title=event.title)

@classmethod
def get_body(cls, notification):
Expand All @@ -581,14 +581,21 @@ def get_body(cls, notification):
@classmethod
def get_actions(cls, notification):
event = Event.objects.get(pk=notification.data.get("event_id"))
participation = AbstractParticipation.objects.filter(
pk=notification.data.get("participation_id")
).first() # there is no participation for responsible users
return [
(
str(_("View message")),
make_absolute(reverse("core:notification_detail", kwargs={"pk": notification.pk})),
),
(
str(_("View event")),
make_absolute(notification.data.get("event_url", event.get_absolute_url())),
make_absolute(
participation.participant.reverse_event_detail(event)
if participation
else event.get_absolute_url()
),
),
]

Expand Down

0 comments on commit b8e4e61

Please sign in to comment.