"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:
Antoine Nguyen
2011-09-20 14:57:04 +02:00
parent af4aab9fa6
commit 858fe43cdd
13 changed files with 88 additions and 22 deletions
+3
View File
@@ -18,6 +18,9 @@ events = ["CreateDomain",
"PermsGetTables",
"PermsGetClass",
"ExtEnabled",
"ExtDisabled",
"UserLogin",
"UserLogout"]
+31 -2
View File
@@ -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)