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

Commit

Permalink
Send a different email for waitinglist on manually accepted events (#669
Browse files Browse the repository at this point in the history
)

* different email for waiting list if not fcfs

* fix tests

* shortened some lines :)

* i am at war with the linter
  • Loading branch information
michaelstambach authored Nov 4, 2024
1 parent 6b8b461 commit a54cf26
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
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

0 comments on commit a54cf26

Please sign in to comment.