✨(api) add required actions to fix domain
Send all informations about required actions to do to fix a domain and full check domain health from dimail too.
This commit is contained in:
@@ -10,6 +10,7 @@ and this project adheres to
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- ✨(domains) display required actions to do on domain
|
||||||
- ✨(plugin) add CommuneCreation plugin with domain provisioning #658
|
- ✨(plugin) add CommuneCreation plugin with domain provisioning #658
|
||||||
- ✨(frontend) display action required status on domain
|
- ✨(frontend) display action required status on domain
|
||||||
- ✨(domains) store last health check details on MailDomain
|
- ✨(domains) store last health check details on MailDomain
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
abilities = serializers.SerializerMethodField(read_only=True)
|
abilities = serializers.SerializerMethodField(read_only=True)
|
||||||
count_mailboxes = serializers.SerializerMethodField(read_only=True)
|
count_mailboxes = serializers.SerializerMethodField(read_only=True)
|
||||||
|
action_required_details = serializers.SerializerMethodField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.MailDomain
|
model = models.MailDomain
|
||||||
@@ -71,6 +72,8 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
|||||||
"updated_at",
|
"updated_at",
|
||||||
"count_mailboxes",
|
"count_mailboxes",
|
||||||
"support_email",
|
"support_email",
|
||||||
|
"last_check_details",
|
||||||
|
"action_required_details",
|
||||||
]
|
]
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
"id",
|
"id",
|
||||||
@@ -80,8 +83,23 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
|||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"count_mailboxes",
|
"count_mailboxes",
|
||||||
|
"last_check_details",
|
||||||
|
"action_required_details",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_action_required_details(self, domain) -> dict:
|
||||||
|
"""Return last check details of the domain."""
|
||||||
|
details = {}
|
||||||
|
if domain.last_check_details:
|
||||||
|
for check, value in domain.last_check_details.items():
|
||||||
|
if (
|
||||||
|
isinstance(value, dict)
|
||||||
|
and value.get("ok") is False
|
||||||
|
and value.get("internal") is False
|
||||||
|
):
|
||||||
|
details[check] = value["errors"][0].get("detail")
|
||||||
|
return details
|
||||||
|
|
||||||
def get_abilities(self, domain) -> dict:
|
def get_abilities(self, domain) -> dict:
|
||||||
"""Return abilities of the logged-in user on the instance."""
|
"""Return abilities of the logged-in user on the instance."""
|
||||||
request = self.context.get("request")
|
request = self.context.get("request")
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ def test_api_mail_domains__create_authenticated():
|
|||||||
"abilities": domain.get_abilities(user),
|
"abilities": domain.get_abilities(user),
|
||||||
"count_mailboxes": 0,
|
"count_mailboxes": 0,
|
||||||
"support_email": domain.support_email,
|
"support_email": domain.support_email,
|
||||||
|
"last_check_details": None,
|
||||||
|
"action_required_details": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
# a new domain with status "pending" is created and authenticated user is the owner
|
# a new domain with status "pending" is created and authenticated user is the owner
|
||||||
@@ -198,6 +200,8 @@ def test_api_mail_domains__create_authenticated__dimail_failure():
|
|||||||
"abilities": domain.get_abilities(user),
|
"abilities": domain.get_abilities(user),
|
||||||
"count_mailboxes": 0,
|
"count_mailboxes": 0,
|
||||||
"support_email": domain.support_email,
|
"support_email": domain.support_email,
|
||||||
|
"last_check_details": None,
|
||||||
|
"action_required_details": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
# a new domain with status "failed" is created and authenticated user is the owner
|
# a new domain with status "failed" is created and authenticated user is the owner
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ from rest_framework.test import APIClient
|
|||||||
|
|
||||||
from core import factories as core_factories
|
from core import factories as core_factories
|
||||||
|
|
||||||
from mailbox_manager import factories
|
from mailbox_manager import enums, factories
|
||||||
|
from mailbox_manager.tests.fixtures import dimail as dimail_fixtures
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
@@ -88,4 +89,80 @@ def test_api_mail_domains__retrieve_authenticated_related():
|
|||||||
"abilities": domain.get_abilities(user),
|
"abilities": domain.get_abilities(user),
|
||||||
"count_mailboxes": 10,
|
"count_mailboxes": 10,
|
||||||
"support_email": domain.support_email,
|
"support_email": domain.support_email,
|
||||||
|
"last_check_details": None,
|
||||||
|
"action_required_details": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_mail_domains__retrieve_authenticated_related_with_action_required():
|
||||||
|
"""
|
||||||
|
Authenticated users should be allowed to retrieve a domain
|
||||||
|
to which they have access and which has actions required to be done.
|
||||||
|
"""
|
||||||
|
user = core_factories.UserFactory()
|
||||||
|
|
||||||
|
client = APIClient()
|
||||||
|
client.force_login(user)
|
||||||
|
|
||||||
|
domain = factories.MailDomainFactory(
|
||||||
|
status=enums.MailDomainStatusChoices.ACTION_REQUIRED,
|
||||||
|
last_check_details=dimail_fixtures.CHECK_DOMAIN_BROKEN_EXTERNAL,
|
||||||
|
)
|
||||||
|
factories.MailDomainAccessFactory(domain=domain, user=user)
|
||||||
|
|
||||||
|
response = client.get(
|
||||||
|
f"/api/v1.0/mail-domains/{domain.slug}/",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == status.HTTP_200_OK
|
||||||
|
assert response.json() == {
|
||||||
|
"id": str(domain.id),
|
||||||
|
"name": domain.name,
|
||||||
|
"slug": domain.slug,
|
||||||
|
"status": domain.status,
|
||||||
|
"created_at": domain.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": domain.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"abilities": domain.get_abilities(user),
|
||||||
|
"count_mailboxes": 0,
|
||||||
|
"support_email": domain.support_email,
|
||||||
|
"last_check_details": dimail_fixtures.CHECK_DOMAIN_BROKEN_EXTERNAL,
|
||||||
|
"action_required_details": {
|
||||||
|
"mx": "Je veux que le MX du domaine soit mx.ox.numerique.gouv.fr., "
|
||||||
|
"or je trouve example-fr.mail.protection.outlook.com.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_mail_domains__retrieve_authenticated_related_with_ok_status():
|
||||||
|
"""
|
||||||
|
Authenticated users should be allowed to retrieve a domain
|
||||||
|
to which they have access and which has no actions required to be done.
|
||||||
|
"""
|
||||||
|
user = core_factories.UserFactory()
|
||||||
|
|
||||||
|
client = APIClient()
|
||||||
|
client.force_login(user)
|
||||||
|
|
||||||
|
domain = factories.MailDomainEnabledFactory(
|
||||||
|
last_check_details=dimail_fixtures.CHECK_DOMAIN_OK,
|
||||||
|
)
|
||||||
|
factories.MailDomainAccessFactory(domain=domain, user=user)
|
||||||
|
|
||||||
|
response = client.get(
|
||||||
|
f"/api/v1.0/mail-domains/{domain.slug}/",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == status.HTTP_200_OK
|
||||||
|
assert response.json() == {
|
||||||
|
"id": str(domain.id),
|
||||||
|
"name": domain.name,
|
||||||
|
"slug": domain.slug,
|
||||||
|
"status": domain.status,
|
||||||
|
"created_at": domain.created_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"updated_at": domain.updated_at.isoformat().replace("+00:00", "Z"),
|
||||||
|
"abilities": domain.get_abilities(user),
|
||||||
|
"count_mailboxes": 0,
|
||||||
|
"support_email": domain.support_email,
|
||||||
|
"last_check_details": dimail_fixtures.CHECK_DOMAIN_OK,
|
||||||
|
"action_required_details": {},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user