Skip to content
27 changes: 27 additions & 0 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from apps.app_registry import APP_REGISTRY
from apps.models import BaseAppInstance
from common.tasks import send_email_task

from .exceptions import ProjectCreationException
from .forms import PublishProjectToGitHub
Expand Down Expand Up @@ -355,6 +356,32 @@ def post(self, request, project_slug):
project.authorized.add(selected_user)
assign_perm("can_view_project", selected_user, project)

project_uri = f"{request.get_host()}/projects/{project.slug}"
# The backslash below is used to ignore a newline
email_body = f"""\
Hi {selected_username},

{request.user.username} added you to the project {project.name} on SciLifeLab Serve (https://serve.scilifelab.se)
You can now view the project here: {project_uri}
If you have any questions get in touch with us at [email protected]

Thank you for signing up for our service. We are excited to have you on board!

Best regards,
The Data Centre team
"""

try:
# Notify user via email
send_email_task(
subject=f"You've been added to {project.name} on SciLifeLab Serve",
message=email_body,
recipient_list=[selected_username],
)

except Exception as err:
logger.exception(f"Unable to send email to user: {str(err)}", exc_info=True)

log = ProjectLog(
project=project,
module="PR",
Expand Down
1 change: 1 addition & 0 deletions studio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def delete_account_post_handler(request: Response, user_id: int) -> Response:
email = request.user.email
logger.debug(f"User account was deleted (set to inactive). Now sending email to user email {email}")

# TODO use send_email_task instead
send_mail(
"User account deleted from SciLifeLab Serve",
f"The user account {request.user.username} was deleted from SciLifeLab Serve as requested.",
Expand Down
Loading