✨(api) add count mailboxes to MailDomain serializer
Return number of mailboxes of a domain in our API.
This commit is contained in:
@@ -10,6 +10,7 @@ and this project adheres to
|
||||
|
||||
### Added
|
||||
|
||||
- ✨(api) add count mailboxes to MailDomain serializer
|
||||
- ✨(dimail) manage 'action required' status for MailDomain
|
||||
- ✨(domains) add action required status on MailDomain
|
||||
- ✨(dimail) send pending mailboxes upon domain activation
|
||||
|
||||
@@ -56,6 +56,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
||||
"""Serialize mail domain."""
|
||||
|
||||
abilities = serializers.SerializerMethodField(read_only=True)
|
||||
count_mailboxes = serializers.SerializerMethodField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = models.MailDomain
|
||||
@@ -68,6 +69,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
||||
"abilities",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"count_mailboxes",
|
||||
]
|
||||
read_only_fields = [
|
||||
"id",
|
||||
@@ -76,6 +78,7 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
||||
"abilities",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"count_mailboxes",
|
||||
]
|
||||
|
||||
def get_abilities(self, domain) -> dict:
|
||||
@@ -85,6 +88,10 @@ class MailDomainSerializer(serializers.ModelSerializer):
|
||||
return domain.get_abilities(request.user)
|
||||
return {}
|
||||
|
||||
def get_count_mailboxes(self, domain) -> int:
|
||||
"""Return count of mailboxes for the domain."""
|
||||
return domain.mailboxes.count()
|
||||
|
||||
def create(self, validated_data):
|
||||
"""
|
||||
Override create function to fire a request to dimail upon domain creation.
|
||||
|
||||
@@ -114,6 +114,7 @@ def test_api_mail_domains__create_authenticated():
|
||||
"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,
|
||||
}
|
||||
|
||||
# a new domain with status "pending" is created and authenticated user is the owner
|
||||
@@ -185,6 +186,7 @@ def test_api_mail_domains__create_authenticated__dimail_failure():
|
||||
"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,
|
||||
}
|
||||
|
||||
# a new domain with status "failed" is created and authenticated user is the owner
|
||||
|
||||
@@ -71,6 +71,7 @@ def test_api_mail_domains__retrieve_authenticated_related():
|
||||
|
||||
domain = factories.MailDomainEnabledFactory()
|
||||
factories.MailDomainAccessFactory(domain=domain, user=user)
|
||||
factories.MailboxFactory.create_batch(10, domain=domain)
|
||||
|
||||
response = client.get(
|
||||
f"/api/v1.0/mail-domains/{domain.slug}/",
|
||||
@@ -85,4 +86,5 @@ def test_api_mail_domains__retrieve_authenticated_related():
|
||||
"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": 10,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user