When the demo application is enabled, we disable the ''password change'' action for default super administrator.

see #187
This commit is contained in:
Antoine Nguyen
2011-11-24 11:00:24 +01:00
parent d23923a248
commit 767343640a
5 changed files with 31 additions and 3 deletions
+4
View File
@@ -35,6 +35,10 @@ def announcement(**kwargs):
return [txt]
return ""
def password_change(user):
return [user.id == 1]
if 'modoboa.demo' in settings.INSTALLED_APPS:
events.register("UserMenuDisplay", menu)
events.register("GetAnnouncement", announcement)
events.register("PasswordChange", password_change)
+11
View File
@@ -256,6 +256,17 @@ callbacks and indicates the place where the announcement will appear:
Callbacks listening to this event must return a list of string.
PasswordChange
--------------
Raised just before a *password change* action. The associated ``User``
object is provided inside the ``user`` keyword argument.
Callbacks listening to this event must return a list containing either
``True`` or ``False``. If at least one ``True`` is returned, the
*password change* will be cancelled (ie. changing the password for
this user is disabled).
Parameters
==========
+2
View File
@@ -12,6 +12,8 @@ events = ["CreateDomain",
"DeleteMailbox",
"ModifyMailbox",
"PasswordChange",
"UserMenuDisplay",
"AdminMenuDisplay",
+4
View File
@@ -0,0 +1,4 @@
{% extends "layout_simple.html" %}
{% block content %}
<div class="error"><p>{{ error }}</p></div>
{% endblock %}
+10 -3
View File
@@ -3,9 +3,10 @@ from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators \
import login_required, user_passes_test
from django.conf import settings
from django.utils.translation import ugettext as _
from modoboa.lib import parameters
from modoboa.lib.webutils import _render, ajax_response
from modoboa.lib import parameters, events
from modoboa.lib.webutils import _render, _render_error, ajax_response
from forms import *
from modoboa.admin.models import Mailbox, Alias
from modoboa.admin.lib import is_domain_admin
@@ -21,6 +22,11 @@ def changepassword(request, tplname="userprefs/chpassword.html"):
target = request.user
else:
target = Mailbox.objects.get(user=request.user.id)
res = events.raiseQueryEvent("PasswordChange", user=request.user)
if True in res:
ctx = dict(error=_("Password change is disabled for this user"))
return _render_error(request, errortpl="error_simple", user_context=ctx)
error = None
if request.method == "POST":
form = ChangePasswordForm(target, request.POST)
@@ -32,7 +38,8 @@ def changepassword(request, tplname="userprefs/chpassword.html"):
request.session["password"] = encrypt(request.POST["confirmation"])
target.save()
return ajax_response(request, respmsg=_("Password changed"))
return ajax_response(request, status="ko", template=tplname, form=form, error=error)
return ajax_response(request, status="ko", template=tplname,
form=form, error=error)
form = ChangePasswordForm(target)
return _render(request, 'userprefs/chpassword.html', {