Пример #1
0
 def _add_post_hook(self, queue_name, email, mapping):
     if queue_name == 'pending_pmod_post':
         if self.mem_list.is_allowed_sender(email):
             send_pending_posts(self.context, [mapping])
         else:
             adapter = getAdapter(
                 self.context, IPostPendingList, 'pending_mod_post')
             adapter.add(email, user_name=mapping.get('user_name',''), time=mapping['time'], post=mapping)
         return True
     return False
Пример #2
0
    def _send_pending_posts(self, email):
        post_list = self._get_post_pending_list()
        # XXX currently expecting one post,
        # this is not the case for Post Moderated Lists
        # send the post for the user to the list
        posts = post_list.get_posts(email)
        # uniquify posts
        post_dict = {}
        for p in posts:
            post_dict[p['body']] = p['header']
        posts = [dict(header=v, body=k) for k, v in post_dict.iteritems()]

        send_pending_posts(self.context, posts)
 def _add_post_hook(self, queue_name, email, mapping):
     if queue_name == 'pending_pmod_post':
         if self.mem_list.is_allowed_sender(email):
             send_pending_posts(self.context, [mapping])
         else:
             adapter = getAdapter(self.context, IPostPendingList,
                                  'pending_mod_post')
             adapter.add(email,
                         user_name=mapping.get('user_name', ''),
                         time=mapping['time'],
                         post=mapping)
         return True
     return False
    def _send_pending_posts(self, email):
        post_list = self._get_post_pending_list()
        # XXX currently expecting one post,
        # this is not the case for Post Moderated Lists
        # send the post for the user to the list
        posts = post_list.get_posts(email)
        # uniquify posts
        post_dict = {}
        for p in posts:
            post_dict[p['body']] = p['header']
        posts = [dict(header=v, body=k)
                 for k,v in post_dict.iteritems()]

        send_pending_posts(self.context, posts)
Пример #5
0
    def enforce(self, request):
        user_email = request.get('email')
        user_name = request.get('name')
        post = request.get('post')
        action = request.get('action', '').lower()
        postid = request.get('postid')
        if user_email is None:
            return POST_ERROR

        if action:
            post = self.mod_post_pending_list.pop_post(user_email, postid)
            if post is None:
                return MODERATION_FAILED
            if action == 'approve':
                send_pending_posts(self.context, [post])
            elif action == 'discard':
                pass
            elif action == 'reject':
                self.mail_sender.user_post_rejected(
                    user_email, user_name, request.get('reject_reason'))
            return MODERATION_SUCCESSFUL

        if post is None:
            return POST_ERROR

        if self.is_internal_message(request):
            return POST_ALLOWED

        self.mod_post_pending_list.add(user_email,
                                       user_name=user_name,
                                       post=post)

        # notify people
        if self.mem_list.is_subscribed(user_email):
            self.mail_sender.user_post_mod_notification(user_email, user_name)
        else:
            self.mail_sender.user_post_mod_subscribe_notification(
                user_email, user_name)

        self.mail_sender.manager_mod_post_request(user_email, user_name, post)
        return POST_DEFERRED
def became_allowed_sender(event):
    """
    This function should ensure that all other pending allowed sender
    lists that the other policy adapters depend on are in sync.

    set up the phony mailing list and policies
    >>> from Products.listen.content.tests import DummyAnnotableList
    >>> from Products.listen.content.tests import DummyMembershipTool
    >>> from Products.listen.extras.tests import TestMailingList
    >>> from Products.listen.content.tests import DummyMember
    >>> from Products.listen.config import POST_DEFERRED, MEMBERSHIP_DEFERRED
    >>> ml = TestMailingList()
    >>> from zope.interface import alsoProvides
    >>> from Products.listen.interfaces import IPublicList
    >>> alsoProvides(ml, IPublicList)
    >>> mails_to_list = []
    >>> def listMail(post):
    ...     mails_to_list.append(post)
    >>> ml.listMail = listMail
    >>> from Products.listen.interfaces import IMailingList
    >>> dtool = DummyMembershipTool('foo')
    >>> dtool.result = None
    >>> ml.portal_membership = dtool
    >>> from Products.listen.content import WriteMembershipList
    >>> mlist = WriteMembershipList(ml)
    >>> from zope.component import getAdapter
    >>> from zope.component import provideAdapter
    >>> from Products.listen.interfaces import IEmailPostPolicy
    >>> from Products.listen.interfaces import IUserEmailMembershipPolicy
    >>> from Products.listen.content import PublicEmailPostPolicy
    >>> from Products.listen.content import UserMembershipPolicy
    >>> postpolicy = getAdapter(ml, IEmailPostPolicy)
    >>> mempolicy = getAdapter(ml, IUserEmailMembershipPolicy)

    send a subscribe email to get on the pending list
    >>> request = dict(email='*****@*****.**',
    ...                subject='subscribe')
    >>> mempolicy.enforce(request) == MEMBERSHIP_DEFERRED
    True

    now submit a post to get on that pending list
    >>> request = dict(email='*****@*****.**',
    ...                post=dict(header={}, body='there is only zul!'))
    >>> postpolicy.enforce(request) == POST_DEFERRED
    True

    now add the email as an allowed sender
    >>> mlist.add_allowed_sender('*****@*****.**')

    make sure he's not on the allowed sender pending list
    >>> from zope.annotation.interfaces import IAnnotations
    >>> annot = IAnnotations(ml)
    >>> listen_annot = annot['listen']
    >>> a_s_list = listen_annot['a_s_pending_sub_email']
    >>> '*****@*****.**' in a_s_list
    False

    verify that the post is no longer pending and has been sent out
    >>> post_list = listen_annot['pending_mod_post']
    >>> '*****@*****.**' in post_list
    False
    >>> 'there is only zul!' in mails_to_list[0]['Mail']
    True

    try with a mem-moderated list policy
    >>> from zope.interface import directlyProvides
    >>> from Products.listen.interfaces import IMembershipModeratedList
    >>> directlyProvides(ml, IMembershipModeratedList)
    >>> postpolicy = getAdapter(ml, IEmailPostPolicy)
    >>> request = dict(email='*****@*****.**',
    ...                post=dict(header={}, body='there is only zui!'))
    >>> postpolicy.enforce(request) == POST_DEFERRED
    True
    >>> mlist.add_allowed_sender('*****@*****.**')
    >>> '*****@*****.**' in post_list
    False
    >>> 'there is only zui!' in mails_to_list[1]['Mail']
    True

    make someone who is pending subscription moderation an allowed sender
    and make sure they get automatically subscribed
    >>> from Products.listen.interfaces import IMembershipPendingList
    >>> sub_mod_pending_list = getAdapter(ml, IMembershipPendingList, 'pending_sub_mod_email')
    >>> sub_mod_pending_list.add('*****@*****.**')
    >>> mlist.add_allowed_sender('*****@*****.**')
    >>> mlist.is_subscribed('*****@*****.**')
    True

    now try subscribing a member who is pending subscription moderation
    >>> sub_mod_pending_list.add('*****@*****.**')
    >>> mlist.subscribe('*****@*****.**')
    >>> mlist.is_subscribed('*****@*****.**')
    True

    """
    
    email = event.email
    context = event.context

    # clean up pending subscription
    pend_list = getAdapter(context, IPostPendingList, 'a_s_pending_sub_email')
    pend_list.remove(email)

    # if member is waiting for moderation to become a subscriber
    # then subscribe member
    sub_pending_list = getAdapter(context, IMembershipPendingList, 'pending_sub_mod_email')
    if sub_pending_list.is_pending(email):
        mlist = IWriteMembershipList(context)
        mail_sender = ISendMail(context)
        sub_pending_list.remove(email)
        mlist.subscribe(email)
        mail_sender.user_welcome(email, email)

    # clean up pending posts
    post_mod_list = getAdapter(context, IPostPendingList, 'pending_mod_post')
    # XXX currently expecting one post,
    # this is not the case for Post Moderated Lists
    # send the post for the user to the list
    posts = post_mod_list.get_posts(email)
    # uniquify posts
    post_dict = {}
    for p in posts:
        post_dict[p['body']] = p['header']
    posts = [dict(header=v, body=k) for k,v in post_dict.iteritems()]
    send_pending_posts(context, posts)
    post_mod_list.remove(email)