mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Few improvements
This commit is contained in:
@@ -582,7 +582,7 @@ class WritableAccountSerializer(v1_serializers.WritableAccountSerializer):
|
||||
recipients=[validated_data["username"]],
|
||||
creator=creator,
|
||||
domain=alias["domain"]
|
||||
)
|
||||
)
|
||||
try:
|
||||
alias_recipients.remove(address)
|
||||
except ValueError:
|
||||
@@ -591,8 +591,9 @@ class WritableAccountSerializer(v1_serializers.WritableAccountSerializer):
|
||||
alias = models.Alias.objects.filter(
|
||||
address=alias_address, internal=False)
|
||||
if alias.exists():
|
||||
alias.first().remove_recipient_from_alias(
|
||||
validated_data["username"])
|
||||
alias.first().remove_recipient_or_delete(
|
||||
validated_data["username"]
|
||||
)
|
||||
instance.save()
|
||||
resources = validated_data.get("resources")
|
||||
if resources:
|
||||
|
||||
@@ -39,7 +39,7 @@ def validate_alias_address(
|
||||
condition = (
|
||||
alias.exists()
|
||||
and not ignore_existing
|
||||
)
|
||||
)
|
||||
if condition:
|
||||
raise AliasExists(alias.first().pk)
|
||||
if instance is None:
|
||||
@@ -73,16 +73,16 @@ class AliasManager(models.Manager):
|
||||
def modify_or_create(self, address, recipients, creator, domain):
|
||||
"""Add recipient if the alias already exists or create it."""
|
||||
|
||||
alias = Alias.objects.filter(address=address, internal=False)
|
||||
alias = self.get_queryset().filter(address=address, internal=False)
|
||||
if alias.exists():
|
||||
alias.first().add_recipients(recipients)
|
||||
else:
|
||||
self.create(
|
||||
creator=creator,
|
||||
domain=domain,
|
||||
address=address,
|
||||
recipients=recipients
|
||||
)
|
||||
return
|
||||
self.create(
|
||||
creator=creator,
|
||||
domain=domain,
|
||||
address=address,
|
||||
recipients=recipients
|
||||
)
|
||||
|
||||
|
||||
class Alias(AdminObject):
|
||||
@@ -208,13 +208,15 @@ class Alias(AdminObject):
|
||||
kwargs["r_mailbox"] = rcpt
|
||||
AliasRecipient(**kwargs).save()
|
||||
|
||||
def remove_recipient_from_alias(self, recipient_to_delete):
|
||||
"""Delete the selected recipient from an alias
|
||||
or delete the whole alias if only one is left."""
|
||||
def remove_recipient_or_delete(self, recipient_to_delete: str):
|
||||
"""
|
||||
Delete the selected recipient from this alias
|
||||
or delete the whole alias if only one is left.
|
||||
"""
|
||||
alias_recipients = list(self.recipients)
|
||||
if recipient_to_delete in alias_recipients:
|
||||
if len(alias_recipients) == 1:
|
||||
# Only recipient, we delete the AliasExists
|
||||
# Only recipient, we delete the Alias
|
||||
self.delete()
|
||||
else:
|
||||
alias_recipients.remove(recipient_to_delete)
|
||||
|
||||
Reference in New Issue
Block a user