(models) impose uniqueness on display name, to match ox's constraint

OpenXchange's primary key is display name (= first name + last name).
It must be unique in the domain's context. We don't have context info
but we can impose uniqueness by domain.
This commit is contained in:
Marie PUPO JEAMMET
2025-09-08 16:38:41 +02:00
committed by Marie
parent 608f8c6988
commit b24cb23a83
3 changed files with 111 additions and 4 deletions

View File

@@ -303,7 +303,15 @@ class Mailbox(AbstractBaseUser, BaseModel):
db_table = "people_mail_box"
verbose_name = _("Mailbox")
verbose_name_plural = _("Mailboxes")
unique_together = ("local_part", "domain")
constraints = [
models.UniqueConstraint(
fields=["local_part", "domain"], name="unique_username"
),
models.UniqueConstraint(
fields=["first_name", "last_name", "domain"],
name="unique_ox_display_name",
),
]
ordering = ["-created_at"]
def __str__(self):