Skip to content
Snippets Groups Projects
Commit fc604644 authored by geant-release-service's avatar geant-release-service
Browse files

Finished release 0.32.

parents a54ef7f9 0d71a4d2
Branches
Tags 0.32
No related merge requests found
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.32] - 2023-08-27
- Send an email to the user on first login
- Change NREN to (N)REN on the landing page
## [0.31] - 2023-08-24 ## [0.31] - 2023-08-24
- Fixed applying CSS class to all questions - Fixed applying CSS class to all questions
- Increased width of the service name input fields in the services section - Increased width of the service name input fields in the services section
......
...@@ -5,7 +5,7 @@ from datetime import datetime ...@@ -5,7 +5,7 @@ from datetime import datetime
from flask_login import LoginManager, current_user # type: ignore from flask_login import LoginManager, current_user # type: ignore
from compendium_v2.db import session_scope from compendium_v2.db import session_scope
from compendium_v2.db.auth_model import User, ROLES from compendium_v2.db.auth_model import User, ROLES
from compendium_v2.email import send_mail from compendium_v2.email import send_admin_signup_notification, send_user_signup_notification
def admin_required(func): def admin_required(func):
...@@ -33,20 +33,22 @@ def admin_required(func): ...@@ -33,20 +33,22 @@ def admin_required(func):
return wraps(func)(wrapper) return wraps(func)(wrapper)
def create_user(email: str, fullname: str, oidc_sub: str): def create_user(email: str, fullname: str, oidc_sub: str, given_name: str):
""" """
Function used to create a new user in the database. Function used to create a new user in the database.
:param email: The email of the user :param email: The email of the user
:param fullname: The full name of the user :param fullname: The full name of the user
:param oidc_sub: The OIDC subject identifier (ID) of the user :param oidc_sub: The OIDC subject identifier (ID) of the user
:param given_name: The given name of the user
:return: The user object :return: The user object
""" """
with session_scope() as session: with session_scope() as session:
user = User(email=email, fullname=fullname, oidc_sub=oidc_sub) user = User(email=email, fullname=fullname, oidc_sub=oidc_sub)
session.add(user) session.add(user)
send_mail(f'{fullname} has just signed up with the email {email} and provider ID {oidc_sub}') send_admin_signup_notification(user)
send_user_signup_notification(user, given_name)
return user return user
......
...@@ -10,6 +10,18 @@ from compendium_v2.db.auth_model import User, ROLES ...@@ -10,6 +10,18 @@ from compendium_v2.db.auth_model import User, ROLES
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
USER_NOTIFICATION_TEMPLATE = """Hello{name},
Thank you for registering for the new GÉANT Compendium Survey site.
The Compendium team have been notified and will assign you to your NREN shortly. If you are a long-time contributor this should be fairly quick (same working day). For new users, we will have to check with your colleagues first to make sure you are authorised to answer on behalf of your NREN.
Best regards,
Daniel and Jennifer (the Compendium admins)
""" # noqa: E501
def _send_mail(smtp_server, port, sender_email, recipients, message): def _send_mail(smtp_server, port, sender_email, recipients, message):
try: try:
...@@ -22,7 +34,7 @@ def _send_mail(smtp_server, port, sender_email, recipients, message): ...@@ -22,7 +34,7 @@ def _send_mail(smtp_server, port, sender_email, recipients, message):
def send_mail( def send_mail(
contents: str, contents: str,
subject: str = 'New user signed up for Compendium', subject: str,
recipients: Union[str, Sequence[str]] = '' recipients: Union[str, Sequence[str]] = ''
): ):
if not current_app.config['MAIL_ENABLE']: if not current_app.config['MAIL_ENABLE']:
...@@ -52,3 +64,20 @@ def send_mail( ...@@ -52,3 +64,20 @@ def send_mail(
logger.debug('Sending email') logger.debug('Sending email')
thread = threading.Thread(target=_send_mail, args=(smtp_server, port, sender_email, recipients, message)) thread = threading.Thread(target=_send_mail, args=(smtp_server, port, sender_email, recipients, message))
thread.start() thread.start()
def send_admin_signup_notification(user: User):
fullname = user.fullname
email = user.email
oidc_sub = user.oidc_sub
contents = f"""{fullname} has just signed up with the email {email} and provider ID {oidc_sub}"""
send_mail(contents=contents, subject='New user signed up for Compendium')
def send_user_signup_notification(user: User, given_name: str):
email = user.email
name = f' {given_name}' if given_name else ''
contents = USER_NOTIFICATION_TEMPLATE.format(name=name)
send_mail(contents=contents, subject='You have signed up for the Compendium Survey', recipients=email)
...@@ -36,7 +36,7 @@ def authorize(): ...@@ -36,7 +36,7 @@ def authorize():
user = fetch_user(profile) user = fetch_user(profile)
if user is None: if user is None:
# create a new user # create a new user
user = create_user(profile['email'], profile['name'], profile['sub']) user = create_user(profile['email'], profile['name'], profile['sub'], profile['given_name'])
login_user(user) login_user(user)
# redirect to / # redirect to /
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='compendium-v2', name='compendium-v2',
version="0.31", version="0.32",
author='GEANT', author='GEANT',
author_email='swd@geant.org', author_email='swd@geant.org',
description='Flask and React project for displaying ' description='Flask and React project for displaying '
......
...@@ -28,10 +28,10 @@ function Landing(): ReactElement { ...@@ -28,10 +28,10 @@ function Landing(): ReactElement {
<div className="wordwrap pt-4" style={{ maxWidth: '75rem' }}> <div className="wordwrap pt-4" style={{ maxWidth: '75rem' }}>
<p style={{ textAlign: "left" }}> <p style={{ textAlign: "left" }}>
Hello, Hello,
<br />Welcome to the GÉANT Compendium Survey. NREN Compendium administrators can login via Single Sign On (SSO) <a href="/login">here</a>, which will complete their registration to fill in the 2023 Compendium survey. <br />Welcome to the GÉANT Compendium Survey. (N)REN Compendium administrators can login via Single Sign On (SSO) <a href="/login">here</a>, which will complete their registration to fill in the 2023 Compendium survey.
This will send a notification to the Compendium administration team and they will assign you to your NREN. This will send a notification to the Compendium administration team and they will assign you to your (N)REN.
<br />Once this step has been completed, you will receive an email from the administration team. We aim to get back to you the same working day, but sometimes may take a little longer. <br />Once this step has been completed, you will receive an email from the administration team. We aim to get back to you the same working day, but sometimes may take a little longer.
<br />If you are not sure whether you are a Compendium Administrator for your NREN, please contact your GÉANT Partner Relations relationship manager. <br />If you are not sure whether you are a Compendium Administrator for your (N)REN, please contact your GÉANT Partner Relations relationship manager.
<br />Thank you. <br />Thank you.
</p> </p>
......
from compendium_v2.email import send_mail from contextlib import contextmanager
from compendium_v2.db.auth_model import User
from compendium_v2.email import send_admin_signup_notification, send_user_signup_notification
def test_email(app, mocked_admin_user, mocker): @contextmanager
def test_user(app):
def _send_mail(*args, **kwargs):
pass
mocker.patch('compendium_v2.email._send_mail', _send_mail)
with app.app_context(): with app.app_context():
app.config['MAIL_ENABLE'] = True app.config['MAIL_ENABLE'] = True
app.config['MAIL_SERVER'] = 'localhost' app.config['MAIL_SERVER'] = 'localhost'
app.config['MAIL_PORT'] = 54655 app.config['MAIL_PORT'] = 54655
app.config['MAIL_SENDER_EMAIL'] = 'fakesender123@test.local' app.config['MAIL_SENDER_EMAIL'] = 'fakesender123@test.local'
app.config['MAIL_EXCLUDED_ADMINS'] = [] app.config['MAIL_EXCLUDED_ADMINS'] = []
send_mail('testmail321') user = User(fullname='testname', email='testmail321@email.com', oidc_sub='testsub')
yield user
def test_signup_email_admin(app, mocked_admin_user, mocker):
def _send_mail(*args, **kwargs):
message = 'testname has just signed up with the email testmail321@email.com and provider ID testsub'
assert args[-1].split('\n\n')[-1] == message
mocker.patch('compendium_v2.email._send_mail', _send_mail)
with test_user(app) as user:
send_admin_signup_notification(user)
def test_signup_email_user(app, mocker):
def _send_mail(*args, **kwargs):
assert len(args[-1].split('\n\n', 1)[-1]) > 50 # check that there's a message
mocker.patch('compendium_v2.email._send_mail', _send_mail)
with test_user(app) as user:
send_user_signup_notification(user, 'testname')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment