| 1 |
from DateTime import DateTime |
|---|
| 2 |
from Globals import InitializeClass |
|---|
| 3 |
from AccessControl import Unauthorized |
|---|
| 4 |
from AccessControl import getSecurityManager |
|---|
| 5 |
from Products.CMFCore.utils import getToolByName |
|---|
| 6 |
from Products.CMFDefault.DiscussionItem import DiscussionItem |
|---|
| 7 |
from Products.CMFDefault.DiscussionItem import DiscussionItemContainer |
|---|
| 8 |
|
|---|
| 9 |
from Products.qPloneComments.utils import getProp |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
def createReply(self, title, text, Creator=None, email=''): |
|---|
| 14 |
"""Create a reply in the proper place. |
|---|
| 15 |
""" |
|---|
| 16 |
container = self._container |
|---|
| 17 |
|
|---|
| 18 |
id = int(DateTime().timeTime()) |
|---|
| 19 |
while self._container.get(str(id), None) is not None: |
|---|
| 20 |
id += 1 |
|---|
| 21 |
id = str(id) |
|---|
| 22 |
|
|---|
| 23 |
item = DiscussionItem(id, title=title, description=title) |
|---|
| 24 |
|
|---|
| 25 |
if Creator: |
|---|
| 26 |
if getattr(item, 'addCreator', None) is not None: |
|---|
| 27 |
item.addCreator(Creator) |
|---|
| 28 |
else: |
|---|
| 29 |
item.creator = Creator |
|---|
| 30 |
|
|---|
| 31 |
self._container[id] = item |
|---|
| 32 |
item = item.__of__(self) |
|---|
| 33 |
|
|---|
| 34 |
item.setFormat('structured-text') |
|---|
| 35 |
item._edit(text) |
|---|
| 36 |
|
|---|
| 37 |
pm = getToolByName(self, 'portal_membership') |
|---|
| 38 |
if pm.isAnonymousUser(): |
|---|
| 39 |
item.manage_addProperty(id='email', value=email, type='string') |
|---|
| 40 |
|
|---|
| 41 |
item.review_state = 'private' |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
if getProp(self, 'enable_moderation', marker=False): |
|---|
| 45 |
roles = [role['name'] for role in self.acl_users.rolesOfPermission('Moderate Discussion') |
|---|
| 46 |
if role['selected']== 'SELECTED'] |
|---|
| 47 |
roles.append('DiscussionManager') |
|---|
| 48 |
item.manage_permission('Delete objects', roles, acquire=1) |
|---|
| 49 |
item.manage_permission('View', roles, acquire=0) |
|---|
| 50 |
else: |
|---|
| 51 |
item.review_state = 'published' |
|---|
| 52 |
|
|---|
| 53 |
item.setReplyTo(self._getDiscussable()) |
|---|
| 54 |
item.indexObject() |
|---|
| 55 |
|
|---|
| 56 |
return id |
|---|
| 57 |
|
|---|
| 58 |
def getReplies( self ): |
|---|
| 59 |
"""Return a sequence of the DiscussionResponse objects which are |
|---|
| 60 |
associated with this Discussable. |
|---|
| 61 |
""" |
|---|
| 62 |
objects = [] |
|---|
| 63 |
validate = getSecurityManager().validate |
|---|
| 64 |
|
|---|
| 65 |
result_ids = self._getReplyResults() |
|---|
| 66 |
for id in result_ids: |
|---|
| 67 |
comment = self._container.get(id).__of__(self) |
|---|
| 68 |
try: |
|---|
| 69 |
if validate(self, self, id, comment): |
|---|
| 70 |
objects.append(comment) |
|---|
| 71 |
except Unauthorized: |
|---|
| 72 |
pass |
|---|
| 73 |
return objects |
|---|
| 74 |
|
|---|
| 75 |
perms = DiscussionItemContainer.__ac_permissions__ |
|---|
| 76 |
new_perms = [] |
|---|
| 77 |
for item in perms: |
|---|
| 78 |
perm_name = item[0] |
|---|
| 79 |
funcs = item[1] |
|---|
| 80 |
if 'deleteReply' in funcs: |
|---|
| 81 |
new_perms.append((perm_name, [f for f in funcs if f != 'deleteReply'])) |
|---|
| 82 |
new_perms.append(('Moderate Discussion', ('deleteReply',))) |
|---|
| 83 |
else: |
|---|
| 84 |
new_perms.append(item) |
|---|
| 85 |
|
|---|
| 86 |
DiscussionItemContainer.__ac_permissions__ = new_perms |
|---|
| 87 |
InitializeClass(DiscussionItemContainer) |
|---|
| 88 |
|
|---|
| 89 |
DiscussionItemContainer.createReply = createReply |
|---|
| 90 |
DiscussionItemContainer.getReplies = getReplies |
|---|