🗃️(mailbox_manager) add organization to domain
To be able to provide a SIRET in the ProConnect IdP process we need to be able to link a mail domain to its organization. For now this is not mandatory, as we can't detect the organization and need a frontend process to clarify it.
This commit is contained in:
@@ -144,12 +144,13 @@ class MailDomainAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = (
|
||||
"name",
|
||||
"organization",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"slug",
|
||||
"status",
|
||||
)
|
||||
search_fields = ("name",)
|
||||
search_fields = ("name", "organization__name")
|
||||
readonly_fields = ["created_at", "slug"]
|
||||
list_filter = ("status",)
|
||||
inlines = (UserMailDomainAccessInline,)
|
||||
@@ -158,6 +159,7 @@ class MailDomainAdmin(admin.ModelAdmin):
|
||||
fetch_domain_status_from_dimail,
|
||||
fetch_domain_expected_config_from_dimail,
|
||||
)
|
||||
autocomplete_fields = ["organization"]
|
||||
|
||||
|
||||
@admin.register(models.Mailbox)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-10 11:10
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0010_team_depth_team_numchild_team_path_and_more'),
|
||||
('mailbox_manager', '0017_alter_maildomain_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='maildomain',
|
||||
name='organization',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='mail_domains', to='core.organization'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-10 11:10
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0010_team_depth_team_numchild_team_path_and_more'),
|
||||
('mailbox_manager', '0021_maildomain_expected_config'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='maildomain',
|
||||
name='organization',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='mail_domains', to='core.organization'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,52 @@
|
||||
# Generated by Django 5.1.5 on 2025-02-07 16:13
|
||||
|
||||
import django.db.models.functions.text
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def fill_dn_email(apps, schema_editor):
|
||||
"""Fill the dn_email field with the email field."""
|
||||
Mailbox = apps.get_model("mailbox_manager", "Mailbox")
|
||||
|
||||
for mailbox in Mailbox.objects.select_related("domain").filter(
|
||||
models.Q(dn_email="") | models.Q(dn_email__isnull=True)
|
||||
):
|
||||
# quite naive but we don't have many data
|
||||
mailbox.dn_email = mailbox.get_email()
|
||||
mailbox.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mailbox_manager', '0020_maildomain_organization'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mailbox',
|
||||
name='last_login',
|
||||
field=models.DateTimeField(blank=True, null=True, verbose_name='last login'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mailbox',
|
||||
name='password',
|
||||
field=models.CharField(default='', max_length=128, verbose_name='password'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mailbox',
|
||||
name='dn_email',
|
||||
field=models.EmailField(blank=True, editable=False, max_length=254, null=True, unique=True,
|
||||
verbose_name='email'),
|
||||
),
|
||||
migrations.RunPython(
|
||||
code=fill_dn_email,
|
||||
reverse_code=migrations.RunPython.noop,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='mailbox',
|
||||
name='dn_email',
|
||||
field=models.EmailField(blank=True, editable=False, max_length=254, unique=True, verbose_name='email'),
|
||||
),
|
||||
]
|
||||
@@ -8,7 +8,7 @@ from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import BaseModel
|
||||
from core.models import BaseModel, Organization
|
||||
|
||||
from mailbox_manager.enums import (
|
||||
MailboxStatusChoices,
|
||||
@@ -23,6 +23,13 @@ class MailDomain(BaseModel):
|
||||
name = models.CharField(
|
||||
_("name"), max_length=150, null=False, blank=False, unique=True
|
||||
)
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="mail_domains",
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
slug = models.SlugField(null=False, blank=False, unique=True, max_length=80)
|
||||
status = models.CharField(
|
||||
max_length=20,
|
||||
|
||||
Reference in New Issue
Block a user