From c9103bd0e03e936e74b22293bfc129e76e068e90 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Mon, 4 Nov 2013 09:29:59 +0100 Subject: [PATCH] I forgot those modifications from 1.0.1 :p --- modoboa/core/__init__.py | 2 +- modoboa/core/app_settings.py | 13 ++++++++++--- modoboa/core/views/auth.py | 2 +- modoboa/lib/fixtures/demo.json | 2 +- modoboa/lib/webutils.py | 16 +++++----------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/modoboa/core/__init__.py b/modoboa/core/__init__.py index 824c49add..544b3a1b3 100644 --- a/modoboa/core/__init__.py +++ b/modoboa/core/__init__.py @@ -52,4 +52,4 @@ def unset_default_topredirection(extension): """ topredirection = parameters.get_admin("DEFAULT_TOP_REDIRECTION") if topredirection == extension.name: - parameters.save_admin("DEFAULT_TOP_REDIRECTION", "userprefs") + parameters.save_admin("DEFAULT_TOP_REDIRECTION", "core") diff --git a/modoboa/core/app_settings.py b/modoboa/core/app_settings.py index 9acfafae5..543672102 100644 --- a/modoboa/core/app_settings.py +++ b/modoboa/core/app_settings.py @@ -19,7 +19,7 @@ def enabled_applications(): from modoboa.core.models import Extension from modoboa.lib.dbutils import db_table_exists - result = [("core", "core")] + result = [("user", "user")] if db_table_exists("core_extension"): exts = Extension.objects.filter(enabled=True) result += [(ext.name, ext.name) for ext in exts] @@ -98,7 +98,7 @@ class GeneralParametersForm(parameters.AdminParametersForm): label=ugettext_lazy("Bind password"), initial='', help_text=ugettext_lazy("The password to use when binding to the LDAP server (with 'Bind DN')"), - widget=forms.PasswordInput, + widget=forms.PasswordInput(render_value=True), required=False ) @@ -152,7 +152,7 @@ class GeneralParametersForm(parameters.AdminParametersForm): default_top_redirection = forms.ChoiceField( label=ugettext_lazy("Default top redirection"), choices=[], - initial="core", + initial="user", help_text=ugettext_lazy("The default redirection used when no application is specified") ) @@ -176,6 +176,13 @@ class GeneralParametersForm(parameters.AdminParametersForm): super(GeneralParametersForm, self).__init__(*args, **kwargs) self.fields["default_top_redirection"].choices = enabled_applications() + def clean_secret_key(self): + if len(self.cleaned_data["secret_key"]) not in [16, 24, 32]: + raise forms.ValidationError( + _("Key must be either 16, 24, or 32 bytes long") + ) + return self.cleaned_data["secret_key"] + def clean_ldap_user_dn_template(self): tpl = self.cleaned_data["ldap_user_dn_template"] try: diff --git a/modoboa/core/views/auth.py b/modoboa/core/views/auth.py index f4d132d9e..67eb3f973 100644 --- a/modoboa/core/views/auth.py +++ b/modoboa/core/views/auth.py @@ -35,7 +35,7 @@ def dologin(request): nextlocation = request.POST.get("next", None) if nextlocation is None or nextlocation == "None": - if user.group != "SimpleUsers": + if user.group == "SimpleUsers": nextlocation = reverse("modoboa.lib.webutils.topredirection") else: nextlocation = reverse("domains") diff --git a/modoboa/lib/fixtures/demo.json b/modoboa/lib/fixtures/demo.json index d155e29d7..046dd26f0 100644 --- a/modoboa/lib/fixtures/demo.json +++ b/modoboa/lib/fixtures/demo.json @@ -20,7 +20,7 @@ "model": "lib.parameter", "fields": { "name": "general.DEFAULT_TOP_REDIRECTION", - "value": "userprefs" + "value": "user" } }, { diff --git a/modoboa/lib/webutils.py b/modoboa/lib/webutils.py index aa47ea23e..f85c90ecb 100644 --- a/modoboa/lib/webutils.py +++ b/modoboa/lib/webutils.py @@ -138,27 +138,21 @@ def size2integer(value): @login_required def topredirection(request): - """Simple view to redirect the request when no application is specified + """Simple view to redirect the request when no application is specified. The default "top redirection" can be specified in the *Admin > Settings* panel. It is the application that will be launched by default. Users that are not allowed to access this application will be redirected to the "User preferences" application. + This feature only applies to simple users. + :param request: a Request object """ from modoboa.lib import parameters from modoboa.core.extensions import exts_pool topredir = parameters.get_admin("DEFAULT_TOP_REDIRECTION", app="core") - if not topredir in ["core"]: - infos = exts_pool.get_extension_infos(topredir) - path = infos["url"] if infos["url"] else infos["name"] - else: - path = "admin" # topredir - - if topredir in ["core", "stats"] and \ - request.user.belongs_to_group('SimpleUsers'): - path = "userprefs" - + infos = exts_pool.get_extension_infos(topredir) + path = infos["url"] if infos["url"] else infos["name"] return HttpResponseRedirect(path)