Skip to content
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
c3fb2bb
update base-html
odeimaiz Mar 26, 2025
32c56b0
parametrize base.html
odeimaiz Mar 26, 2025
316b330
pass product metadata
odeimaiz Mar 26, 2025
7e29b7e
minor
odeimaiz Mar 26, 2025
7bf0043
extend ProductData model
odeimaiz Mar 26, 2025
4a63e42
HttpUrl
odeimaiz Mar 26, 2025
dc02a80
renaming
odeimaiz Mar 26, 2025
9d6551e
add logo and strong_color to Vendor's model
odeimaiz Mar 26, 2025
e9a38d9
ProductData
odeimaiz Mar 26, 2025
9d6f69d
minor
odeimaiz Mar 26, 2025
f34fe9e
set product info
odeimaiz Mar 26, 2025
e7e4b6c
minor
odeimaiz Mar 26, 2025
500797c
Merge branch 'master' into enh/prettify-base-email
odeimaiz Mar 27, 2025
f254081
no need to pass the args
odeimaiz Mar 27, 2025
e715f71
Merge branch 'enh/prettify-base-email' of github.com:odeimaiz/osparc-…
odeimaiz Mar 27, 2025
a90238c
strong-button for links
odeimaiz Mar 27, 2025
8851478
Manrope by default
odeimaiz Mar 27, 2025
66d25cc
prettify button
odeimaiz Mar 27, 2025
f50cae5
more buttons
odeimaiz Mar 27, 2025
a98d9b9
inline styling
odeimaiz Mar 27, 2025
7b4f3c1
minor
odeimaiz Mar 27, 2025
1771fa1
buttons templated strong color
odeimaiz Mar 27, 2025
9c2c0f3
minor
odeimaiz Mar 27, 2025
c64124e
Merge branch 'master' into enh/prettify-base-email
odeimaiz Mar 28, 2025
423a842
product ui data
odeimaiz Mar 28, 2025
6e2eb50
.ui.
odeimaiz Mar 28, 2025
f5f31c4
minor
odeimaiz Mar 28, 2025
0977198
ui -> product_ui
odeimaiz Mar 28, 2025
04e75de
1st try
odeimaiz Mar 28, 2025
9073d4f
back
odeimaiz Mar 28, 2025
c9c72bf
typo
odeimaiz Mar 28, 2025
081bbe1
fix test
odeimaiz Mar 28, 2025
130a9b7
product_ui -> ui
odeimaiz Mar 28, 2025
df04634
add defaults
odeimaiz Mar 28, 2025
1c63495
vendor.ui
odeimaiz Mar 28, 2025
2a0c1d6
Merge branch 'master' into enh/prettify-base-email
odeimaiz Mar 31, 2025
47087d5
Merge branch 'master' into enh/prettify-base-email
odeimaiz Mar 31, 2025
900941c
add emails
odeimaiz Mar 31, 2025
1337fa3
include them in the testing
odeimaiz Mar 31, 2025
ee53285
Merge branch 'master' into feature/on-share-project-email
odeimaiz Mar 31, 2025
1ed4955
Merge branch 'master' into feature/on-share-project-email
odeimaiz Apr 4, 2025
865b15a
pass sharer_message and put it in a box
odeimaiz Apr 4, 2025
e801dc4
minor fix
odeimaiz Apr 4, 2025
de27334
typo
odeimaiz Apr 4, 2025
264ef9e
minor
odeimaiz Apr 4, 2025
05b483f
enable testing
odeimaiz Apr 4, 2025
79e3634
project_alias is part of product_ui
odeimaiz Apr 4, 2025
f511ff0
minor
odeimaiz Apr 4, 2025
6713746
random
odeimaiz Apr 4, 2025
6a374e8
SharerData
odeimaiz Apr 4, 2025
fb59670
SharerData
odeimaiz Apr 4, 2025
c174a4f
sharer
odeimaiz Apr 4, 2025
5e14a72
typo
odeimaiz Apr 4, 2025
bcc714b
typo
odeimaiz Apr 4, 2025
93852c3
Merge branch 'master' into feature/on-share-project-email
odeimaiz Apr 7, 2025
85b30fc
default to empty string
odeimaiz Apr 7, 2025
7afb556
random_element
odeimaiz Apr 7, 2025
64b3e3f
user.first_name or user.user_name
odeimaiz Apr 7, 2025
fd14931
SharerData will go in the other_data
odeimaiz Apr 7, 2025
4c109c8
extend event_extra_data with optional sharer_data
odeimaiz Apr 7, 2025
c76a716
let faker provide a sentence or empty
odeimaiz Apr 7, 2025
423c324
make it part of the event_extra_data
odeimaiz Apr 7, 2025
73a4e48
minor
odeimaiz Apr 7, 2025
6d3a6d0
enable tests
odeimaiz Apr 7, 2025
53517c6
fix test
odeimaiz Apr 7, 2025
32640f7
user_name for UserData
odeimaiz Apr 7, 2025
23f84cb
minor
odeimaiz Apr 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class EmailPartsTuple(NamedTuple):
suject: str
subject: str
text_content: str
html_content: str | None

Expand Down Expand Up @@ -58,5 +58,5 @@ def render_email_parts(
html_content = None

return EmailPartsTuple(
suject=subject, text_content=text_content, html_content=html_content
subject=subject, text_content=text_content, html_content=html_content
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ class UserData:
email: str


@dataclass(frozen=True)
class SharerData:
user_name: str
message: str


@dataclass(frozen=True)
class ProductUIData:
logo_url: str
strong_color: str
project_alias: str


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_change_email.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>
You have requested to change the email address linked to your {{ product.display_name }} account.
Please follow the on-screen information in the link below:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

You have requested to change the email address linked to your {{ product.display_name }} account. Please follow the on-screen information in the link below:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_new_code.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>Please find below the Two-factor Authentication sign-in code for your {{ host }} account.</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

Please find below the Two-factor Authentication sign-in code for your {{ host }} account.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_new_invitation.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>Thank you for your interest in {{ product.display_name }}. We are pleased to provide you with a one-time invitation link to register on the platform.</p>
<p>
<!-- Many email clients strip or ignore certain CSS properties, including them inline -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

Thank you for your interest in {{ product.display_name }}. We are pleased to provide you with a one-time invitation link to register on the platform.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}

<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>We are delighted to confirm the successful processing of your payment of <strong>{{ payment.price_dollars }}</strong> <strong><em>USD</em></strong> for the purchase of <strong>{{ payment.osparc_credits }}</strong> <strong><em>credits</em></strong>.
The credits have been added to your {{ product.display_name }} account, and you are all set to utilize them.</p>
<p>For more details you can view or download your <a href="{{ payment.invoice_url }}">receipt</a>.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

We are delighted to confirm the successful processing of your payment of {{ payment.price_dollars }} USD for the purchase of {{ payment.osparc_credits }} credits. The credits have been added to your {{ product.display_name }} account, and you are all set to utilize them.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_registered.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>Thank you for your interest in {{ product.display_name }}. You have successfully registered for {{ host }}.</p>
<p>Please activate your account via the link below:</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

Thank you for your interest in {{ product.display_name }}. You have successfully registered for {{ host }}.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_reset_password.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>

<p>A request to reset your {{ host }} password has been made.</p>
{% if success %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

A request to reset your {{ host }} password has been made.
{% if success %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_share_project.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name or user.user_name }},</p>

<p>Great news! {{ sharer.user_name }} has shared a {{ product.ui.project_alias }} with you on {{ product.display_name }}.</p>

<p>To view the {{ product.ui.project_alias }} and accept the sharing, follow below:</p>

<p>
{% if sharer.message %}
<div style="border: 1px solid #ccc; padding: 16px; border-radius: 8px; background-color: #f9f9f9;">
<p style="margin-top: 0;">{{ sharer.message }}</p>
<button class="strong-button" style="border-radius: 4px;">
<a href="{{ accept_link }}" style="color: white;">Open</a>
</button>
</div>
{% else %}
<button class="strong-button" style="border-radius: 4px;">
<a href="{{ accept_link }}" style="color: white;">Open</a>
</button>
{% endif %}
</p>

<p>Please don't hesitate to contact us at {{ product.support_email }} if you need further help.</p>

<p>Best Regards,</p>
<p>The <i>{{ product.display_name }}</i> Team</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Dear {{ user.first_name or user.user_name }},

Great news! {{ sharer.user_name }} has shared a {{ product.ui.project_alias }} with you on {{ product.display_name }}.

To view the {{ product.ui.project_alias }} and accept the sharing, follow below:

{{ sharer.message }}
{{ accept_link }}

Please don't hesitate to contact us at {{ product.support_email }} if you need further help.

Best Regards,
The {{ product.display_name }} Team
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A {{ product.ui.project_alias }} was shared with you on {{ host }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %} {% include 'on_unregister.email.subject.txt' %} {% endblock %}
{% block content %}
<p>Dear {{ user.first_name }},</p>
<p>Dear {{ user.first_name or user.user_name }},</p>
<p>
We have received your account closure request, and we want to say thank you for being a part of our platform. While
we're sad to see you go, we respect your decision.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dear {{ user.first_name }},
Dear {{ user.first_name or user.user_name }},

We have received your account closure request, and we want to say thank you for being a part of our platform. While we're sad to see you go, we respect your decision.

Expand Down
17 changes: 16 additions & 1 deletion packages/notifications-library/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

import notifications_library
import pytest
from faker import Faker
from models_library.products import ProductName
from notifications_library._models import ProductData, ProductUIData, UserData
from notifications_library._models import (
ProductData,
ProductUIData,
SharerData,
UserData,
)
from notifications_library.payments import PaymentData
from pydantic import EmailStr
from pytest_simcore.helpers.typing_env import EnvVarsDict
Expand Down Expand Up @@ -61,6 +67,7 @@ def product_data(
"https://raw.githubusercontent.com/ITISFoundation/osparc-simcore/refs/heads/master/services/static-webserver/client/source/resource/osparc/osparc-white.svg",
),
strong_color=vendor.get("ui", {}).get("strong_color", "rgb(131, 0, 191)"),
project_alias=vendor.get("ui", {}).get("project_alias", "project"),
)

return ProductData( # type: ignore
Expand All @@ -84,6 +91,14 @@ def user_data(
)


@pytest.fixture
def sharer_data(user_name: str, faker: Faker) -> SharerData:
return SharerData(
user_name=user_name,
message=faker.random_element(elements=(faker.sentence(), "")),
)


@pytest.fixture
def payment_data(successful_transaction: dict[str, Any]) -> PaymentData:
return PaymentData(
Expand Down
21 changes: 18 additions & 3 deletions packages/notifications-library/tests/email/test_email_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import functools
import json
from dataclasses import asdict
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock
Expand All @@ -41,7 +42,7 @@
get_user_address,
render_email_parts,
)
from notifications_library._models import ProductData, UserData
from notifications_library._models import ProductData, SharerData, UserData
from notifications_library._render import (
create_render_environment_from_notifications_library,
)
Expand Down Expand Up @@ -135,6 +136,16 @@ def event_extra_data( # noqa: PLR0911
"reason": faker.sentence(),
"link": f"{host_url}?reset-password={code}",
}
case "on_share_project":
return {
"host": host_url,
"resource_alias": "Project",
"sharer": SharerData(
user_name=faker.name(),
message=faker.random_element(elements=(faker.sentence(), "")),
),
"accept_link": f"{host_url}?code={code}",
}
case "on_unregister":
return {
"host": host_url,
Expand Down Expand Up @@ -169,6 +180,7 @@ def event_attachments(event_name: str, faker: Faker) -> list[tuple[bytes, str]]:
"on_payed",
"on_registered",
"on_reset_password",
"on_share_project",
"on_unregister",
],
)
Expand All @@ -177,6 +189,7 @@ async def test_email_event(
smtp_mock_or_none: MagicMock | None,
user_data: UserData,
user_email: EmailStr,
sharer_data: SharerData | None,
product_data: ProductData,
product_name: ProductName,
event_name: str,
Expand All @@ -187,6 +200,8 @@ async def test_email_event(
assert user_data.email == user_email
assert product_data.product_name == product_name

event_extra_data = event_extra_data | (asdict(sharer_data) if sharer_data else {})

parts = render_email_parts(
env=create_render_environment_from_notifications_library(
undefined=StrictUndefined
Expand All @@ -207,7 +222,7 @@ async def test_email_event(
msg = compose_email(
from_,
to,
subject=parts.suject,
subject=parts.subject,
content_text=parts.text_content,
content_html=parts.html_content,
)
Expand Down Expand Up @@ -278,7 +293,7 @@ async def test_email_with_reply_to(
msg = compose_email(
from_,
to,
subject=parts.suject,
subject=parts.subject,
content_text=parts.text_content,
content_html=parts.html_content,
reply_to=reply_to,
Expand Down
1 change: 1 addition & 0 deletions packages/notifications-library/tests/test__templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"on_payed",
"on_registered",
"on_reset_password",
"on_share_project",
"on_unregister",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class VendorUI(TypedDict, total=True):
logo_url: str # vendor logo url
strong_color: str # vendor main color
project_alias: str # project alias for the product (e.g. "project" or "study")


class Vendor(TypedDict, total=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def random_product(
"host_regex": r"[a-zA-Z0-9]+\.com",
"support_email": f"support@{suffix}.io",
"product_owners_email": fake.random_element(
elements=[f"product-onwers@{suffix}.io", None]
elements=[f"product-owners@{suffix}.io", None]
),
"twilio_messaging_sid": fake.random_element(
elements=(None, f"{fake.uuid4()}"[:34])
Expand All @@ -260,6 +260,7 @@ def random_product(
ui=VendorUI(
logo_url=fake.url(),
strong_color=fake.color(),
project_alias=fake.random_element(elements=["project", "study"]),
),
),
"registration_email_template": registration_email_template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
and isinstance(c.server_default.arg, str) # type: ignore[union-attr]
},
},
# Example of data in the dabase with a url set with blanks
# Example of data in the database with a url set with blanks
{
"name": "tis",
"display_name": "TI PT",
Expand Down Expand Up @@ -245,6 +245,7 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
"ui": {
"logo_url": "https://acme.com/logo",
"strong_color": "#123456",
"project_alias": "study",
},
},
"issues": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_product_to_static():
"ui": {
"logo_url": "https://acme.com/logo",
"strong_color": "#123456",
"project_alias": "study",
},
},
"issues": [
Expand Down
Loading