Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/apps/api/views/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/apps/api/views/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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",
Expand Down
17 changes: 10 additions & 7 deletions src/apps/competitions/emails.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/apps/forums/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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",
Expand Down
35 changes: 17 additions & 18 deletions src/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/templates/emails/base_email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
User <strong>{{ participant.user.username }}</strong> has been accepted into your competition
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
You can manage all participants from the admin panel of your competition.
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
User <strong>{{ participant.user.username }}</strong> has been accepted into your competition
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
You can manage all participants from the admin panel of your competition.
</p>
User {{ participant.user.username }} has been accepted into your competition {{ participant.competition.title }}.
{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}

You can manage all participants from the admin panel of your competition.
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
A user <strong>{{ participant.user.username }}</strong> has been denied access to your competition.
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
You can manage all participants from the admin panel of your competition.
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
A user <strong>{{ participant.user.username }}</strong> has been denied access to your competition.
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
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.
</p>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
A user <strong>{{ participant.user.username }}</strong> has requested access to your competition
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
You can manage all participants from the admin panel of your competition.
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
A user <strong>{{ participant.user.username }}</strong> has requested access to your competition
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>.
<br>
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.
</p>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
Your application for the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition has been <b>accepted</b>. Get ready to showcase your skills and compete with other talented individuals.
</p>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
Your application for the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition has been <b>accepted</b>. Get ready to showcase your skills and compete with other talented individuals.
</p>
{% 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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
Your application for the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition has been denied. You can reach out to the organizing team for more details.
</p>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
Your application for the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition has been denied. You can reach out to the organizing team for more details.
</p>
{% 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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}
<p>
This is a message from the organizer for the competition:
<a href="http://{{ site.domain }}{{ competition.get_absolute_url }}">{{ competition }}</a>
<a href="{{ protocol }}://{{ domain }}{{ competition.get_absolute_url }}">{{ competition }}</a>
</p>
<br><br>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{% extends 'emails/base_email.txt' %}

{% block title %}
<p>
This is a message from the organizer for the competition:
<a href="http://{{ site.domain }}{{ competition.get_absolute_url }}">{{ competition }}</a>
</p>
<br><br>
This is a message from the organizer for the competition: {{ competition }}
{{ protocol }}://{{ domain }}{{ competition.get_absolute_url }}
{% endblock %}

{% block content %}
<h3>Message:</h3>
<pre>{{ body }}</pre>
Message:
{{ body }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<p>
Thank you for your interest in the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
<a href="{{ protocol }}://{{ domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition. We have received your request to participate.
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{% extends 'emails/base_email.html' %}
{% extends 'emails/base_email.txt' %}

{% block content %}
<p>
Thank you for your interest in the
<a href="http://{{ site.domain }}{{ participant.competition.get_absolute_url }}">{{ participant.competition.title }}</a>
competition. We have received your request to participate.
</p>
<p>
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.
</p>
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 %}
2 changes: 1 addition & 1 deletion src/templates/forums/emails/new_post.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'emails/base_email.html' %}

{% block content %}
<p>There was a new post in <a href="http://{{ site.domain }}{{ thread.get_absolute_url }}">{{ thread.title }}</a>.</p>
<p>There was a new post in <a href="{{ protocol }}://{{ domain }}{{ thread.get_absolute_url }}">{{ thread.title }}</a>.</p>

<blockquote>{{ new_post.content|linebreaks }}<p> - {{ new_post.posted_by.username }}</p></blockquote>
{% endblock %}
Loading