mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
wip: UI refactoring
* fixed an issue with the FETCH responses parser * Aliases are now displayed into *identities* * French translation update see #204
This commit is contained in:
+67
-27
@@ -196,28 +196,22 @@ class DlistForm(forms.ModelForm, DynamicForm):
|
||||
self.save_m2m()
|
||||
return dlist
|
||||
|
||||
class ForwardForm(forms.ModelForm):
|
||||
class GenericAliasForm(forms.ModelForm):
|
||||
email = forms.EmailField(
|
||||
label=ugettext_lazy("Email address"),
|
||||
help_text=ugettext_lazy("The forwarded address")
|
||||
label=ugettext_lazy("Address"),
|
||||
help_text=ugettext_lazy("A valid e-mail address")
|
||||
)
|
||||
recipient = forms.EmailField(
|
||||
label=ugettext_lazy("Recipient"),
|
||||
help_text=ugettext_lazy("The address to forward messages to")
|
||||
)
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Alias
|
||||
fields = ("enabled",)
|
||||
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
self.user = user
|
||||
super(ForwardForm, self).__init__(*args, **kwargs)
|
||||
self.fields.keyOrder = ['email', 'recipient', 'enabled']
|
||||
super(GenericAliasForm, self).__init__(*args, **kwargs)
|
||||
if kwargs.has_key("instance"):
|
||||
forward = kwargs["instance"]
|
||||
self.fields["email"].initial = forward.full_address
|
||||
self.fields["recipient"].initial = forward.extmboxes
|
||||
alias = kwargs["instance"]
|
||||
self.fields["email"].initial = alias.full_address
|
||||
|
||||
def clean_email(self):
|
||||
localpart, domname = split_mailbox(self.cleaned_data["email"])
|
||||
@@ -229,27 +223,73 @@ class ForwardForm(forms.ModelForm):
|
||||
raise forms.ValidationError(_("You don't have access to this domain"))
|
||||
return self.cleaned_data["email"]
|
||||
|
||||
def clean_recipient(self):
|
||||
local_part, domname = split_mailbox(self.cleaned_data["recipient"])
|
||||
def set_recipients(self):
|
||||
pass
|
||||
|
||||
def _save(self):
|
||||
alias = super(GenericAliasForm, self).save(commit=False)
|
||||
localpart, domname = split_mailbox(self.cleaned_data["email"])
|
||||
alias.address = localpart
|
||||
alias.domain = Domain.objects.get(name=domname)
|
||||
return alias
|
||||
|
||||
class AliasForm(GenericAliasForm):
|
||||
int_recipient = forms.EmailField(
|
||||
label=ugettext_lazy("Recipient"),
|
||||
help_text=ugettext_lazy("A local recipient address")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AliasForm, self).__init__(*args, **kwargs)
|
||||
self.fields.keyOrder = ['email', 'int_recipient', 'enabled']
|
||||
if kwargs.has_key("instance"):
|
||||
alias = kwargs["instance"]
|
||||
self.fields["int_recipient"].initial = alias.mboxes.all()[0].full_address
|
||||
|
||||
def clean_int_recipient(self):
|
||||
localpart, domname = split_mailbox(self.cleaned_data["int_recipient"])
|
||||
try:
|
||||
self.rcpt_mb = Mailbox.objects.get(address=localpart, domain__name=domname)
|
||||
except Mailbox.DoesNotExist:
|
||||
raise forms.ValidationError(_("Mailbox does not exist"))
|
||||
if not self.user.can_access(self.rcpt_mb):
|
||||
raise forms.ValidationError(_("You can't access this mailbox"))
|
||||
return self.cleaned_data["int_recipient"]
|
||||
|
||||
def save(self, commit=True):
|
||||
alias = self._save()
|
||||
if commit:
|
||||
alias.save([self.rcpt_mb], [])
|
||||
return alias
|
||||
|
||||
class ForwardForm(GenericAliasForm):
|
||||
ext_recipient = forms.EmailField(
|
||||
label=ugettext_lazy("Recipient"),
|
||||
help_text=ugettext_lazy("An external recipient address")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ForwardForm, self).__init__(*args, **kwargs)
|
||||
self.fields.keyOrder = ['email', 'ext_recipient', 'enabled']
|
||||
if kwargs.has_key("instance"):
|
||||
alias = kwargs["instance"]
|
||||
self.fields["ext_recipient"].initial = alias.extmboxes
|
||||
|
||||
def clean_ext_recipient(self):
|
||||
local_part, domname = split_mailbox(self.cleaned_data["ext_recipient"])
|
||||
try:
|
||||
domain = Domain.objects.get(name=domname)
|
||||
except Domain.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
raise forms.ValidationError(_("Local addresses are forbidden"))
|
||||
return self.cleaned_data["recipient"]
|
||||
|
||||
def set_recipients(self):
|
||||
pass
|
||||
raise forms.ValidationError(_("Local recipients are forbidden"))
|
||||
return self.cleaned_data["ext_recipient"]
|
||||
|
||||
def save(self, commit=True):
|
||||
forward = super(ForwardForm, self).save(commit=False)
|
||||
localpart, domname = split_mailbox(self.cleaned_data["email"])
|
||||
forward.address = localpart
|
||||
forward.domain = Domain.objects.get(name=domname)
|
||||
alias = self._save()
|
||||
if commit:
|
||||
forward.save([], [self.cleaned_data["recipient"]])
|
||||
return forward
|
||||
alias.save([], [self.cleaned_data["ext_recipient"]])
|
||||
return alias
|
||||
|
||||
class ImportDataForm(forms.Form):
|
||||
sourcefile = forms.FileField(label=ugettext_lazy("Select a file"))
|
||||
@@ -389,7 +429,7 @@ class AccountFormMail(forms.Form, DynamicForm):
|
||||
raise AdminError(_("Domain does not exist"))
|
||||
|
||||
if not user.can_access(domain):
|
||||
raise PermDeniedException(_("You don't have access to this domain"))
|
||||
raise PermDeniedException
|
||||
|
||||
if not hasattr(self, "mb") or self.mb is None:
|
||||
try:
|
||||
|
||||
@@ -11,7 +11,8 @@ class Migration(DataMigration):
|
||||
try:
|
||||
sugroup = orm["auth.Group"].objects.get(name="SimpleUsers")
|
||||
except orm["auth.Group"].DoesNotExist:
|
||||
return
|
||||
sugroup = orm["auth.Group"](name="SimpleUsers")
|
||||
sugroup.save()
|
||||
for account in orm["auth.User"].objects.all():
|
||||
if not len(account.groups.all()):
|
||||
account.groups.add(sugroup)
|
||||
|
||||
+7
-4
@@ -35,6 +35,7 @@ class User(DUser):
|
||||
"""
|
||||
class Meta:
|
||||
proxy = True
|
||||
ordering = ["username"]
|
||||
|
||||
password_expr = re.compile(r'\{(\w+)\}(.+)')
|
||||
|
||||
@@ -70,12 +71,12 @@ class User(DUser):
|
||||
raise AdminError(_("You can't delete your own account"))
|
||||
|
||||
if not fromuser.can_access(self):
|
||||
raise PermDeniedException("You don't have access to this account")
|
||||
raise PermDeniedException
|
||||
|
||||
if self.has_mailbox:
|
||||
mb = self.mailbox_set.all()[0]
|
||||
if not fromuser.can_access(mb):
|
||||
raise PermDeniedException(_("You don't have access to this mailbox"))
|
||||
raise PermDeniedException
|
||||
mb.delete(keepdir=keep_mb_dir)
|
||||
|
||||
owner = get_object_owner(self)
|
||||
@@ -383,6 +384,7 @@ class Domain(DatesAware):
|
||||
("view_domain", "View domain"),
|
||||
("view_domains", "View domains"),
|
||||
)
|
||||
ordering = ["name"]
|
||||
|
||||
@property
|
||||
def domainalias_count(self):
|
||||
@@ -672,7 +674,7 @@ class Mailbox(DatesAware):
|
||||
except Domain.DoesNotExist:
|
||||
raise AdminError(_("Cannot import this mailbox because the associated domain does not exist"))
|
||||
if not user.can_access(self.domain):
|
||||
raise PermDeniedException(_("You don't have access to this domain"))
|
||||
raise PermDeniedException
|
||||
|
||||
name = "%s %s" % (line[3].strip(), line[4].strip())
|
||||
self.save(username=line[1].strip(), name=name,
|
||||
@@ -711,6 +713,7 @@ class Alias(DatesAware):
|
||||
("view_aliases", "View aliases"),
|
||||
)
|
||||
unique_together = (("address", "domain"),)
|
||||
ordering = ["domain__name", "address"]
|
||||
|
||||
@property
|
||||
def full_address(self):
|
||||
@@ -775,7 +778,7 @@ class Alias(DatesAware):
|
||||
except Domain.DoesNotExist:
|
||||
raise AdminError(_("Domain does not exist"))
|
||||
if not user.can_access(domain):
|
||||
raise PermDeniedException(_("You can't access this domain"))
|
||||
raise PermDeniedException
|
||||
self.address = localpart
|
||||
self.domain = domain
|
||||
self.enabled = True
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class IdentitiesTable(tables.Table):
|
||||
"identity", label=ugettext_lazy("Email/Username"),
|
||||
modal=True,
|
||||
urlpattern={"User" : "modoboa.admin.views.editaccount",
|
||||
"Alias" : "modoboa.admin.views.editalias"},
|
||||
"Alias" : "modoboa.admin.views.editalias_dispatcher"},
|
||||
modalcb={"User" : "editaccount_cb", "Alias" : "aliasform_cb"}
|
||||
)
|
||||
name_or_rcpt = tables.Column("name_or_rcpt", label=ugettext_lazy("Fullname/Recipient"))
|
||||
|
||||
@@ -92,6 +92,12 @@ def identities_menu(user):
|
||||
"modal" : True,
|
||||
"modalcb" : "newaccount_cb",
|
||||
"url" : reverse(admin.views.newaccount)},
|
||||
{"name" : "newalias",
|
||||
"label" : _("Add alias"),
|
||||
"img" : "icon-plus",
|
||||
"modal" : True,
|
||||
"modalcb" : "aliasform_cb",
|
||||
"url" : reverse(admin.views.newalias)},
|
||||
{"name" : "newforward",
|
||||
"label" : _("Add forward"),
|
||||
"img" : "icon-plus",
|
||||
@@ -148,13 +154,20 @@ def identity_actions(user, iid):
|
||||
"img" : "icon-trash",
|
||||
"title" : _("Delete this distribution list")},
|
||||
]
|
||||
else:
|
||||
elif alias.extmboxes != "":
|
||||
actions = [
|
||||
{"name" : "delforward",
|
||||
"url" : reverse(admin.views.delforward) + "?selection=%s" % objid,
|
||||
"img" : "icon-trash",
|
||||
"title" : _("Delete this forward")},
|
||||
]
|
||||
else:
|
||||
actions = [
|
||||
{"name" : "delalias",
|
||||
"url" : reverse(admin.views.delalias) + "?selection=%s" % objid,
|
||||
"img" : "icon-trash",
|
||||
"title" : _("Delete this alias")},
|
||||
]
|
||||
return render_actions(actions)
|
||||
|
||||
@register.simple_tag
|
||||
|
||||
+5
-1
@@ -26,11 +26,15 @@ urlpatterns = patterns(
|
||||
(r'^accounts/edit/(?P<accountid>\d+)/$', 'editaccount'),
|
||||
(r'^accounts/delete/$', 'delaccount'),
|
||||
|
||||
(r'^mailboxes/list/$', 'mboxes_list'),
|
||||
|
||||
(r'^distriblists/new/$', 'newdlist'),
|
||||
(r'^distriblists/delete/$', 'deldlist'),
|
||||
|
||||
(r'^forwards/new/$', 'newforward'),
|
||||
(r'^forwards/delete/$', 'delforward'),
|
||||
|
||||
(r'^aliases/edit/(?P<alid>\d+)/$', 'editalias')
|
||||
(r'^aliases/new/$', 'newalias'),
|
||||
(r'^aliases/edit/(?P<alid>\d+)/$', 'editalias_dispatcher'),
|
||||
(r'^aliases/delete/$', 'delalias'),
|
||||
)
|
||||
|
||||
+38
-9
@@ -95,7 +95,7 @@ def newdomain(request, tplname="admin/newdomainform.html"):
|
||||
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
if not request.user.can_access(domain):
|
||||
raise PermDeniedException(_("You can't edit this domain"))
|
||||
raise PermDeniedException
|
||||
|
||||
domadmins = filter(
|
||||
lambda u: request.user.can_access(u) and not u.is_superuser,
|
||||
@@ -133,7 +133,7 @@ def deldomain(request):
|
||||
|
||||
for dom in Domain.objects.filter(id__in=selection):
|
||||
if not request.user.can_access(dom):
|
||||
raise PermDeniedException(_("You can't delete this domain"))
|
||||
raise PermDeniedException
|
||||
if mb and mb.domain == dom:
|
||||
raise AdminError(_("You can't delete your own domain"))
|
||||
dom.delete(keepdir=keepdir)
|
||||
@@ -197,6 +197,16 @@ def newdlist(request):
|
||||
return _new_alias(request, "common/generic_modal_form.html",
|
||||
DlistForm, ctx, _("Distribution list created"))
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_alias")
|
||||
@transaction.commit_on_success
|
||||
def newalias(request):
|
||||
ctx = dict(title=_("New alias"),
|
||||
action=reverse(newalias),
|
||||
formid="aliasform")
|
||||
return _new_alias(request, "common/generic_modal_form.html",
|
||||
AliasForm, ctx, _("Alias created"))
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_alias")
|
||||
@transaction.commit_on_success
|
||||
@@ -209,7 +219,7 @@ def newforward(request):
|
||||
|
||||
def _edit_alias(request, alias, tplname, formclass, ctx, successmsg):
|
||||
if not request.user.can_access(alias):
|
||||
raise PermDeniedException(_("You do not have access to this alias"))
|
||||
raise PermDeniedException
|
||||
ctx.update(title=alias.full_address, action_label=_("Update"),
|
||||
action_classes="submit")
|
||||
if request.method == "POST":
|
||||
@@ -220,6 +230,10 @@ def _edit_alias(request, alias, tplname, formclass, ctx, successmsg):
|
||||
ctx["form"] = form
|
||||
return _render(request, tplname, ctx)
|
||||
|
||||
def editalias(request, alias, ctx):
|
||||
return _edit_alias(request, alias, "common/generic_modal_form.html",
|
||||
AliasForm, ctx, _("Alias modified"))
|
||||
|
||||
def editdlist(request, alias, ctx):
|
||||
return _edit_alias(request, alias, "admin/dlistform.html",
|
||||
DlistForm, ctx, _("Distribution list modified"))
|
||||
@@ -230,25 +244,33 @@ def editforward(request, alias, ctx):
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.change_alias")
|
||||
def editalias(request, alid):
|
||||
def editalias_dispatcher(request, alid):
|
||||
alias = Alias.objects.get(pk=alid)
|
||||
ctx = dict(action=reverse(editalias, args=[alias.id]), formid="aliasform")
|
||||
ctx = dict(action=reverse(editalias_dispatcher, args=[alias.id]), formid="aliasform")
|
||||
if len(alias.get_recipients()) >= 2:
|
||||
return editdlist(request, alias, ctx)
|
||||
return editforward(request, alias, ctx)
|
||||
if alias.extmboxes != "":
|
||||
return editforward(request, alias, ctx)
|
||||
return editalias(request, alias, ctx)
|
||||
|
||||
def _del_alias(request, msg, msgs):
|
||||
selection = request.GET["selection"].split(",")
|
||||
for alid in selection:
|
||||
alias = Alias.objects.get(pk=alid)
|
||||
if not request.user.can_access(alias):
|
||||
raise PermDeniedException(_("!"))
|
||||
raise PermDeniedException
|
||||
alias.delete()
|
||||
|
||||
msg = ungettext(msg, msgs, len(selection))
|
||||
messages.info(request, msg)
|
||||
return ajax_response(request)
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.delete_alias")
|
||||
@transaction.commit_on_success
|
||||
def delalias(request):
|
||||
return _del_alias(request, "Alias deleted", "Aliases deleted")
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.delete_alias")
|
||||
@transaction.commit_on_success
|
||||
@@ -285,6 +307,7 @@ def identities(request, tplname='admin/identities.html'):
|
||||
for oa in idents_list:
|
||||
if oa.content_object:
|
||||
objects.append(oa.content_object)
|
||||
objects = sorted(objects, key=lambda o: o.identity)
|
||||
return render_listing(request, "identities", tplname,
|
||||
objects=objects, squery=squery)
|
||||
|
||||
@@ -295,6 +318,12 @@ def accounts_list(request):
|
||||
res = map(lambda a: a.username, accs.all())
|
||||
return ajax_simple_response(res)
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_mailbox")
|
||||
def mboxes_list(request):
|
||||
mboxes = request.user.get_mailboxes()
|
||||
return ajax_simple_response([mb.full_address for mb in mboxes])
|
||||
|
||||
@login_required
|
||||
@permission_required("auth.add_user")
|
||||
@transaction.commit_on_success
|
||||
@@ -359,7 +388,7 @@ def newaccount(request, tplname='admin/newaccount.html'):
|
||||
def editaccount(request, accountid, tplname="common/tabforms.html"):
|
||||
account = User.objects.get(pk=accountid)
|
||||
if not request.user.can_access(account):
|
||||
raise PermDeniedException(_("You can't access this account"))
|
||||
raise PermDeniedException
|
||||
mb = None
|
||||
if account.has_mailbox:
|
||||
mb = account.mailbox_set.all()[0]
|
||||
@@ -422,7 +451,7 @@ def remove_permission(request):
|
||||
except (User.DoesNotExist, Domain.DoesNotExist):
|
||||
raise AdminError(_("Invalid request"))
|
||||
if not request.user.can_access(account) or not request.user.can_access(domain):
|
||||
raise AdminError(_("Permission denied"))
|
||||
raise PermDeniedException
|
||||
ungrant_access_to_object(domain, account)
|
||||
return ajax_simple_response(dict(status="ok"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user