Prevent deleting the same domain multiple times on bulk deletes
This commit is contained in:
parent
06bfa2c767
commit
3cdeb6010d
|
@ -5,7 +5,7 @@ from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from orchestra.core.validators import validate_password
|
from orchestra.core import validators
|
||||||
|
|
||||||
from .models import DatabaseUser, Database
|
from .models import DatabaseUser, Database
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from .models import DatabaseUser, Database
|
||||||
class DatabaseUserCreationForm(forms.ModelForm):
|
class DatabaseUserCreationForm(forms.ModelForm):
|
||||||
password1 = forms.CharField(label=_("Password"), required=False,
|
password1 = forms.CharField(label=_("Password"), required=False,
|
||||||
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
||||||
validators=[validate_password])
|
validators=[validators.validate_password])
|
||||||
password2 = forms.CharField(label=_("Password confirmation"), required=False,
|
password2 = forms.CharField(label=_("Password confirmation"), required=False,
|
||||||
widget=forms.PasswordInput,
|
widget=forms.PasswordInput,
|
||||||
help_text=_("Enter the same password as above, for verification."))
|
help_text=_("Enter the same password as above, for verification."))
|
||||||
|
@ -32,12 +32,12 @@ class DatabaseUserCreationForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class DatabaseCreationForm(DatabaseUserCreationForm):
|
class DatabaseCreationForm(DatabaseUserCreationForm):
|
||||||
username = forms.RegexField(label=_("Username"), max_length=30,
|
username = forms.CharField(label=_("Username"), max_length=16,
|
||||||
required=False, regex=r'^[\w.@+-]+$',
|
required=False, validators=[validators.validate_name],
|
||||||
help_text=_("Required. 30 characters or fewer. Letters, digits and "
|
help_text=_("Required. 16 characters or fewer. Letters, digits and "
|
||||||
"@/./+/-/_ only."),
|
"@/./+/-/_ only."),
|
||||||
error_messages={
|
error_messages={
|
||||||
'invalid': _("This value may contain only letters, numbers and "
|
'invalid': _("This value may contain 16 characters or fewer, only letters, numbers and "
|
||||||
"@/./+/-/_ characters.")})
|
"@/./+/-/_ characters.")})
|
||||||
user = forms.ModelChoiceField(required=False, queryset=DatabaseUser.objects)
|
user = forms.ModelChoiceField(required=False, queryset=DatabaseUser.objects)
|
||||||
|
|
||||||
|
|
|
@ -264,6 +264,11 @@ class PostfixAddressVirtualDomainBackend(ServiceController):
|
||||||
def exclude_virtual_alias_domain(self, context):
|
def exclude_virtual_alias_domain(self, context):
|
||||||
domain = context['domain']
|
domain = context['domain']
|
||||||
if self.is_last_domain(domain):
|
if self.is_last_domain(domain):
|
||||||
|
# Prevent deleting the same domain multiple times on bulk deletes
|
||||||
|
if not hasattr(self, '_excluded_domains'):
|
||||||
|
self._excluded_domains = set()
|
||||||
|
if domain.name not in self._excluded_domains:
|
||||||
|
self._excluded_domains.add(domain.name)
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
# Delete %(domain)s virtual domain
|
# Delete %(domain)s virtual domain
|
||||||
if grep '^%(domain)s\s*$' %(virtual_alias_domains)s > /dev/null; then
|
if grep '^%(domain)s\s*$' %(virtual_alias_domains)s > /dev/null; then
|
||||||
|
@ -378,7 +383,7 @@ class PostfixAddressBackend(PostfixAddressVirtualDomainBackend):
|
||||||
self.update_virtual_alias_maps(address, context)
|
self.update_virtual_alias_maps(address, context)
|
||||||
|
|
||||||
def delete(self, address):
|
def delete(self, address):
|
||||||
context = super().save(address)
|
context = super().delete(address)
|
||||||
self.exclude_virtual_alias_maps(context)
|
self.exclude_virtual_alias_maps(context)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
|
|
Loading…
Reference in New Issue