diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index a8e4c1b49..5703e144b 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -362,16 +362,16 @@ def register(self, request, pk): participant.status = 'approved' elif competition.registration_auto_approve: participant.status = 'approved' - send_participation_accepted_emails(participant) + send_participation_accepted_emails(participant, request) else: # check if user is in whitelist emails then approve directly # Using lower case because some users have used uppercased emails addresses if user.email.lower() in list(competition.whitelist_emails.values_list('email', flat=True)): participant.status = 'approved' - send_participation_accepted_emails(participant) + send_participation_accepted_emails(participant, request) else: participant.status = 'pending' - send_participation_requested_emails(participant) + send_participation_requested_emails(participant, request) participant.save() return Response({'participant_status': participant.status}, status=status.HTTP_201_CREATED) @@ -1034,7 +1034,7 @@ def update(self, request, *args, **kwargs): 'denied': send_participation_denied_emails, } if participation_status in emails: - emails[participation_status](participant) + emails[participation_status](participant, request) return super().update(request, *args, **kwargs) diff --git a/src/apps/api/views/profiles.py b/src/apps/api/views/profiles.py index 65e2bb13c..4f0ecf839 100644 --- a/src/apps/api/views/profiles.py +++ b/src/apps/api/views/profiles.py @@ -21,6 +21,7 @@ from profiles.helpers import send_mail from profiles.models import Organization, Membership from profiles.views import send_delete_account_confirmation_mail +from utils.email import get_link_context User = get_user_model() @@ -180,6 +181,7 @@ def invite_users(self, request, pk=None): 'user': member.user, 'invite_url': f'{reverse("profiles:organization_accept_invite")}?token={member.token}', 'organization': org.name, + **get_link_context(request), }, subject=f'You have been invited to join {org.name}', html_file="profiles/emails/invite.html", diff --git a/src/apps/competitions/emails.py b/src/apps/competitions/emails.py index 33316daa0..fa695b798 100644 --- a/src/apps/competitions/emails.py +++ b/src/apps/competitions/emails.py @@ -1,17 +1,18 @@ -from utils.email import codalab_send_mail, codalab_send_markdown_email +from utils.email import codalab_send_mail, codalab_send_markdown_email, get_link_context def get_organizer_emails(competition): return [user.email for user in competition.all_organizers if not user.is_deleted] -def send_participation_requested_emails(participant): +def send_participation_requested_emails(participant, request): if participant.user.is_deleted: return context = { 'participant': participant, - 'user': participant.user + 'user': participant.user, + **get_link_context(request), } # Notify Organizers codalab_send_mail( @@ -32,13 +33,14 @@ def send_participation_requested_emails(participant): ) -def send_participation_accepted_emails(participant): +def send_participation_accepted_emails(participant, request): if participant.user.is_deleted: return context = { 'participant': participant, - 'user': participant.user + 'user': participant.user, + **get_link_context(request), } codalab_send_mail( context_data=context, @@ -57,13 +59,14 @@ def send_participation_accepted_emails(participant): ) -def send_participation_denied_emails(participant): +def send_participation_denied_emails(participant, request): if participant.user.is_deleted: return context = { 'participant': participant, - 'user': participant.user + 'user': participant.user, + **get_link_context(request), } # Notify Organizers codalab_send_mail( diff --git a/src/apps/forums/models.py b/src/apps/forums/models.py index 9e5848018..dcff36f31 100644 --- a/src/apps/forums/models.py +++ b/src/apps/forums/models.py @@ -3,6 +3,8 @@ from django.db import models from django.urls import reverse +from utils.email import get_link_context + from .helpers import send_mail @@ -63,7 +65,8 @@ def notify_user(self, user, post=None): context={ 'thread': self, 'user': user, - 'new_post': self.posts.last() if post is None else post + 'new_post': self.posts.last() if post is None else post, + **get_link_context(), }, subject='New post in %s' % self.title, html_file="forums/emails/new_post.html", diff --git a/src/apps/profiles/views.py b/src/apps/profiles/views.py index 161fd5ffe..b5c0b1134 100644 --- a/src/apps/profiles/views.py +++ b/src/apps/profiles/views.py @@ -5,8 +5,7 @@ from django.contrib import messages from django.contrib.auth import authenticate, login from django.db.models import Q -from django.contrib.sites.shortcuts import get_current_site -from django.core.mail import EmailMessage, EmailMultiAlternatives +from django.core.mail import EmailMultiAlternatives from django.http import Http404 from django.shortcuts import render, redirect from django.contrib.auth import views as auth_views @@ -28,7 +27,7 @@ from datasets.models import Data from tasks.models import Task from forums.models import Post -from utils.email import codalab_send_mail +from utils.email import codalab_send_mail, get_link_context class LoginView(auth_views.LoginView): @@ -108,29 +107,29 @@ def activate(request, uidb64, token): def activateEmail(request, user, to_email): - mail_subject = 'Activate your user account.' - message = render_to_string('profiles/emails/template_activate_account.html', { - 'username': user.username, - 'domain': settings.DOMAIN_NAME, + context = { + 'user': user, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user), - 'protocol': 'https' if request.is_secure() else 'http' - }) - email = EmailMessage(mail_subject, message, to=[to_email]) - if email.send(): - messages.success(request, f'Dear {user.username}, please go to your email {to_email} inbox and click on \ - the activation link to confirm and complete the registration. *Note: Check your spam folder.') - else: - messages.error(request, f'Problem sending confirmation email to {to_email}, check if you typed it correctly.') + **get_link_context(request), + } + codalab_send_mail( + context_data=context, + subject='Activate your user account.', + html_file='profiles/emails/template_activate_account.html', + text_file='profiles/emails/template_activate_account.txt', + to_email=[to_email] + ) + messages.success(request, f'Dear {user.username}, please go to your email {to_email} inbox and click on \ + the activation link to confirm and complete the registration. *Note: Check your spam folder.') def send_delete_account_confirmation_mail(request, user): context = { 'user': user, - 'domain': get_current_site(request).domain, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_deletion_token.make_token(user), - 'protocol': 'https' if request.is_secure() else 'http' + **get_link_context(request), } codalab_send_mail( context_data=context, @@ -167,7 +166,7 @@ def send_user_deletion_notice_to_admin(user): 'tasks': tasks, 'queues': queues, 'posts': posts, - 'domain': settings.DOMAIN_NAME + **get_link_context(), } codalab_send_mail( context_data=context, diff --git a/src/templates/emails/base_email.txt b/src/templates/emails/base_email.txt index 927e2db0c..5faf58578 100644 --- a/src/templates/emails/base_email.txt +++ b/src/templates/emails/base_email.txt @@ -6,12 +6,9 @@ Hello{% if user %} {{ user.username }}{% endif %}, {% if not mass_email %} Thanks, -CodaLab Team +Codabench Team {% endif %} -Unsubscribe or manage notification settings: -http://{{ site.domain }} - Privacy policy: https://github.com/codalab/codalab-competitions/wiki/Privacy diff --git a/src/templates/emails/participation/organizer/participation_accepted.html b/src/templates/emails/participation/organizer/participation_accepted.html index d0942e6c3..8d71ce65f 100644 --- a/src/templates/emails/participation/organizer/participation_accepted.html +++ b/src/templates/emails/participation/organizer/participation_accepted.html @@ -3,7 +3,7 @@ {% block content %}
User {{ participant.user.username }} has been accepted into your competition
- {{ participant.competition.title }}.
+ {{ participant.competition.title }}.
You can manage all participants from the admin panel of your competition.
- User {{ participant.user.username }} has been accepted into your competition
- {{ participant.competition.title }}.
-
- You can manage all participants from the admin panel of your competition.
-
A user {{ participant.user.username }} has been denied access to your competition.
- {{ participant.competition.title }}.
+ {{ participant.competition.title }}.
You can manage all participants from the admin panel of your competition.
- A user {{ participant.user.username }} has been denied access to your competition.
- {{ participant.competition.title }}.
-
+ A user {{ participant.user.username }} has been denied access to your competition {{ participant.competition.title }}.
+ {{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}
+
You can manage all participants from the admin panel of your competition.
-
A user {{ participant.user.username }} has requested access to your competition
- {{ participant.competition.title }}.
+ {{ participant.competition.title }}.
You can manage all participants from the admin panel of your competition.
- A user {{ participant.user.username }} has requested access to your competition
- {{ participant.competition.title }}.
-
+ A user {{ participant.user.username }} has requested access to your competition {{ participant.competition.title }}.
+ {{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}
+
You can manage all participants from the admin panel of your competition.
-
Your application for the - {{ participant.competition.title }} + {{ participant.competition.title }} competition has been accepted. Get ready to showcase your skills and compete with other talented individuals.
{% endblock %} diff --git a/src/templates/emails/participation/participant/participation_accepted.txt b/src/templates/emails/participation/participant/participation_accepted.txt index d125565df..9e25a8443 100644 --- a/src/templates/emails/participation/participant/participation_accepted.txt +++ b/src/templates/emails/participation/participant/participation_accepted.txt @@ -1,12 +1,7 @@ -{% extends 'emails/base_email.html' %} +{% extends 'emails/base_email.txt' %} {% block content %} -- Your application for the - {{ participant.competition.title }} - competition has been accepted. Get ready to showcase your skills and compete with other talented individuals. -
-{% endblock %} - - + Your application for the {{ participant.competition.title }} competition has been accepted. Get ready to showcase your skills and compete with other talented individuals. + {{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }} +{% endblock %} diff --git a/src/templates/emails/participation/participant/participation_denied.html b/src/templates/emails/participation/participant/participation_denied.html index 9bef8c5ca..12e25c131 100644 --- a/src/templates/emails/participation/participant/participation_denied.html +++ b/src/templates/emails/participation/participant/participation_denied.html @@ -3,7 +3,7 @@ {% block content %}Your application for the - {{ participant.competition.title }} + {{ participant.competition.title }} competition has been denied. You can reach out to the organizing team for more details.
diff --git a/src/templates/emails/participation/participant/participation_denied.txt b/src/templates/emails/participation/participant/participation_denied.txt index 4b592667a..374c6f801 100644 --- a/src/templates/emails/participation/participant/participation_denied.txt +++ b/src/templates/emails/participation/participant/participation_denied.txt @@ -1,11 +1,7 @@ -{% extends 'emails/base_email.html' %} +{% extends 'emails/base_email.txt' %} {% block content %} -- Your application for the - {{ participant.competition.title }} - competition has been denied. You can reach out to the organizing team for more details. -
-{% endblock %} - + Your application for the {{ participant.competition.title }} competition has been denied. You can reach out to the organizing team for more details. + {{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }} +{% endblock %} diff --git a/src/templates/emails/participation/participant/participation_organizer_direct_email.html b/src/templates/emails/participation/participant/participation_organizer_direct_email.html index ad5b88dc1..48ed67deb 100644 --- a/src/templates/emails/participation/participant/participation_organizer_direct_email.html +++ b/src/templates/emails/participation/participant/participation_organizer_direct_email.html @@ -3,7 +3,7 @@ {% block title %}This is a message from the organizer for the competition: - {{ competition }} + {{ competition }}
- This is a message from the organizer for the competition: - {{ competition }} -
-{{ body }}
+ Message:
+ {{ body }}
{% endblock %}
diff --git a/src/templates/emails/participation/participant/participation_requested.html b/src/templates/emails/participation/participant/participation_requested.html
index 3412695c7..a727a95f5 100644
--- a/src/templates/emails/participation/participant/participation_requested.html
+++ b/src/templates/emails/participation/participant/participation_requested.html
@@ -3,7 +3,7 @@
{% block content %}
Thank you for your interest in the - {{ participant.competition.title }} + {{ participant.competition.title }} competition. We have received your request to participate.
diff --git a/src/templates/emails/participation/participant/participation_requested.txt b/src/templates/emails/participation/participant/participation_requested.txt index 3412695c7..53076b968 100644 --- a/src/templates/emails/participation/participant/participation_requested.txt +++ b/src/templates/emails/participation/participant/participation_requested.txt @@ -1,13 +1,9 @@ -{% extends 'emails/base_email.html' %} +{% extends 'emails/base_email.txt' %} {% block content %} -
- Thank you for your interest in the - {{ participant.competition.title }} - competition. We have received your request to participate. -
-- We will carefully review your application and notify you by email regarding your participation status (accepted or denied). - In the meantime, you can review the competition details and rules to familiarize yourself with the challenge. -
+ Thank you for your interest in the {{ participant.competition.title }} competition. We have received your request to participate. + + {{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }} + + We will carefully review your application and notify you by email regarding your participation status (accepted or denied). In the meantime, you can review the competition details and rules to familiarize yourself with the challenge. {% endblock %} diff --git a/src/templates/forums/emails/new_post.html b/src/templates/forums/emails/new_post.html index 34e333b84..96dde02c2 100644 --- a/src/templates/forums/emails/new_post.html +++ b/src/templates/forums/emails/new_post.html @@ -1,7 +1,7 @@ {% extends 'emails/base_email.html' %} {% block content %} -There was a new post in {{ thread.title }}.
+There was a new post in {{ thread.title }}.
{{ new_post.content|linebreaks }}{% endblock %} diff --git a/src/templates/forums/emails/new_post.txt b/src/templates/forums/emails/new_post.txt index 5b53121b4..6306a8b74 100644 --- a/src/templates/forums/emails/new_post.txt +++ b/src/templates/forums/emails/new_post.txt @@ -2,7 +2,7 @@ {% block content %} There was a new post in "{{ thread.title }}" - http://{{ site.domain }}{{ thread.get_absolute_url }} + {{ protocol }}://{{ domain }}{{ thread.get_absolute_url }} {{ new_post.content }} diff --git a/src/templates/profiles/emails/invite.html b/src/templates/profiles/emails/invite.html index 1418fc8c9..97a4efb63 100644 --- a/src/templates/profiles/emails/invite.html +++ b/src/templates/profiles/emails/invite.html @@ -2,6 +2,6 @@ {% block content %}- {{ new_post.posted_by.username }}
You have been invited to join {{ organization }}.
-Click this link to accept or reject your invite. http://{{ site.domain }}{{ invite_url }}
+Click this link to accept or reject your invite. {{ protocol }}://{{ domain }}{{ invite_url }}
{% endblock %} diff --git a/src/templates/profiles/emails/invite.txt b/src/templates/profiles/emails/invite.txt index 0a1dd205a..30b6df7e1 100644 --- a/src/templates/profiles/emails/invite.txt +++ b/src/templates/profiles/emails/invite.txt @@ -2,7 +2,7 @@ {% block content %} You have been invited to join {{ organization }}. - Copy this URL into your web browser to accept. http://{{ site.domain }}{{ invite_url }} + Copy this URL into your web browser to accept. {{ protocol }}://{{ domain }}{{ invite_url }} {{ new_post.content }} diff --git a/src/templates/profiles/emails/template_activate_account.html b/src/templates/profiles/emails/template_activate_account.html index 83ee09085..d26a2ea70 100644 --- a/src/templates/profiles/emails/template_activate_account.html +++ b/src/templates/profiles/emails/template_activate_account.html @@ -1,10 +1,6 @@ -{% autoescape off %} -Hi {{ username }}, +{% extends 'emails/base_email.html' %} -Please click on the link below to confirm your registration: - -{{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %} - -This is an automatic message delivered by Codabench. - -{% endautoescape %} +{% block content %} +Please click on the link below to confirm your registration:
+{{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %}
+{% endblock %} diff --git a/src/templates/profiles/emails/template_activate_account.txt b/src/templates/profiles/emails/template_activate_account.txt new file mode 100644 index 000000000..e6502d6fa --- /dev/null +++ b/src/templates/profiles/emails/template_activate_account.txt @@ -0,0 +1,6 @@ +{% extends 'emails/base_email.txt' %} + +{% block content %} + Please click on the link below to confirm your registration: + {{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %} +{% endblock %} diff --git a/src/templates/profiles/emails/template_delete_account.txt b/src/templates/profiles/emails/template_delete_account.txt index fce090de0..8f90e0258 100644 --- a/src/templates/profiles/emails/template_delete_account.txt +++ b/src/templates/profiles/emails/template_delete_account.txt @@ -1,25 +1,18 @@ -{% extends 'emails/base_email.html' %} +{% extends 'emails/base_email.txt' %} {% block content %} -We have received your request to delete your account.
-To proceed with the deletion of your account, please confirm your request by clicking the link below:
-{{ protocol }}://{{ domain }}{% url 'accounts:delete' uidb64=uid token=token %}
+ We have received your request to delete your account. -Important Information:
-If you did not request this action or have changed your mind, you can safely ignore this email, and your account will remain intact.
- -Thank you for being part of our community.
+ Thank you for being part of our community. {% endblock %} diff --git a/src/templates/profiles/emails/template_delete_account_confirmed.txt b/src/templates/profiles/emails/template_delete_account_confirmed.txt index 690b2dff3..2334ae770 100644 --- a/src/templates/profiles/emails/template_delete_account_confirmed.txt +++ b/src/templates/profiles/emails/template_delete_account_confirmed.txt @@ -1,7 +1,7 @@ -{% extends 'emails/base_email.html' %} +{% extends 'emails/base_email.txt' %} {% block content %} -Your account has been successfully removed. Thank you for being part of our community.
-If you change your mind, you can create a new account at any time. We'd be happy to welcome you back!
+ Your account has been successfully removed. Thank you for being part of our community. + + If you change your mind, you can create a new account at any time. We'd be happy to welcome you back! {% endblock %} diff --git a/src/templates/profiles/emails/template_delete_account_notice.html b/src/templates/profiles/emails/template_delete_account_notice.html index fe0dc9e9f..19ee3ed4d 100644 --- a/src/templates/profiles/emails/template_delete_account_notice.html +++ b/src/templates/profiles/emails/template_delete_account_notice.html @@ -35,7 +35,7 @@You are receiving this notice because your are an administrator of the platform.
- -The following user has removed their account:
-