Skip to content

Commit cc09ad9

Browse files
j-awadaalfredeen
andauthored
SS-964 Send email confirmation on project access (#275)
Co-authored-by: Johan Alfredéen <[email protected]>
1 parent a69a5c7 commit cc09ad9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

projects/views.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from apps.app_registry import APP_REGISTRY
2727
from apps.models import BaseAppInstance
28+
from common.tasks import send_email_task
2829

2930
from .exceptions import ProjectCreationException
3031
from .forms import PublishProjectToGitHub
@@ -355,6 +356,32 @@ def post(self, request, project_slug):
355356
project.authorized.add(selected_user)
356357
assign_perm("can_view_project", selected_user, project)
357358

359+
project_uri = f"{request.get_host()}/projects/{project.slug}"
360+
# The backslash below is used to ignore a newline
361+
email_body = f"""\
362+
Hi {selected_username},
363+
364+
{request.user.username} added you to the project {project.name} on SciLifeLab Serve (https://serve.scilifelab.se)
365+
You can now view the project here: {project_uri}
366+
If you have any questions get in touch with us at [email protected]
367+
368+
Thank you for signing up for our service. We are excited to have you on board!
369+
370+
Best regards,
371+
The Data Centre team
372+
"""
373+
374+
try:
375+
# Notify user via email
376+
send_email_task(
377+
subject=f"You've been added to {project.name} on SciLifeLab Serve",
378+
message=email_body,
379+
recipient_list=[selected_username],
380+
)
381+
382+
except Exception as err:
383+
logger.exception(f"Unable to send email to user: {str(err)}", exc_info=True)
384+
358385
log = ProjectLog(
359386
project=project,
360387
module="PR",

studio/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def delete_account_post_handler(request: Response, user_id: int) -> Response:
180180
email = request.user.email
181181
logger.debug(f"User account was deleted (set to inactive). Now sending email to user email {email}")
182182

183+
# TODO use send_email_task instead
183184
send_mail(
184185
"User account deleted from SciLifeLab Serve",
185186
f"The user account {request.user.username} was deleted from SciLifeLab Serve as requested.",

0 commit comments

Comments
 (0)