From 1135c7d1c28efff2c062f5785a2092be96f9a044 Mon Sep 17 00:00:00 2001 From: Amit Upreti Date: Fri, 10 Mar 2023 14:31:55 -0500 Subject: [PATCH] send email to host,cohost Whenever a host adds or removes a cohost to the event, email notification are sent to a) host and b) the added/removed cohost --- .../event_cohost_cohost_status_change.html | 15 +++++++ .../event_host_cohost_status_change.html | 14 +++++++ physionet-django/events/views.py | 16 ++++++-- physionet-django/notification/utility.py | 39 +++++++++++++++++++ 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html create mode 100644 physionet-django/events/templates/events/email/event_host_cohost_status_change.html diff --git a/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html new file mode 100644 index 0000000000..03d9b0bc55 --- /dev/null +++ b/physionet-django/events/templates/events/email/event_cohost_cohost_status_change.html @@ -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 %} diff --git a/physionet-django/events/templates/events/email/event_host_cohost_status_change.html b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html new file mode 100644 index 0000000000..c22563e470 --- /dev/null +++ b/physionet-django/events/templates/events/email/event_host_cohost_status_change.html @@ -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 %} diff --git a/physionet-django/events/views.py b/physionet-django/events/views.py index 8eb92bcd42..a29195f53d 100644 --- a/physionet-django/events/views.py +++ b/physionet-django/events/views.py @@ -266,8 +266,12 @@ 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'): @@ -275,8 +279,12 @@ def manage_co_hosts(request): 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'}) diff --git a/physionet-django/notification/utility.py b/physionet-django/notification/utility.py index f531057719..7f81ebec52 100644 --- a/physionet-django/notification/utility.py +++ b/physionet-django/notification/utility.py @@ -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.