1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-10-22 11:43:33 +00:00
Files
seahub/organizations/middleware.py

38 lines
1.0 KiB
Python
Raw Normal View History

2012-07-26 17:08:31 +08:00
from django.core.cache import cache
from django.http import HttpResponseRedirect
2012-07-27 14:12:25 +08:00
from seaserv import get_org_by_url_prefix, get_orgs_by_user
2012-07-26 17:08:31 +08:00
try:
2012-08-01 22:34:35 +08:00
from seahub.settings import CLOUD_MODE
except ImportError:
2012-08-01 22:34:35 +08:00
CLOUD_MODE = False
from seahub.utils import get_cur_ctx
2012-07-26 17:08:31 +08:00
class OrganizationMiddleware(object):
"""
Middleware that add organization info to request when user in organization
context.
"""
2012-07-30 10:25:46 +08:00
2012-07-26 17:08:31 +08:00
def process_request(self, request):
2012-08-01 22:34:35 +08:00
if CLOUD_MODE:
request.cloud_mode = True
# Get current org context
ctx_dict = get_cur_ctx(request)
request.user.org = ctx_dict.get('org_dict', None)
2012-07-27 14:12:25 +08:00
# Get all orgs user created.
orgs = get_orgs_by_user(request.user.username)
request.user.orgs = orgs
else:
2012-08-01 22:34:35 +08:00
request.cloud_mode = False
request.user.org = None
request.user.orgs = None
2012-07-26 17:08:31 +08:00
return None
def process_response(self, request, response):
return response