|
21 | 21 | from sqlalchemy import and_, or_, update |
22 | 22 | from sqlalchemy.orm.exc import NoResultFound |
23 | 23 | from api_utils import ( |
| 24 | + add_html_link_to_email_body, |
24 | 25 | async_email_notification, |
25 | 26 | get_api_specification, |
26 | 27 | get_html_email_body_from_template, |
|
44 | 45 | TESTRUN_PRESET_FILEPATH = os.path.join(currentdir, CONFIGS_FOLDER, "testrun_plugin_presets.yaml") |
45 | 46 | SETTINGS_FILEPATH = os.path.join(currentdir, CONFIGS_FOLDER, "settings.yaml") |
46 | 47 | EMAIL_TEMPLATE_PATH = os.path.join(currentdir, CONFIGS_FOLDER, "email_template.html") |
| 48 | +EMAIL_MATRIX_FOOTER_MESSAGE = "<p>Join our <a href='" \ |
| 49 | + "https://matrix.to/#/!RoPWKbVtTKUKNouZCV:matrix.org?via=matrix.org" \ |
| 50 | + "'>BASIL Matrix chat room</a> to discuss about the tool usage and development!</p>" |
47 | 51 | TEST_RUNS_BASE_DIR = os.getenv("TEST_RUNS_BASE_DIR", "/var/test-runs") |
48 | 52 | USER_FILES_BASE_DIR = os.path.join(currentdir, "user-files") # forced under api to ensure tmt tree validity |
49 | 53 | PYPROJECT_FILEPATH = os.path.join(os.path.dirname(currentdir), "pyproject.toml") |
@@ -5489,7 +5493,7 @@ def post(self): |
5489 | 5493 | # Send email notifications to admins |
5490 | 5494 | email_subject = "BASIL - New User" |
5491 | 5495 | email_body = f"{username} joined us on BASIL!" |
5492 | | - email_footer = "" |
| 5496 | + email_footer = EMAIL_MATRIX_FOOTER_MESSAGE |
5493 | 5497 |
|
5494 | 5498 | admins = dbi.session.query(UserModel).filter( |
5495 | 5499 | UserModel.role == "ADMIN").filter( |
@@ -5903,13 +5907,18 @@ def get(self): |
5903 | 5907 | dbi.session.add(target_user) |
5904 | 5908 | dbi.session.commit() |
5905 | 5909 | dbi.engine.dispose() |
| 5910 | + |
| 5911 | + # Notification |
| 5912 | + settings = load_settings() |
5906 | 5913 | email_subject = "BASIL - Confirm password reset" |
5907 | | - email_footer = "" |
| 5914 | + email_footer = EMAIL_MATRIX_FOOTER_MESSAGE |
| 5915 | + email_body = "<p>Your password has been reset</p>" |
| 5916 | + email_body = add_html_link_to_email_body(settings=settings, body=email_body) |
5908 | 5917 | email_body = get_html_email_body_from_template(EMAIL_TEMPLATE_PATH, |
5909 | 5918 | email_subject, |
5910 | | - "Your password has been reset", |
| 5919 | + email_body, |
5911 | 5920 | email_footer) |
5912 | | - email_notifier = EmailNotifier(settings=load_settings()) |
| 5921 | + email_notifier = EmailNotifier(settings=settings) |
5913 | 5922 | ret = email_notifier.send_email(email, email_subject, email_body, True) |
5914 | 5923 | if ret: |
5915 | 5924 | if "redirect" in request_data.keys(): |
@@ -5940,15 +5949,16 @@ def post(self): |
5940 | 5949 |
|
5941 | 5950 | # generate reset_token and reset_pwd |
5942 | 5951 | email_subject = "BASIL - Password reset" |
5943 | | - email_footer = "" |
| 5952 | + email_footer = EMAIL_MATRIX_FOOTER_MESSAGE |
5944 | 5953 |
|
5945 | 5954 | reset_pwd = secrets.token_urlsafe(10) |
5946 | 5955 | encoded_reset_pwd = base64.b64encode(reset_pwd.encode("utf-8")).decode("utf-8") |
5947 | 5956 |
|
5948 | 5957 | reset_token = secrets.token_urlsafe(90) |
5949 | 5958 | reset_url = f"{request.base_url}?email={email}&reset_token={reset_token}" |
5950 | 5959 | if "app_url" in settings.keys(): |
5951 | | - reset_url += f"&redirect={settings['app_url']}/login?from=reset-password" |
| 5960 | + if str(settings["app_url"].trim()): |
| 5961 | + reset_url += f"&redirect={settings['app_url']}/login?from=reset-password" |
5952 | 5962 |
|
5953 | 5963 | target_user.reset_pwd = encoded_reset_pwd |
5954 | 5964 | target_user.reset_token = reset_token |
@@ -6037,6 +6047,23 @@ def put(self): |
6037 | 6047 | target_user.role = request_data["role"] |
6038 | 6048 | dbi.session.commit() |
6039 | 6049 |
|
| 6050 | + # Notification |
| 6051 | + settings = load_settings() |
| 6052 | + email_subject = "BASIL user role changed" |
| 6053 | + email_footer = EMAIL_MATRIX_FOOTER_MESSAGE |
| 6054 | + email_body = f"<p>Your BASIL user role changed to <b>{target_user.role}</b></p>" |
| 6055 | + email_body += "<p>See the <a href='" \ |
| 6056 | + "https://basil-the-fusa-spice.readthedocs.io/en/latest/user_management.html#roles" \ |
| 6057 | + "'>BASIL documentation</a> for a description of each role.</p>" |
| 6058 | + email_body = add_html_link_to_email_body(settings=settings, body=email_body) |
| 6059 | + email_body = get_html_email_body_from_template(EMAIL_TEMPLATE_PATH, |
| 6060 | + email_subject, |
| 6061 | + email_body, |
| 6062 | + email_footer) |
| 6063 | + |
| 6064 | + email_notifier = EmailNotifier(settings=settings) |
| 6065 | + email_notifier.send_email(target_user.email, email_subject, email_body, True) |
| 6066 | + |
6040 | 6067 | return {"email": request_data["email"]} |
6041 | 6068 |
|
6042 | 6069 |
|
|
0 commit comments