Skip to content

Commit

Permalink
send email to host,cohost
Browse files Browse the repository at this point in the history
Whenever a host adds or removes a cohost to the event, email notification are sent to a) host and b) the added/removed cohost
  • Loading branch information
superryeti committed Mar 15, 2023
1 parent 1bb6ca0 commit 1135c7d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% load i18n %}{% autoescape off %}{% filter wordwrap:70 %}
Dear {{ name }},
{% if status == 'Make cohost' %}
You have been added as Cohost to the Event : {{ event_title }}.

You can now manage the event participants from your events dashboard.
{% elif status == 'Remove cohost' %}
Your Cohost access has been removed from the Event : {{ event_title }}.
{% endif %}
You can view further information about the event using the following link:
{{ url_prefix }}{{ event_url }}

Regards
The {{ SITE_NAME }} Team
{% endfilter %}{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load i18n %}{% autoescape off %}{% filter wordwrap:70 %}
Dear {{ host_name }},
{% if status == 'Make cohost' %}
You have provided {{ cohost_name }} Cohost access to the Event : {{ event_title }}.
{% elif status == 'Remove cohost' %}
You have removed {{ cohost_name }}'s Cohost access from the Event : {{ event_title }}.
{% endif %}
If this was done by mistake, you can change the cohost status by visiting the events dashboard.

{{ url_prefix }}/events/

Regards
The {{ SITE_NAME }} Team
{% endfilter %}{% endautoescape %}
16 changes: 12 additions & 4 deletions physionet-django/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,25 @@ def manage_co_hosts(request):
return JsonResponse({'error': 'User is not a cohost of this event'}, status=403)
participant.is_cohost = False
participant.save()

# placeholder for notification to cohost that they have been removed and to host that they removed a cohost
# notify the cohost that their cohost permission has been removed
notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user,
event=event, status='Remove cohost')
# notify the host that they have removed a cohost
notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event,
status='Remove cohost')

return JsonResponse({'success': 'Cohost removed successfully'})
elif 'Make cohost' in request.POST.get('submit'):
if participant.is_cohost:
return JsonResponse({'error': 'User is already a cohost of this event'}, status=403)
participant.is_cohost = True
participant.save()

# placeholder for notification to cohost that they have been added and to host that they added a cohost
# notify the cohost that they have been added as a cohost for the event
notification.notify_event_cohost_cohost_status_change(request=request, cohost=participant.user,
event=event, status='Make cohost')
# notify the host that they have added a cohost for the event
notification.notify_event_host_cohost_status_change(request=request, cohost=participant.user, event=event,
status='Make cohost')

return JsonResponse({'success': 'Cohost added successfully'})

Expand Down
39 changes: 39 additions & 0 deletions physionet-django/notification/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,45 @@ def notify_participant_event_decision(request, user, event, decision, comment_to
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)


def notify_event_cohost_cohost_status_change(request, cohost, event, status='Make cohost'):
"""
Send email to co-host about their cohost status change for the event.
"""
subject = f"{settings.SITE_NAME} Event Cohost Status Change"
context = {
'name': cohost.get_full_name(),
'domain': get_current_site(request),
'url_prefix': get_url_prefix(request),
'event_title': event.title,
'event_url': reverse('event_detail', args=[event.slug]),
'status': status,
'SITE_NAME': settings.SITE_NAME,
}
body = loader.render_to_string('events/email/event_cohost_cohost_status_change.html', context)
# Not resend the email if there was an integrity error
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [cohost.email], fail_silently=False)


def notify_event_host_cohost_status_change(request, cohost, event, status='Make cohost'):
"""
Send email to host about cohost status change for the event.
"""
subject = f"{settings.SITE_NAME} Event Cohost Status Change"
context = {
'host_name': event.host.get_full_name(),
'cohost_name': cohost.get_full_name(),
'domain': get_current_site(request),
'url_prefix': get_url_prefix(request),
'event_title': event.title,
'event_url': reverse('event_detail', args=[event.slug]),
'status': status,
'SITE_NAME': settings.SITE_NAME,
}
body = loader.render_to_string('events/email/event_host_cohost_status_change.html', context)
# Not resend the email if there was an integrity error
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [cohost.email], fail_silently=False)


def notify_event_participant_application(request, user, registered_user, event):
"""
Send email to host and co-host about new registration request on event.
Expand Down

0 comments on commit 1135c7d

Please sign in to comment.