def addUsers(self):
    self.loginAsPortalOwner()
    # Add all users
    self.membership = getToolByName(self.portal, 'portal_membership', None)
    for user_id in USERS.keys():
        self.membership.addMember(user_id, USERS[user_id]['passw'],
                                  USERS[user_id]['roles'], [])

    # Add users to Discussion Manager group
    portal_groups = getToolByName(self.portal, 'portal_groups')
    dm_group = portal_groups.getGroupById('DiscussionManager')
    [dm_group.addMember(u) for u in DM_USERS_IDS]
    def testViewRepliesPublishedAllUsers(self):
        # All users MUST VIEW PUBLISHED comments
        # Get any document and publish it's comment
        doc = getattr(self.portal, 'doc_%s' % 'dm_admin')
        self.login('dm_admin')
        di = self.discussion.getDiscussionFor(doc).getReplies()[0]
        di.discussion_publish_comment()

        all_users_id = USERS.keys() + ['anonym']
        for u in all_users_id:
            self.logout()
            if not u == 'anonym':
                self.login(u)
            replies = self.discussion.getDiscussionFor(doc).getReplies()
            self.failUnless(replies,
                            "Viewing PUBLISHED discussion item forbiden for %s user" % u)
    def afterSetUp(self):
        self.loginAsPortalOwner()
        self.request = self.app.REQUEST

        # VERY IMPORTANT to guarantee product skin's content visibility
        self._refreshSkinData()

        # Add all users
        self.membership = getToolByName(self.portal, 'portal_membership', None)
        for user_id in USERS.keys():
            self.membership.addMember(user_id, USERS[user_id]['passw'],
                USERS[user_id]['roles'], [])

        # Add users to Discussion Manager group
        portal_groups = getToolByName(self.portal, 'portal_groups')
        dm_group = portal_groups.getGroupById('DiscussionManager')
        [dm_group.addMember(u) for u in DM_USERS_IDS]

        # Allow discussion for Document
        portal_types = getToolByName(self.portal, 'portal_types', None)
        doc_fti = portal_types.getTypeInfo('Document')
        doc_fti._updateProperty('allow_discussion', 1)

        # Make sure Documents are visible by default
        # XXX only do this for plone 3
        self.portal.portal_workflow.setChainForPortalTypes(('Document',),
                                                           'plone_workflow')

        # Add testing documents to portal. Add one document for avery user.
        # For testing behaviors, where made some changes to document state
        # it's more usefull.
        self.discussion = getToolByName(self.portal, 'portal_discussion',
                                        None)
        self.all_users_id = DM_USERS_IDS + COMMON_USERS_IDS
        for user_id in self.all_users_id:
            doc_id = 'doc_%s' % user_id
            self.portal.invokeFactory('Document', id=doc_id)
            doc_obj = getattr(self.portal, doc_id)
            doc_obj.edit(text_format='plain',
                         text='hello world from %s' % doc_id)
            # Create talkback for document and Add comment to doc_obj
            self.discussion.getDiscussionFor(doc_obj)
            doc_obj.discussion_reply('A Reply for %s' % doc_id,
                                     'text of reply for %s' % doc_id)
 def testDeleting(self):
     # Manager with DiscussionManager role CAN delete ANY REPLY.
     # Manager without DiscussionManager role [common manager] CAN delete
     # ONLY PUBLISHED REPLY.
     # Get Managers
     managers = [u for u in USERS.keys() if 'Manager' in USERS[u]['roles']]
     dm_man = [u for u in managers if u.startswith('dm_')][0]
     common_man = [u for u in managers if not u.startswith('dm_')][0]
     # Publish document for common manager
     self.login(dm_man)
     doc_obj = getattr(self.portal, "doc_%s" % common_man)
     reply = self.discussion.getDiscussionFor(doc_obj).getReplies()[0]
     reply.discussion_publish_comment()
     # Check for really deleting
     for u in managers:
         self.login(u)
         doc_id = "doc_%s" % u
         doc_obj = getattr(self.portal, doc_id)
         getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies
         self.failUnless(getReplies(), "%s - user with Manager role not "
                                       "view discussion reply" % u)
         getReplies()[0].deleteDiscussion()
         self.failIf(getReplies(), "%s - user with Manager role not really "
                                   "delete discussion" % u)