🔧(project) add DJANGO_EMAIL_URL_APP environment variable
Most of Docs app is configured thanks to environment variables, except the url in the email that was from the django site table. Now we can set it with DJANGO_EMAIL_URL_APP environment variable to have a better consistency. We keep the previous way to avoid breaking changes.
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to
|
|||||||
- ✨(frontend) integrate configurable Waffle #1795
|
- ✨(frontend) integrate configurable Waffle #1795
|
||||||
- ✨ Import of documents #1609
|
- ✨ Import of documents #1609
|
||||||
- 🚨(CI) gives warning if theme not updated #1811
|
- 🚨(CI) gives warning if theme not updated #1811
|
||||||
|
- 🔧(project) add DJANGO_EMAIL_URL_APP environment variable #1825
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ These are the environment variables you can set for the `impress-backend` contai
|
|||||||
| DJANGO_EMAIL_HOST_USER | User to authenticate with on the email host | |
|
| DJANGO_EMAIL_HOST_USER | User to authenticate with on the email host | |
|
||||||
| DJANGO_EMAIL_LOGO_IMG | Logo for the email | |
|
| DJANGO_EMAIL_LOGO_IMG | Logo for the email | |
|
||||||
| DJANGO_EMAIL_PORT | Port used to connect to email host | |
|
| DJANGO_EMAIL_PORT | Port used to connect to email host | |
|
||||||
|
| DJANGO_EMAIL_URL_APP | Url used in the email to go to the app | |
|
||||||
| DJANGO_EMAIL_USE_SSL | Use ssl for email host connection | false |
|
| DJANGO_EMAIL_USE_SSL | Use ssl for email host connection | false |
|
||||||
| DJANGO_EMAIL_USE_TLS | Use tls for email host connection | false |
|
| DJANGO_EMAIL_USE_TLS | Use tls for email host connection | false |
|
||||||
| DJANGO_SECRET_KEY | Secret key | |
|
| DJANGO_SECRET_KEY | Secret key | |
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ backend:
|
|||||||
DJANGO_EMAIL_HOST: "mailcatcher"
|
DJANGO_EMAIL_HOST: "mailcatcher"
|
||||||
DJANGO_EMAIL_LOGO_IMG: https://docs.127.0.0.1.nip.io/assets/logo-suite-numerique.png
|
DJANGO_EMAIL_LOGO_IMG: https://docs.127.0.0.1.nip.io/assets/logo-suite-numerique.png
|
||||||
DJANGO_EMAIL_PORT: 1025
|
DJANGO_EMAIL_PORT: 1025
|
||||||
|
DJANGO_EMAIL_URL_APP: https://docs.127.0.0.1.nip.io
|
||||||
DJANGO_EMAIL_USE_SSL: False
|
DJANGO_EMAIL_USE_SSL: False
|
||||||
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
||||||
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ DJANGO_EMAIL_FROM=<your email address>
|
|||||||
|
|
||||||
DJANGO_EMAIL_BRAND_NAME=<brand name used in email templates> # e.g. "La Suite Numérique"
|
DJANGO_EMAIL_BRAND_NAME=<brand name used in email templates> # e.g. "La Suite Numérique"
|
||||||
DJANGO_EMAIL_LOGO_IMG=<logo image to use in email templates.> # e.g. "https://docs.yourdomain.tld/assets/logo-suite-numerique.png"
|
DJANGO_EMAIL_LOGO_IMG=<logo image to use in email templates.> # e.g. "https://docs.yourdomain.tld/assets/logo-suite-numerique.png"
|
||||||
|
DJANGO_EMAIL_URL_APP=<url used in email templates to go to the app> # e.g. "https://docs.yourdomain.tld"
|
||||||
```
|
```
|
||||||
|
|
||||||
### AI
|
### AI
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ DJANGO_EMAIL_BRAND_NAME="La Suite Numérique"
|
|||||||
DJANGO_EMAIL_HOST="mailcatcher"
|
DJANGO_EMAIL_HOST="mailcatcher"
|
||||||
DJANGO_EMAIL_LOGO_IMG="http://localhost:3000/assets/logo-suite-numerique.png"
|
DJANGO_EMAIL_LOGO_IMG="http://localhost:3000/assets/logo-suite-numerique.png"
|
||||||
DJANGO_EMAIL_PORT=1025
|
DJANGO_EMAIL_PORT=1025
|
||||||
|
DJANGO_EMAIL_URL_APP="http://localhost:3000"
|
||||||
|
|
||||||
# Backend url
|
# Backend url
|
||||||
IMPRESS_BASE_URL="http://localhost:8072"
|
IMPRESS_BASE_URL="http://localhost:8072"
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ DJANGO_EMAIL_FROM=<your email address>
|
|||||||
#DJANGO_EMAIL_USE_SSL=true # A flag to enable or disable SSL for email sending.
|
#DJANGO_EMAIL_USE_SSL=true # A flag to enable or disable SSL for email sending.
|
||||||
|
|
||||||
DJANGO_EMAIL_BRAND_NAME="La Suite Numérique"
|
DJANGO_EMAIL_BRAND_NAME="La Suite Numérique"
|
||||||
DJANGO_EMAIL_LOGO_IMG="https://${DOCS_HOST}/assets/logo-suite-numerique.png"
|
DJANGO_EMAIL_LOGO_IMG="https://${DOCS_HOST}/assets/logo-suite-numerique.png"
|
||||||
|
DJANGO_EMAIL_URL_APP="https://${DOCS_HOST}"
|
||||||
|
|
||||||
# Media
|
# Media
|
||||||
AWS_S3_ENDPOINT_URL=https://${S3_HOST}
|
AWS_S3_ENDPOINT_URL=https://${S3_HOST}
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ class Document(MP_Node, BaseModel):
|
|||||||
def send_email(self, subject, emails, context=None, language=None):
|
def send_email(self, subject, emails, context=None, language=None):
|
||||||
"""Generate and send email from a template."""
|
"""Generate and send email from a template."""
|
||||||
context = context or {}
|
context = context or {}
|
||||||
domain = Site.objects.get_current().domain
|
domain = settings.EMAIL_URL_APP or Site.objects.get_current().domain
|
||||||
language = language or get_language()
|
language = language or get_language()
|
||||||
context.update(
|
context.update(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1024,6 +1024,39 @@ def test_models_documents__email_invitation__success():
|
|||||||
assert f"docs/{document.id}/" in email_content
|
assert f"docs/{document.id}/" in email_content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"email_url_app",
|
||||||
|
[
|
||||||
|
"https://test-example.com", # Test with EMAIL_URL_APP set
|
||||||
|
None, # Test fallback to Site domain
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_models_documents__email_invitation__url_app_param(email_url_app):
|
||||||
|
"""
|
||||||
|
Test that email invitation uses EMAIL_URL_APP when set, or falls back to Site domain.
|
||||||
|
"""
|
||||||
|
with override_settings(EMAIL_URL_APP=email_url_app):
|
||||||
|
document = factories.DocumentFactory()
|
||||||
|
|
||||||
|
sender = factories.UserFactory(
|
||||||
|
full_name="Test Sender", email="sender@example.com"
|
||||||
|
)
|
||||||
|
document.send_invitation_email(
|
||||||
|
"guest@example.com", models.RoleChoices.EDITOR, sender, "en"
|
||||||
|
)
|
||||||
|
|
||||||
|
# pylint: disable-next=no-member
|
||||||
|
email = mail.outbox[0]
|
||||||
|
email_content = " ".join(email.body.split())
|
||||||
|
|
||||||
|
# Determine expected domain
|
||||||
|
if email_url_app:
|
||||||
|
assert f"https://test-example.com/docs/{document.id}/" in email_content
|
||||||
|
else:
|
||||||
|
# Default Site domain is example.com
|
||||||
|
assert f"example.com/docs/{document.id}/" in email_content
|
||||||
|
|
||||||
|
|
||||||
def test_models_documents__email_invitation__success_empty_title():
|
def test_models_documents__email_invitation__success_empty_title():
|
||||||
"""
|
"""
|
||||||
The email invitation is sent successfully.
|
The email invitation is sent successfully.
|
||||||
|
|||||||
@@ -459,6 +459,7 @@ class Base(Configuration):
|
|||||||
EMAIL_HOST_PASSWORD = SecretFileValue(None)
|
EMAIL_HOST_PASSWORD = SecretFileValue(None)
|
||||||
EMAIL_LOGO_IMG = values.Value(None)
|
EMAIL_LOGO_IMG = values.Value(None)
|
||||||
EMAIL_PORT = values.PositiveIntegerValue(None)
|
EMAIL_PORT = values.PositiveIntegerValue(None)
|
||||||
|
EMAIL_URL_APP = values.Value(None)
|
||||||
EMAIL_USE_TLS = values.BooleanValue(False)
|
EMAIL_USE_TLS = values.BooleanValue(False)
|
||||||
EMAIL_USE_SSL = values.BooleanValue(False)
|
EMAIL_USE_SSL = values.BooleanValue(False)
|
||||||
EMAIL_FROM = values.Value("from@example.com")
|
EMAIL_FROM = values.Value("from@example.com")
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ backend:
|
|||||||
DJANGO_EMAIL_HOST: "mailcatcher"
|
DJANGO_EMAIL_HOST: "mailcatcher"
|
||||||
DJANGO_EMAIL_LOGO_IMG: https://docs.127.0.0.1.nip.io/assets/logo-suite-numerique.png
|
DJANGO_EMAIL_LOGO_IMG: https://docs.127.0.0.1.nip.io/assets/logo-suite-numerique.png
|
||||||
DJANGO_EMAIL_PORT: 1025
|
DJANGO_EMAIL_PORT: 1025
|
||||||
|
DJANGO_EMAIL_URL_APP: https://docs.127.0.0.1.nip.io
|
||||||
DJANGO_EMAIL_USE_SSL: False
|
DJANGO_EMAIL_USE_SSL: False
|
||||||
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
||||||
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ backend:
|
|||||||
DJANGO_EMAIL_HOST: "mailcatcher"
|
DJANGO_EMAIL_HOST: "mailcatcher"
|
||||||
DJANGO_EMAIL_LOGO_IMG: https://{{ .Values.feature }}-docs.{{ .Values.domain }}/assets/logo-suite-numerique.png
|
DJANGO_EMAIL_LOGO_IMG: https://{{ .Values.feature }}-docs.{{ .Values.domain }}/assets/logo-suite-numerique.png
|
||||||
DJANGO_EMAIL_PORT: 1025
|
DJANGO_EMAIL_PORT: 1025
|
||||||
|
DJANGO_EMAIL_URL_APP: https://{{ .Values.feature }}-docs.{{ .Values.domain }}
|
||||||
DJANGO_EMAIL_USE_SSL: False
|
DJANGO_EMAIL_USE_SSL: False
|
||||||
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
LOGGING_LEVEL_HANDLERS_CONSOLE: ERROR
|
||||||
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
LOGGING_LEVEL_LOGGERS_ROOT: INFO
|
||||||
|
|||||||
Reference in New Issue
Block a user