[1] | 1 | from Products.CMFCore.CMFCorePermissions import View, ReviewPortalContent,DeleteObjects |
---|
| 2 | from Products.CMFDefault.DiscussionItem import DiscussionItemContainer, DiscussionItem |
---|
| 3 | from AccessControl import getSecurityManager, Unauthorized |
---|
| 4 | from DateTime import DateTime |
---|
| 5 | from Products.CMFCore.utils import getToolByName |
---|
| 6 | |
---|
| 7 | #from config import * |
---|
| 8 | from utils import * |
---|
| 9 | |
---|
| 10 | # Patching createReply method of |
---|
| 11 | # Products.CMFDefault.DiscussionItem.DiscussionItemContainer |
---|
| 12 | def createReply( self, title, text, Creator=None ): |
---|
| 13 | """ |
---|
| 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 = id + 1 |
---|
| 21 | id = str( id ) |
---|
| 22 | |
---|
| 23 | item = DiscussionItem( id, title=title, description=title ) |
---|
| 24 | item._edit( text_format='structured-text', text=text ) |
---|
| 25 | |
---|
| 26 | if Creator: |
---|
| 27 | item.creator = Creator |
---|
| 28 | |
---|
| 29 | pm = getToolByName(self, 'portal_membership') |
---|
| 30 | value = 0 |
---|
| 31 | if pm.isAnonymousUser(): |
---|
| 32 | value = 1 |
---|
| 33 | if item.hasProperty('isAnon'): |
---|
| 34 | item.manage_changeProperties({'id':'isAnon','value':value}) |
---|
| 35 | else: |
---|
| 36 | item.manage_addProperty(id='isAnon', value=value, type='boolean') |
---|
| 37 | item.review_state="private" |
---|
| 38 | |
---|
| 39 | item.__of__( self ).indexObject() |
---|
| 40 | |
---|
| 41 | item.setReplyTo( self._getDiscussable() ) |
---|
| 42 | |
---|
| 43 | self._container[ id ] = item |
---|
| 44 | |
---|
| 45 | # Control of performing moderation |
---|
| 46 | ifModerate = getProp(self, "Enable_Moderation", marker=False) |
---|
| 47 | if ifModerate: |
---|
| 48 | roles = ['DiscussionManager'] |
---|
| 49 | item.manage_permission(DeleteObjects, roles, acquire=1) |
---|
| 50 | #item.manage_permission(ReviewPortalContent, roles, acquire=0) |
---|
| 51 | item.manage_permission(View, roles, acquire=0) |
---|
| 52 | else: |
---|
| 53 | item.review_state = "published" |
---|
| 54 | item._p_changed = 1 |
---|
| 55 | |
---|
| 56 | return id |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | def getReplies( self ): |
---|
| 60 | """ |
---|
| 61 | Return a sequence of the DiscussionResponse objects which are |
---|
| 62 | associated with this Discussable |
---|
| 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 | #DiscussionItemContainer.__dict__["createReply"] = createReply |
---|
| 79 | #DiscussionItemContainer.__dict__["getReplies"] = getReplies |
---|
| 80 | DiscussionItemContainer.createReply = createReply |
---|
| 81 | DiscussionItemContainer.getReplies = getReplies |
---|