| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
from Products.PloneTestCase import PloneTestCase |
|---|
| 6 |
from Products.CMFCore.utils import getToolByName |
|---|
| 7 |
import re |
|---|
| 8 |
|
|---|
| 9 |
from common import * |
|---|
| 10 |
|
|---|
| 11 |
PloneTestCase.installProduct(PRODUCT) |
|---|
| 12 |
PloneTestCase.setupPloneSite() |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
class TestModeration(PloneTestCase.FunctionalTestCase): |
|---|
| 16 |
|
|---|
| 17 |
def afterSetUp(self): |
|---|
| 18 |
self.loginAsPortalOwner() |
|---|
| 19 |
self.portal.portal_quickinstaller.installProduct(PRODUCT) |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
addMembers(self.portal, USERS) |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
add2Group(self.portal, 'DiscussionManager', DM_USERS_IDS) |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
portal_types = getToolByName(self.portal, 'portal_types') |
|---|
| 29 |
doc_fti = portal_types.getTypeInfo('Document') |
|---|
| 30 |
doc_fti._updateProperty('allow_discussion', 1) |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
self.portal.portal_workflow.setChainForPortalTypes(('Document',), 'plone_workflow') |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
self.discussion = getToolByName(self.portal, 'portal_discussion', None) |
|---|
| 38 |
all_users_id = DM_USERS_IDS + COMMON_USERS_IDS |
|---|
| 39 |
for user_id in all_users_id: |
|---|
| 40 |
doc_id = 'doc_%s' % user_id |
|---|
| 41 |
self.portal.invokeFactory('Document', id=doc_id) |
|---|
| 42 |
doc_obj = getattr(self.portal, doc_id) |
|---|
| 43 |
doc_obj.edit(text_format='plain', text='hello world from %s' % doc_id) |
|---|
| 44 |
|
|---|
| 45 |
self.discussion.getDiscussionFor(doc_obj) |
|---|
| 46 |
doc_obj.discussion_reply('A Reply for %s' % doc_id,'text of reply for %s' % doc_id) |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
def testViewRepliesNotPublishedDMUsers(self): |
|---|
| 51 |
|
|---|
| 52 |
doc = getattr(self.portal, 'doc_%s' % DM_USERS_IDS[0]) |
|---|
| 53 |
for u in DM_USERS_IDS: |
|---|
| 54 |
self.login(u) |
|---|
| 55 |
replies = self.discussion.getDiscussionFor(doc).getReplies() |
|---|
| 56 |
self.assert_(replies, "Viewing discussion item forbiden for %s - member of DiscussionManager group" % u) |
|---|
| 57 |
|
|---|
| 58 |
def testViewRepliesNotPublishedNotDMUsers(self): |
|---|
| 59 |
|
|---|
| 60 |
doc = getattr(self.portal, 'doc_%s' % DM_USERS_IDS[0]) |
|---|
| 61 |
roles = [r['name'] for r in self.portal.rolesOfPermission('Moderate Discussion') if r['selected'] == 'SELECTED'] |
|---|
| 62 |
authorized_users = [user for user in COMMON_USERS_IDS if user !='anonym'] |
|---|
| 63 |
users_without_md_perm = [u for u in authorized_users if filter(lambda x: x not in roles, USERS[u]['roles'])] |
|---|
| 64 |
for u in users_without_md_perm: |
|---|
| 65 |
self.logout() |
|---|
| 66 |
if not u=='anonym': |
|---|
| 67 |
self.login(u) |
|---|
| 68 |
replies = self.discussion.getDiscussionFor(doc).getReplies() |
|---|
| 69 |
self.assert_(not replies, "Viewing of NOT published discussion item allow %s - user without 'Moderate Discussion' permission" % u) |
|---|
| 70 |
|
|---|
| 71 |
def testViewRepliesPublishedAllUsers(self): |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
doc = getattr(self.portal, 'doc_%s' % 'dm_admin') |
|---|
| 75 |
self.login('dm_admin') |
|---|
| 76 |
di = self.discussion.getDiscussionFor(doc).getReplies()[0] |
|---|
| 77 |
di.discussion_publish_comment() |
|---|
| 78 |
|
|---|
| 79 |
all_users_id = USERS.keys() + ['anonym'] |
|---|
| 80 |
for u in all_users_id: |
|---|
| 81 |
self.logout() |
|---|
| 82 |
if not u=='anonym': |
|---|
| 83 |
self.login(u) |
|---|
| 84 |
replies = self.discussion.getDiscussionFor(doc).getReplies() |
|---|
| 85 |
self.assert_(replies, "Viewing PUBLISHED discussion item forbiden for %s user" % u) |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
def testViewPublishButtonNonDMUsers(self): |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
pattern = re.compile('.*<input.+?value="Publish"', re.S|re.M) |
|---|
| 93 |
roles = [r['name'] for r in self.portal.rolesOfPermission('Moderate Discussion') if r['selected'] == 'SELECTED'] |
|---|
| 94 |
authorized_users = [user for user in COMMON_USERS_IDS if user !='anonym'] |
|---|
| 95 |
users_without_md_perm = [u for u in authorized_users if filter(lambda x: x not in roles, USERS[u]['roles'])] |
|---|
| 96 |
for u in users_without_md_perm: |
|---|
| 97 |
self.logout() |
|---|
| 98 |
auth = "%s:" % u |
|---|
| 99 |
if not u=='anonym': |
|---|
| 100 |
self.login(u) |
|---|
| 101 |
auth = '%s:%s' % (u,USERS[u]['passw']) |
|---|
| 102 |
doc_id = "doc_%s" % u |
|---|
| 103 |
html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| 104 |
m = pattern.match(html) |
|---|
| 105 |
self.assert_(not m, "Publish button present for %s - user without Moderate Discussion permission" % u) |
|---|
| 106 |
|
|---|
| 107 |
def testViewPublishButtonDMUsers(self): |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
pattern = re.compile('.*<input.+?value="Publish"',re.S|re.M) |
|---|
| 111 |
|
|---|
| 112 |
import pdb; pdb.set_trace() |
|---|
| 113 |
for u in DM_USERS_IDS: |
|---|
| 114 |
self.login(u) |
|---|
| 115 |
auth = '%s:%s' % (u,USERS[u]['passw']) |
|---|
| 116 |
doc_id = "doc_%s" % u |
|---|
| 117 |
html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| 118 |
m = pattern.match(html) |
|---|
| 119 |
self.assert_(m, "Publish button NOT PRESENT for %s - member of DiscussionManager group" % u) |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
def testPublishing(self): |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
pattern = re.compile('.*<input.+?value="Publish"',re.S|re.M) |
|---|
| 126 |
for u in DM_USERS_IDS: |
|---|
| 127 |
doc_id = "doc_%s" % u |
|---|
| 128 |
doc_obj = getattr(self.portal, doc_id) |
|---|
| 129 |
getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies |
|---|
| 130 |
|
|---|
| 131 |
self.logout() |
|---|
| 132 |
self.assert_(not getReplies(), "View not published reply ALLOW for Anonymous") |
|---|
| 133 |
|
|---|
| 134 |
self.login(u) |
|---|
| 135 |
self.assert_(getReplies(), "%s - member of DiscussionManager group NOT VIEW not published reply" % u) |
|---|
| 136 |
getReplies()[0].discussion_publish_comment() |
|---|
| 137 |
|
|---|
| 138 |
auth = "%s:" % u |
|---|
| 139 |
if not u=='anonym': |
|---|
| 140 |
auth = '%s:%s' % (u,USERS[u]['passw']) |
|---|
| 141 |
html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| 142 |
m = pattern.match(html) |
|---|
| 143 |
self.assert_(not m, "Publish button present for %s - DiscussionManager role user after publishing" % u) |
|---|
| 144 |
|
|---|
| 145 |
self.logout() |
|---|
| 146 |
self.assert_(getReplies(), "%s - member of DiscussionManager group NOT PUBLISH reply" % u) |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
def testViewDeleteButtonNonDMUsers(self): |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
self.logout() |
|---|
| 156 |
self.login('dm_admin') |
|---|
| 157 |
for u in COMMON_USERS_IDS: |
|---|
| 158 |
doc_id = "doc_%s" % u |
|---|
| 159 |
doc_obj = getattr(self.portal, doc_id) |
|---|
| 160 |
reply = self.discussion.getDiscussionFor(doc_obj).getReplies()[0] |
|---|
| 161 |
reply.discussion_publish_comment() |
|---|
| 162 |
|
|---|
| 163 |
pattern = re.compile('.*<input\\s*class="destructive"\\s*type="submit"\\s*value="Remove"\\s*/>', re.S|re.M) |
|---|
| 164 |
for u in COMMON_USERS_IDS: |
|---|
| 165 |
self.logout() |
|---|
| 166 |
auth = "%s:" % u |
|---|
| 167 |
if not u=='anonym': |
|---|
| 168 |
self.login(u) |
|---|
| 169 |
auth = '%s:%s' % (u,USERS[u]['passw']) |
|---|
| 170 |
doc_id = "doc_%s" % u |
|---|
| 171 |
html = str(self.publish(self.portal.id+'/%s' % doc_id, auth)) |
|---|
| 172 |
m = pattern.match(html) |
|---|
| 173 |
if not u=='anonym' and 'Manager' in USERS[u]['roles']: |
|---|
| 174 |
self.assert_(m, "%s - user with Manager role NOT VIEW Delete reply button for published reply on document view form" % u) |
|---|
| 175 |
else: |
|---|
| 176 |
self.assert_(not m, "%s - user without Manager role CAN VIEW Delete reply button for published reply on document view form" % u) |
|---|
| 177 |
|
|---|
| 178 |
def testDeleting(self): |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
managers = [u for u in USERS.keys() if 'Manager' in USERS[u]['roles']] |
|---|
| 183 |
dm_man = [u for u in managers if u.startswith('dm_')][0] |
|---|
| 184 |
common_man = [u for u in managers if not u.startswith('dm_')][0] |
|---|
| 185 |
|
|---|
| 186 |
self.login(dm_man) |
|---|
| 187 |
doc_obj = getattr(self.portal, "doc_%s" % common_man) |
|---|
| 188 |
reply = self.discussion.getDiscussionFor(doc_obj).getReplies()[0] |
|---|
| 189 |
reply.discussion_publish_comment() |
|---|
| 190 |
|
|---|
| 191 |
for u in managers: |
|---|
| 192 |
self.login(u) |
|---|
| 193 |
auth = '%s:%s' % (u,USERS[u]['passw']) |
|---|
| 194 |
doc_id = "doc_%s" % u |
|---|
| 195 |
doc_obj = getattr(self.portal, doc_id) |
|---|
| 196 |
getReplies = self.discussion.getDiscussionFor(doc_obj).getReplies |
|---|
| 197 |
self.assert_(getReplies(), "%s - user with Manager role not view discussion reply" % u) |
|---|
| 198 |
getReplies()[0].deleteDiscussion() |
|---|
| 199 |
self.assert_(not getReplies(), "%s - user with Manager role not really delete discussion" % u) |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
def test_suite(): |
|---|
| 203 |
from unittest import TestSuite, makeSuite |
|---|
| 204 |
suite = TestSuite() |
|---|
| 205 |
suite.addTest(makeSuite(TestModeration)) |
|---|
| 206 |
return suite |
|---|