Beispiel #1
0
  def process_view(self, request, view_func, view_args, view_kwargs):
    if not hasattr(request, 'kbsite'):
      return None
    elif _path_allowed(request.path, request.kbsite):
      return None
    elif getattr(request, 'kb_api_key_authenticated', False):
      # This is an auth-required kb api view; no need to check privacy since API
      # keys are given staff-level access.
      return None

    privacy = request.kbsite.settings.privacy
    if privacy == 'public':
      return None

    # If non-public, apply the API key check.
    if view_func.__module__.startswith('pykeg.web.api'):
      check_api_key(request)

    if privacy == 'staff' and not request.user.is_staff:
      return SimpleTemplateResponse('kegweb/staff_only.html',
          context=RequestContext(request), status=503)
    elif privacy == 'members':
      if not request.user.is_authenticated or not request.user.is_active:
        return SimpleTemplateResponse('kegweb/members_only.html',
            context=RequestContext(request), status=503)
      return None

    return HttpResponse('Server misconfigured, unknown privacy setting:%s' % privacy, status=503)
Beispiel #2
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        if not hasattr(request, 'kbsite'):
            return None
        elif _path_allowed(request.path, request.kbsite):
            return None
        elif getattr(request, 'kb_api_authenticated', False):
            # This is an auth-required kb api view; no need to check privacy since API
            # keys are given staff-level access.
            return None

        privacy = request.kbsite.settings.privacy
        if privacy == 'public':
            return None

        # If non-public, apply the API key check.
        if view_func.__module__.startswith('pykeg.web.api'):
            check_api_key(request)

        if privacy == 'staff' and not request.user.is_staff:
            return SimpleTemplateResponse('kegweb/staff_only.html',
                                          context=RequestContext(request),
                                          status=503)
        elif privacy == 'members':
            if not request.user.is_authenticated or not request.user.is_active:
                return SimpleTemplateResponse('kegweb/members_only.html',
                                              context=RequestContext(request),
                                              status=503)
            return None

        return HttpResponse(
            'Server misconfigured, unknown privacy setting:%s' % privacy,
            status=503)
Beispiel #3
0
 def process_view(self, request, view_func, view_args, view_kwargs):
   if not view_func.__module__.startswith('pykeg.web.api'):
     return None
   if getattr(view_func, 'kb_api_key_required', False):
     check_api_key(request)
     request.kb_api_authenticated = True