mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-23 06:38:40 +02:00
Generic transport editor. (#1309)
Generic transport editor. see #1301 * Fixed unit test. * Added unit tests. * Fixed unit test. * Added transport module to test list. * Moved relay transport backend to appropriate app. see #1301 * Added missing file.
This commit is contained in:
@@ -5,11 +5,27 @@ from __future__ import unicode_literals
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
|
||||
from modoboa.core import models as core_models
|
||||
from modoboa.lib.permissions import (
|
||||
grant_access_to_object, ungrant_access_to_object
|
||||
)
|
||||
|
||||
|
||||
class AdminObjectManager(models.Manager):
|
||||
|
||||
def get_for_admin(self, admin):
|
||||
"""Return the objects belonging to this admin
|
||||
|
||||
The result is a ``QuerySet`` object, so this function can be used
|
||||
to fill ``ModelChoiceField`` objects.
|
||||
"""
|
||||
if admin.is_superuser:
|
||||
return self.get_queryset()
|
||||
return self.get_queryset().filter(owners__user=admin)
|
||||
|
||||
|
||||
class AdminObject(models.Model):
|
||||
"""Abstract model to support dates.
|
||||
|
||||
@@ -20,8 +36,11 @@ class AdminObject(models.Model):
|
||||
|
||||
creation = models.DateTimeField(default=timezone.now)
|
||||
last_modification = models.DateTimeField(auto_now=True)
|
||||
owners = GenericRelation(core_models.ObjectAccess)
|
||||
_objectname = None
|
||||
|
||||
objects = AdminObjectManager()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from functools import reduce
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.manager import Manager
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import (
|
||||
python_2_unicode_compatible, smart_text, force_text
|
||||
@@ -14,31 +12,15 @@ from django.utils.encoding import (
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from modoboa.core import signals as core_signals
|
||||
from modoboa.core.models import User, ObjectAccess
|
||||
from modoboa.core.models import User
|
||||
from modoboa.lib.exceptions import BadRequest, Conflict
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
from .base import AdminObject
|
||||
from .. import constants
|
||||
from .. import signals
|
||||
|
||||
|
||||
class DomainManager(Manager):
|
||||
|
||||
def get_for_admin(self, admin):
|
||||
"""Return the domains belonging to this admin
|
||||
|
||||
The result is a ``QuerySet`` object, so this function can be used
|
||||
to fill ``ModelChoiceField`` objects.
|
||||
"""
|
||||
if admin.is_superuser:
|
||||
return self.get_queryset()
|
||||
return self.get_queryset().filter(owners__user=admin)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
@@ -67,15 +49,12 @@ class Domain(AdminObject):
|
||||
help_text=ugettext_lazy("Check to activate this domain"),
|
||||
default=True
|
||||
)
|
||||
owners = GenericRelation(ObjectAccess)
|
||||
type = models.CharField(default="domain", max_length=20)
|
||||
enable_dns_checks = models.BooleanField(
|
||||
ugettext_lazy("Enable DNS checks"), default=True,
|
||||
help_text=ugettext_lazy("Check to enable DNS checks for this domain")
|
||||
)
|
||||
|
||||
objects = DomainManager()
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
("view_domain", "View domain"),
|
||||
@@ -111,11 +90,11 @@ class Domain(AdminObject):
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
if self.type == "domain":
|
||||
return [{"name": "domain", "label": _("Domain"), "type": "dom"}]
|
||||
results = signals.get_domain_tags.send(
|
||||
sender=self.__class__, domain=self)
|
||||
return reduce(lambda a, b: a + b, [result[1] for result in results])
|
||||
label = ""
|
||||
for dt in constants.DOMAIN_TYPES:
|
||||
if self.type == dt[0]:
|
||||
label = dt[1]
|
||||
return [{"name": self.type, "label": label, "type": "dom"}]
|
||||
|
||||
@property
|
||||
def admins(self):
|
||||
|
||||
@@ -345,6 +345,7 @@ class Mailbox(AdminObject):
|
||||
username=self.full_address)
|
||||
super(Mailbox, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
reversion.register(Mailbox)
|
||||
|
||||
|
||||
@@ -365,6 +366,7 @@ class SenderAddress(models.Model):
|
||||
"""Return address."""
|
||||
return smart_text(self.address)
|
||||
|
||||
|
||||
reversion.register(SenderAddress)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user