1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-22 03:16:34 +00:00

Add USE_ORG in settings.

NOTE: Org feature is not enabled by default, in order to use org, need set USE_ORG to True in settings or local_settings.
This commit is contained in:
xiez
2012-08-01 11:08:56 +08:00
parent 9881e80ea3
commit c5d80ee8e7
5 changed files with 25 additions and 11 deletions

View File

@@ -4,7 +4,11 @@ from django.http import HttpResponseRedirect
from seaserv import get_org_by_url_prefix, get_orgs_by_user
from settings import ORG_CACHE_PREFIX
try:
from seahub.settings import USE_ORG
except ImportError:
USE_ORG = False
class OrganizationMiddleware(object):
"""
Middleware that add organization info to request when user in organization
@@ -12,13 +16,20 @@ class OrganizationMiddleware(object):
"""
def process_request(self, request):
# Get current org context
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
request.user.org = org
if USE_ORG:
request.use_org = True
# Get current org context
org = cache.get(ORG_CACHE_PREFIX + request.user.username)
request.user.org = org
# Get all orgs user created.
orgs = get_orgs_by_user(request.user.username)
request.user.orgs = orgs
# Get all orgs user created.
orgs = get_orgs_by_user(request.user.username)
request.user.orgs = orgs
else:
request.use_org = False
request.user.org = None
request.user.orgs = None
return None