🐛(domains) use a dedicated mail to invite user to manage domain
- modify models to allow to specify path to mail template - rename team invitation template - fix logo and text used for domain invitation email
This commit is contained in:
@@ -7,6 +7,7 @@ from django.contrib.auth.base_user import AbstractBaseUser
|
||||
from django.core import exceptions, validators
|
||||
from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import BaseInvitation, BaseModel, Organization, User
|
||||
@@ -294,6 +295,9 @@ class MailDomainInvitation(BaseInvitation):
|
||||
default=MailDomainRoleChoices.VIEWER,
|
||||
)
|
||||
|
||||
MAIL_TEMPLATE_HTML = "mail/html/maildomain_invitation.html"
|
||||
MAIL_TEMPLATE_TXT = "mail/text/maildomain_invitation.txt"
|
||||
|
||||
class Meta:
|
||||
db_table = "people_mail_domain_invitation"
|
||||
verbose_name = _("Mail domain invitation")
|
||||
@@ -307,6 +311,18 @@ class MailDomainInvitation(BaseInvitation):
|
||||
def __str__(self):
|
||||
return f"{self.email} invited to {self.domain}"
|
||||
|
||||
def _get_mail_subject(self):
|
||||
"""Get the subject of the invitation."""
|
||||
return gettext("[La Suite] You have been invited to join La Régie")
|
||||
|
||||
def _get_mail_context(self):
|
||||
"""Get the template variables for the invitation."""
|
||||
return {
|
||||
**super()._get_mail_context(),
|
||||
"domain": self.domain.name,
|
||||
"role": self.get_role_display(),
|
||||
}
|
||||
|
||||
def get_abilities(self, user):
|
||||
"""Compute and return abilities for a given user."""
|
||||
can_delete = False
|
||||
|
||||
@@ -3,6 +3,8 @@ Tests for MailDomainInvitations API endpoint in People's app mailbox_manager.
|
||||
Focus on "create" action.
|
||||
"""
|
||||
|
||||
from django.core import mail
|
||||
|
||||
import pytest
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
@@ -70,12 +72,18 @@ def test_api_domain_invitations__admin_should_create_invites(role):
|
||||
client = APIClient()
|
||||
client.force_login(user)
|
||||
|
||||
assert len(mail.outbox) == 0
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1.0/mail-domains/{domain.slug}/invitations/",
|
||||
invitation_values,
|
||||
format="json",
|
||||
)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert len(mail.outbox) == 1
|
||||
email = mail.outbox[0]
|
||||
assert email.to == [invitation_values["email"]]
|
||||
assert email.subject == "[La Suite] You have been invited to join La Régie"
|
||||
|
||||
|
||||
def test_api_domain_invitations__viewers_should_not_invite_to_manage_domains():
|
||||
|
||||
Reference in New Issue
Block a user