Пример #1
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        if 'domain' in view_kwargs:
            request.domain = view_kwargs['domain']
        if 'org' in view_kwargs:
            request.org = view_kwargs['org']
        if request.user and hasattr(request.user, 'get_profile'):
            sessionid = request.COOKIES.get('sessionid', None)
            if sessionid:
                # roundabout way to keep doc_id based caching consistent.
                # get user doc_id from session_id
                MISSING = object()
                INTERRUPTED = object()
                try:
                    cached_user_doc_id = rcache.get(
                        SESSION_USER_KEY_PREFIX % sessionid, MISSING)
                except ConnectionInterrumped:
                    cached_user_doc_id = INTERRUPTED

                # disable session based couch user caching - to be enabled later.
                if cached_user_doc_id not in (MISSING, INTERRUPTED):
                    # cache hit
                    couch_user = CouchUser.wrap_correctly(
                        cache_core.cached_open_doc(CouchUser.get_db(),
                                                   cached_user_doc_id))
                else:
                    # cache miss, write to cache
                    couch_user = CouchUser.from_django_user(request.user)
                    if couch_user:
                        cache_core.do_cache_doc(couch_user.to_json())
                        if cached_user_doc_id is not INTERRUPTED:
                            rcache.set(SESSION_USER_KEY_PREFIX % sessionid,
                                       couch_user.get_id)
                request.couch_user = couch_user

            if 'domain' in view_kwargs:
                domain = request.domain
                if not request.couch_user:
                    couch_domain = Domain.view(
                        "domain/domains",
                        key=domain,
                        reduce=False,
                        include_docs=True,
                    ).one()
                    if couch_domain and couch_domain.is_public:
                        request.couch_user = PublicUser(domain)
                    else:
                        request.couch_user = InvalidUser()
                if request.couch_user:
                    request.couch_user.current_domain = domain
        return None
Пример #2
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user and request.user.is_authenticated():
         request.couch_user = CouchUser.get_by_username(
             request.user.username, strict=False)
         if 'domain' in view_kwargs:
             domain = request.domain
             if not request.couch_user:
                 request.couch_user = InvalidUser()
             if request.couch_user:
                 request.couch_user.current_domain = domain
     return None
Пример #3
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user and hasattr(request.user, 'get_profile'):
         request.couch_user = CouchUser.get_by_username(
             request.user.username, strict=False)
         if 'domain' in view_kwargs:
             domain = request.domain
             if not request.couch_user:
                 couch_domain = Domain.get_by_name(domain)
                 if couch_domain and couch_domain.is_public:
                     request.couch_user = PublicUser(domain)
                 else:
                     request.couch_user = InvalidUser()
             if request.couch_user:
                 request.couch_user.current_domain = domain
     return None
Пример #4
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     request.analytics_enabled = True
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user and request.user.is_authenticated:
         user_id = username_to_user_id(request.user.username)
         couch_user = CouchUser.get_by_user_id(user_id)
         if not couch_user:
             couch_user = InvalidUser()
         request.couch_user = couch_user
         if not request.couch_user.analytics_enabled:
             request.analytics_enabled = False
         if 'domain' in view_kwargs:
             domain = request.domain
             request.couch_user.current_domain = domain
     elif is_public_reports(view_kwargs, request):
         request.couch_user = AnonymousCouchUser()
     return None
Пример #5
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     request.analytics_enabled = True
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user.is_anonymous() and 'domain' in view_kwargs:
         if ANONYMOUS_WEB_APPS_USAGE.enabled(view_kwargs['domain']):
             request.couch_user = CouchUser.get_anonymous_mobile_worker(
                 request.domain)
     if request.user and request.user.is_authenticated():
         request.couch_user = CouchUser.get_by_username(
             request.user.username, strict=False)
         if not request.couch_user.analytics_enabled:
             request.analytics_enabled = False
         if 'domain' in view_kwargs:
             domain = request.domain
             if not request.couch_user:
                 request.couch_user = InvalidUser()
             if request.couch_user:
                 request.couch_user.current_domain = domain
     return None
Пример #6
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user and hasattr(request.user, 'get_profile'):
         request.couch_user = CouchUser.from_django_user(request.user)
         if 'domain' in view_kwargs:
             domain = request.domain
             if not request.couch_user:
                 couch_domain = Domain.view("domain/domains",
                     key=domain,
                     reduce=False,
                     include_docs=True,
                     stale=settings.COUCH_STALE_QUERY,
                 ).one()
                 if couch_domain and couch_domain.is_public:
                     request.couch_user = PublicUser(domain)
                 else:
                     request.couch_user = InvalidUser()
             if request.couch_user:
                 request.couch_user.current_domain = domain
     return None
Пример #7
0
 def process_view(self, request, view_func, view_args, view_kwargs):
     request.analytics_enabled = True
     if 'domain' in view_kwargs:
         request.domain = view_kwargs['domain']
     if 'org' in view_kwargs:
         request.org = view_kwargs['org']
     if request.user.is_anonymous and 'domain' in view_kwargs:
         if ANONYMOUS_WEB_APPS_USAGE.enabled(view_kwargs['domain']):
             request.couch_user = CouchUser.get_anonymous_mobile_worker(request.domain)
     if request.user and request.user.is_authenticated:
         user_id = username_to_user_id(request.user.username)
         request.couch_user = CouchUser.get_by_user_id(user_id)
         if not request.couch_user.analytics_enabled:
             request.analytics_enabled = False
         if 'domain' in view_kwargs:
             domain = request.domain
             if not request.couch_user:
                 request.couch_user = InvalidUser()
             if request.couch_user:
                 request.couch_user.current_domain = domain
     elif is_public_reports(view_kwargs, request):
         request.couch_user = AnonymousCouchUser()
     return None