mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
"Top redirection" feature.
A new admin parameter is available to specify the default application that will be launched when no one is present in the url. (ie. when the top level "/" is called). fixed #165
This commit is contained in:
+20
-1
@@ -1,7 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib import parameters, events
|
||||
from django.utils.translation import ugettext as _
|
||||
from models import Extension
|
||||
|
||||
parameters.register_admin("STORAGE_PATH", type="string", deflt="/var/vmail",
|
||||
help=_("Path to the root directory where messages are stored"))
|
||||
@@ -19,3 +20,21 @@ parameters.register_admin("PASSWORD_SCHEME", type="list", deflt="crypt",
|
||||
help=_("Scheme used to crypt mailbox passwords"))
|
||||
parameters.register_admin("ITEMS_PER_PAGE", type="int", deflt=30,
|
||||
help=_("Number of displayed items per page"))
|
||||
|
||||
parameters.register_admin("DEFAULT_TOP_REDIRECTION", type="list", deflt="admin",
|
||||
app="general",
|
||||
values=sorted([("admin", "admin"), ("userprefs", "userprefs")] \
|
||||
+ map(lambda ext: (ext.name, ext.name),
|
||||
Extension.objects.filter(enabled=True))),
|
||||
help=_("The default redirection used when no application is specified"))
|
||||
|
||||
def unset_default_topredirection(**kwargs):
|
||||
"""
|
||||
Simple callback to change the default redirection if the
|
||||
corresponding extension is being disabled.
|
||||
"""
|
||||
topredirection = parameters.get_admin("DEFAULT_TOP_REDIRECTION", app="general")
|
||||
if topredirection == kwargs["ext"].name:
|
||||
parameters.save_admin("DEFAULT_TOP_REDIRECTION", "userprefs", app="general")
|
||||
|
||||
events.register("ExtDisabled", unset_default_topredirection)
|
||||
|
||||
+14
-12
@@ -44,20 +44,22 @@ def good_domain(f):
|
||||
def dec(request, **kwargs):
|
||||
if request.user.is_superuser:
|
||||
return f(request, **kwargs)
|
||||
mb = Mailbox.objects.get(user=request.user.id)
|
||||
access = True
|
||||
if request.GET.has_key("domid"):
|
||||
dom_id = int(request.GET["domid"])
|
||||
if dom_id != mb.domain.id:
|
||||
access = False
|
||||
else:
|
||||
q = request.GET.copy()
|
||||
q["domid"] = mb.domain.id
|
||||
request.GET = q
|
||||
if access:
|
||||
return f(request, **kwargs)
|
||||
if is_domain_admin(request.user):
|
||||
mb = Mailbox.objects.get(user=request.user.id)
|
||||
access = True
|
||||
if request.GET.has_key("domid"):
|
||||
dom_id = int(request.GET["domid"])
|
||||
if dom_id != mb.domain.id:
|
||||
access = False
|
||||
else:
|
||||
q = request.GET.copy()
|
||||
q["domid"] = mb.domain.id
|
||||
request.GET = q
|
||||
if access:
|
||||
return f(request, **kwargs)
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.http import urlquote
|
||||
path = urlquote(request.get_full_path())
|
||||
login_url = settings.LOGIN_URL
|
||||
return HttpResponseRedirect("%s?next=%s" % (login_url, path))
|
||||
|
||||
+5
-1
@@ -3,7 +3,7 @@ from django.db import models, IntegrityError
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext as _, ugettext_noop
|
||||
from django.conf import settings
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.lib import parameters, events
|
||||
from modoboa.lib.sysutils import exec_cmd, exec_as_vuser
|
||||
from modoboa.lib.emailutils import split_mailbox
|
||||
from modoboa.auth.lib import crypt_password
|
||||
@@ -418,6 +418,8 @@ class Extension(models.Model):
|
||||
exec_cmd("ln -s %s/static %s/static/%s" % \
|
||||
(extdir, settings.MODOBOA_DIR, self.name))
|
||||
|
||||
events.raiseEvent("ExtEnabled", ext=self)
|
||||
|
||||
def off(self):
|
||||
self.unload()
|
||||
|
||||
@@ -431,6 +433,8 @@ class Extension(models.Model):
|
||||
if os.path.exists(staticpath):
|
||||
exec_cmd("rm -r %s/static/%s" % (settings.MODOBOA_DIR, self.name))
|
||||
|
||||
events.raiseEvent("ExtDisabled", ext=self)
|
||||
|
||||
#
|
||||
# Optional callback to execute if django-auth-ldap is enabled.
|
||||
#
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils import simplejson
|
||||
from django.utils.translation import ugettext as _, ungettext
|
||||
from django.utils.http import urlquote
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators \
|
||||
import login_required, permission_required, user_passes_test
|
||||
|
||||
@@ -6,6 +6,10 @@ from django.conf import settings
|
||||
def isinstalled(ext):
|
||||
return "modoboa.extensions.%s" % ext in settings.INSTALLED_APPS
|
||||
|
||||
def get_extension_infos(name):
|
||||
ext = __import__(name, globals(), locals(), ["main"])
|
||||
return ext.main.infos()
|
||||
|
||||
def loadextensions(prefix):
|
||||
# To avoid a circular import...
|
||||
from modoboa.admin.models import Extension
|
||||
|
||||
@@ -12,7 +12,8 @@ def infos():
|
||||
return {
|
||||
"name" : "Amavis quarantine",
|
||||
"version" : "1.0",
|
||||
"description" : ugettext("Simple amavis quarantine management tool")
|
||||
"description" : ugettext("Simple amavis quarantine management tool"),
|
||||
"url" : "quarantine"
|
||||
}
|
||||
|
||||
def init():
|
||||
|
||||
@@ -18,7 +18,8 @@ def infos():
|
||||
return {
|
||||
"name" : "Postfix autoreply",
|
||||
"version" : "1.0",
|
||||
"description" : ugettext("Auto-reply (vacation) functionality using Postfix")
|
||||
"description" : ugettext("Auto-reply (vacation) functionality using Postfix"),
|
||||
"url" : "postfix_autoreply"
|
||||
}
|
||||
|
||||
def init():
|
||||
|
||||
@@ -39,7 +39,8 @@ def infos():
|
||||
return {
|
||||
"name" : "Sieve filters",
|
||||
"version" : "1.0",
|
||||
"description" : ugettext("Plugin to easily create server-side filters")
|
||||
"description" : ugettext("Plugin to easily create server-side filters"),
|
||||
"url" : "sfilters"
|
||||
}
|
||||
|
||||
def urls(prefix):
|
||||
|
||||
@@ -17,7 +17,8 @@ def infos():
|
||||
return {
|
||||
"name" : "Statistics",
|
||||
"version" : "1.0",
|
||||
"description" : ugettext("Graphical statistics about emails traffic using RRDtool")
|
||||
"description" : ugettext("Graphical statistics about emails traffic using RRDtool"),
|
||||
"url" : "stats"
|
||||
}
|
||||
|
||||
def init():
|
||||
|
||||
@@ -73,7 +73,8 @@ def infos():
|
||||
return {
|
||||
"name" : "Webmail",
|
||||
"version" : "1.0",
|
||||
"description" : ugettext("Simple IMAP webmail")
|
||||
"description" : ugettext("Simple IMAP webmail"),
|
||||
"url" : "webmail"
|
||||
}
|
||||
|
||||
def urls(prefix):
|
||||
|
||||
@@ -18,6 +18,9 @@ events = ["CreateDomain",
|
||||
"PermsGetTables",
|
||||
"PermsGetClass",
|
||||
|
||||
"ExtEnabled",
|
||||
"ExtDisabled",
|
||||
|
||||
"UserLogin",
|
||||
"UserLogout"]
|
||||
|
||||
|
||||
+31
-2
@@ -3,9 +3,10 @@
|
||||
"""
|
||||
This module contains extra functions/shortcuts used to render HTML.
|
||||
"""
|
||||
import sys
|
||||
import os, sys
|
||||
import re
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template.loader import render_to_string
|
||||
from django import template
|
||||
@@ -141,3 +142,31 @@ def size2integer(value):
|
||||
if m.group(2)[0] in ["G", "g"]:
|
||||
return int(m.group(1)) * 2 ** 30
|
||||
return 0
|
||||
|
||||
@login_required
|
||||
def topredirection(request):
|
||||
"""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.
|
||||
|
||||
:param request: a Request object
|
||||
"""
|
||||
from modoboa.lib import parameters
|
||||
from modoboa.extensions import get_extension_infos
|
||||
from modoboa.admin.lib import is_domain_admin
|
||||
|
||||
topredir = parameters.get_admin("DEFAULT_TOP_REDIRECTION", app="general")
|
||||
if not topredir in ["admin", "userprefs"]:
|
||||
infos = get_extension_infos(topredir)
|
||||
path = infos["url"]
|
||||
else:
|
||||
path = topredir
|
||||
|
||||
if topredir in ["admin", "stats"] and \
|
||||
(not request.user.is_superuser and not is_domain_admin(request.user)):
|
||||
path = "userprefs"
|
||||
|
||||
return HttpResponseRedirect(path)
|
||||
|
||||
@@ -11,6 +11,7 @@ if prefix != "":
|
||||
prefix += "/"
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^%s$' % prefix, 'modoboa.lib.webutils.topredirection'),
|
||||
(r'^%sadmin/' % prefix, include('modoboa.admin.urls')),
|
||||
(r'^%suserprefs/' % prefix, include('modoboa.userprefs.urls')),
|
||||
(r'^accounts/login/$', 'modoboa.auth.views.dologin'),
|
||||
|
||||
Reference in New Issue
Block a user