Added command to repair old postfix autoreply setups

This commit is contained in:
Antoine Nguyen
2024-07-17 17:36:38 +02:00
parent 0f5c53d1ba
commit 3ec023fa23
2 changed files with 23 additions and 10 deletions
+11 -10
View File
@@ -144,6 +144,17 @@ Version 2.3.0
new migrations **AFTER** the following instructions. If you don't,
you'll get into trouble...
Pre update
----------
Before your start upgrading modoboa, run the following commands from
your virtual environment:
.. sourcecode:: bash
> python manage.py modo repair
> python manage.py rename_app modoboa_postfix_autoreply postfix_autoreply
Required changes to :file:`settings.py`
---------------------------------------
@@ -301,16 +312,6 @@ SORBS DNS
bl.spameatingmonkey.net=127.0.0.2*2
bl.spamcop.net=127.0.0.2
Post update
-----------
After upgrading modoboa, run the following commands from your virtual environment:
.. sourcecode:: bash
> python manage.py rename_app modoboa_postfix_autoreply postfix_autoreply
Version 2.2.3
=============
@@ -4,6 +4,9 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils.encoding import smart_str
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from modoboa.admin import models
from modoboa.core.models import User
from modoboa.lib.permissions import get_object_owner, grant_access_to_object
@@ -89,6 +92,15 @@ def sometimes_mailbox_have_no_alias(**options):
)
@known_problem
def postfix_autoreply_old_contenttypes(**options):
"""Sometime old postfix autoreply contenttypes might be present."""
for ct in ContentType.objects.filter(app_label="postfix_autoreply"):
result = Permission.objects.filter(content_type=ct).delete()
ct.delete()
log(f"Removed content type {ct.name} and {result[0]} associated permssions")
class Repair(BaseCommand):
"""Command class."""