Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix user welcome email #703

Merged
merged 1 commit into from
Dec 2, 2021
Merged
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
4 changes: 3 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fi
safety check -i 42194 -i 40459 -i 42050&& \
pydocstyle sonar tests docs && \
isort --check-only --diff "${SCRIPT_PATH}/.." && \
autoflake -rc --remove-all-unused-imports --ignore-init-module-imports . && \
autoflake -c -r --remove-all-unused-imports --ignore-init-module-imports . &> /dev/null || {
autoflake --remove-all-unused-imports -r --ignore-init-module-imports .
} && \
sphinx-build -qnNW docs docs/_build/html && \
pytest
2 changes: 1 addition & 1 deletion sonar/modules/users/templates/users/email/welcome/en.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>Dear {{ user.first_name }},</p>
<p>An account has been created for you on SONAR, the Insitutional repository of {{ user.organisation.name }}.</p>
<p>An account has been created for you on {{ platform_name }}.</p>
<p>To access it, please <a href="{{ reset_link.replace('/api', '') }}">reset your password.</a></p>
<p>Your login e-mail: {{ user.email }}</p>
{% if user.is_submitter %}
Expand Down
34 changes: 25 additions & 9 deletions sonar/modules/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Utils functions for user module."""

import markdown
from bs4 import BeautifulSoup
from flask_babelex import _
from flask_security import url_for_security
from flask_security.recoverable import generate_reset_password_token
Expand All @@ -31,14 +33,28 @@ def send_welcome_email(user_record, user):
:param user: User account.
"""
user_record = user_record.replace_refs()
code = user_record['organisation'].get('code', '')
plain_platform_name = 'SONAR'
platform_name = user_record['organisation'].get('platformName')
if platform_name:
html = markdown.markdown(platform_name)
plain_platform_name = ''.join(
BeautifulSoup(html).findAll(text=True)).replace('\n', ' - ')

token = generate_reset_password_token(user)
reset_link = url_for_security('reset_password',
token=token,
_external=True)

send_email([user_record['email']], _('Welcome to SONAR'),
'users/email/welcome', {
'user': user_record,
'reset_link': reset_link
})
reset_link = url_for_security(
'reset_password',
token=token,
next=f'/{code}',
_external=True
)

send_email(
[user_record['email']],
f'{_("Welcome to")} {plain_platform_name}',
'users/email/welcome', {
'user': user_record,
'reset_link': reset_link,
'platform_name': plain_platform_name
}
)