Skip to content

Commit

Permalink
🐛(maildomain) fix domain access creation
Browse files Browse the repository at this point in the history
If creating a user or allow in dimail after
domain creation fails, creation of domain access
on our side is not called.
So the domain is created but the user cannot see
his domain and he will try to create his domain
again and will get an error message.
To avoid this, we make sure to create the
user's domain access on our side despite
a dimail failure and log a error message.
  • Loading branch information
sdemagny committed Dec 16, 2024
1 parent fa80edf commit 91c4f5f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/backend/mailbox_manager/api/client/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Client serializers for People's mailbox manager app."""

import json
from logging import getLogger

from requests.exceptions import HTTPError
from rest_framework import exceptions, serializers

from core.api.client.serializers import UserSerializer
Expand All @@ -10,6 +12,8 @@
from mailbox_manager import enums, models
from mailbox_manager.utils.dimail import DimailAPIClient

logger = getLogger(__name__)


class MailboxSerializer(serializers.ModelSerializer):
"""Serialize mailbox."""
Expand Down Expand Up @@ -194,10 +198,13 @@ def create(self, validated_data):
enums.MailDomainRoleChoices.ADMIN,
enums.MailDomainRoleChoices.OWNER,
]:
dimail.create_user(validated_data["user"].sub)
dimail.create_allow(
validated_data["user"].sub, validated_data["domain"].name
)
try:
dimail.create_user(validated_data["user"].sub)
dimail.create_allow(
validated_data["user"].sub, validated_data["domain"].name
)
except HTTPError:
logger.error("[DIMAIL] access creation failed %s")

return super().create(validated_data)

Expand Down

0 comments on commit 91c4f5f

Please sign in to comment.