Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Send a different email for waitinglist on manually accepted events #669

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions amivapi/events/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def find_reply_to_email(event):
return current_app.config.get('DEFAULT_EVENT_REPLY_TO')


def notify_signup_accepted(event, signup, waiting_list=False):
def notify_signup_accepted(
event,
signup,
waiting_list=False,
spots_available=False):
"""Send an email to a user that his signup was accepted"""
id_field = current_app.config['ID_FIELD']

Expand Down Expand Up @@ -84,16 +88,28 @@ def notify_signup_accepted(event, signup, waiting_list=False):
calendar_invite = None

if waiting_list:
mail_from_template(
to=[email],
subject='Your signup for %s was put on the waiting list'
% (title_en or title_de),
template_name='events_waitingList',
template_args=dict(
name=name,
title_en=(title_en or title_de),
title_de=(title_de or title_en)),
reply_to=reply_to_email)
if spots_available:
mail_from_template(
to=[email],
subject='Your signup for %s was put on the waiting list'
% (title_en or title_de),
template_name='events_waitingListManual',
template_args=dict(
name=name,
title_en=(title_en or title_de),
title_de=(title_de or title_en)),
reply_to=reply_to_email)
else:
mail_from_template(
to=[email],
subject='Your signup for %s was put on the waiting list'
% (title_en or title_de),
template_name='events_waitingList',
template_args=dict(
name=name,
title_en=(title_en or title_de),
title_de=(title_de or title_en)),
reply_to=reply_to_email)
else:
mail_from_template(
to=[email],
Expand Down
13 changes: 11 additions & 2 deletions amivapi/events/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,19 @@ def update_waiting_list_after_insert(signups):
if signup['_id'] in accepted:
signup['accepted'] = True
elif signup.get('user') is not None:
lookup = {current_app.config['ID_FIELD']: signup.get('event')}
event_id = signup.get('event')
lookup = {current_app.config['ID_FIELD']: event_id}
event = current_app.data.find_one('events', None, **lookup)
lookup = {'event': event_id, 'accepted': True}
signup_count = (
current_app.data.driver.db['eventsignups']
.count_documents(lookup))
if event is not None:
notify_signup_accepted(event, signup, True)
if event['selection_strategy'] == "manual" \
and signup_count < event['spots']:
notify_signup_accepted(event, signup, True, True)
else:
notify_signup_accepted(event, signup, True, False)


def update_waiting_list_after_delete(signup):
Expand Down
19 changes: 19 additions & 0 deletions amivapi/templates/events_waitingListManual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.html" %}

{% block text_german %}
<p>Hey {{ name }}!</p>

<p>Deine Anmeldung für {{ title_de }} wurde auf die Warteliste gesetzt, da bei diesem Event die Teilnehmer manuell akzeptiert werden.</p>
<p>Du erhältst eine E-Mail sobald deine Anmeldung definitiv aufgenommen wird.</p>

<p>Freundliche Grüsse,</br>AMIV</p>
{% endblock %}

{% block text_english %}
<p>Hello {{ name }}!</p>

<p>Your signup for {{ title_en }} was put on the waiting list, as the signups for this event are manually reviewed.</p>
<p>You will be notified as soon as your signup has been definitively accepted.</p>

<p>Best Regards,</br>AMIV</p>
{% endblock %}
21 changes: 21 additions & 0 deletions amivapi/templates/events_waitingListManual.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.txt" %}

{% block text_german %}
Hey {{ name }}!

Deine Anmeldung für {{ title_de }} wurde auf die Warteliste gesetzt, da bei diesem Event die Teilnehmer manuell akzeptiert werden.
Du erhältst eine E-Mail sobald deine Anmeldung definitiv aufgenommen wird.

Freundliche Grüsse,
AMIV
{% endblock %}

{% block text_english %}
Hello {{ name }}!

Your signup for {{ title_en }} was put on the waiting list, as the signups for this event are manually reviewed.
You will be notified as soon as your signup has been definitively accepted.

Best Regards,
AMIV
{% endblock %}
4 changes: 3 additions & 1 deletion amivapi/tests/events/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ def test_notify_waitlist_on_signup_update(self):
'event': str(manual_event['_id'])
},
status_code=201).json
self.assertTrue('was rejected' in self.app.test_mails[0]['text'])
# this results in a different email
self.assertTrue('are manually reviewed'
in self.app.test_mails[0]['text'])

# User manually accepted from waiting list
self.api.patch('/eventsignups/%s' % manual_signup['_id'],
Expand Down