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