def effective_principals(self, request):
        """ See IAuthenticationPolicy.
        """
        context = request.context
        effective_principals = [Everyone]
        userid = self.unauthenticated_userid(request)

        if userid is None:
            return effective_principals

        if userid in (Authenticated, Everyone): #pragma NO COVER
            return None

        effective_principals.append(userid)
        effective_principals.append('system.Identified')

        adapter = request.registry.queryMultiAdapter(
            (context, request), IUserLocator)
        if adapter is None:
            adapter = DefaultUserLocator(context, request)
        try:
            user = adapter.get_user_by_userid(userid)
        except ValueError:
            user = None
 
        if user is not None:
            effective_principals.append(Authenticated)
            effective_principals.extend(
                adapter.get_groupids(userid))

        return effective_principals
Exemple #2
0
 def response(self):
     # import pdb; pdb.set_trace()
     adapter = DefaultUserLocator(self.context, self.request)
     user = adapter.get_user_by_userid(int(self.context.author))
     return {
         'title': self.context.title,
         'description': self.context.description,
         'text': self.context.text,
         'pubdate': self.context.pubdate.strftime('%Y-%m-%d %H:%M:%S'),
         'keywords': self.context.keywords,
         'author': user.name,
         'short_description': self.context.short_description,
     }
    def authenticated_userid(self, request):
        """ See IAuthenticationPolicy.
        """
        context = request.context
        userid = self.unauthenticated_userid(request)
        if userid is None:
            return None

        if userid in (Authenticated, Everyone): #pragma NO COVER
            return None

        adapter = request.registry.queryMultiAdapter(
            (context, request), IUserLocator)
        if adapter is None:
            adapter = DefaultUserLocator(context, request)
        try:
            user = adapter.get_user_by_userid(userid)
        except ValueError: #pragma NO COVER
            user = None

        if user is not None:
            return userid