1 | from Products.CMFCore.utils import getToolByName |
---|
2 | from Products.CMFCore.CMFCorePermissions import ReplyToItem |
---|
3 | from Products.qPloneComments.config import * |
---|
4 | |
---|
5 | # Get apropriate property from (propery_sheeet) configlet |
---|
6 | def getProp(self, prop_name, marker=None): |
---|
7 | result = marker |
---|
8 | pp = getToolByName(self, 'portal_properties') |
---|
9 | config_ps = getattr(pp, PROPERTY_SHEET, None) |
---|
10 | if config_ps: |
---|
11 | result = getattr(config_ps, prop_name, marker) |
---|
12 | return result |
---|
13 | |
---|
14 | |
---|
15 | # Checking is discussion item published |
---|
16 | def isPublished(self): |
---|
17 | roles = self.permission_settings() |
---|
18 | roles = [r for r in roles if r['name']=='View'] |
---|
19 | |
---|
20 | if roles[0]['acquire']=='CHECKED': |
---|
21 | return 1 |
---|
22 | return 0 |
---|
23 | |
---|
24 | |
---|
25 | # Send notification e-mail on |
---|
26 | # Discussion_Reply |
---|
27 | def send_email(reply, context): |
---|
28 | # Check is notification active |
---|
29 | notify = getProp(context, "Turning_on/off_notification", False) |
---|
30 | if not notify: |
---|
31 | return |
---|
32 | # Get parent object |
---|
33 | parent = reply.inReplyTo() |
---|
34 | mt = parent.meta_type |
---|
35 | while mt == 'Discussion Item': |
---|
36 | try: |
---|
37 | parent = parent.inReplyTo() |
---|
38 | mt = parent.meta_type |
---|
39 | except: |
---|
40 | break |
---|
41 | |
---|
42 | # Get discussion manager's email |
---|
43 | admin_email = getProp(context, "Email_of_discussion_manager", None) |
---|
44 | |
---|
45 | # Set sending email to creator's or admin's one |
---|
46 | creator = parent.Creator() |
---|
47 | if creator: |
---|
48 | creator = context.portal_membership.getMemberById(creator) |
---|
49 | try: |
---|
50 | email = creator.getProperty('email',None) |
---|
51 | except: |
---|
52 | email = admin_email |
---|
53 | if not email: |
---|
54 | email = admin_email |
---|
55 | else: |
---|
56 | email = admin_email |
---|
57 | # Combine and send email |
---|
58 | if email: |
---|
59 | body = context.comment_template(obj=parent, |
---|
60 | mto=email, |
---|
61 | msubject="[Cornicen] New comment added", |
---|
62 | mfrom=admin_email) |
---|
63 | mh = context.MailHost |
---|
64 | mh.send(body) |
---|
65 | |
---|
66 | def publishDiscussion(self): |
---|
67 | roles = ['Anonymous'] |
---|
68 | self.manage_permission('View', roles, acquire=1) |
---|
69 | |
---|
70 | |
---|
71 | def setAnonymCommenting(context, allow=False): |
---|
72 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
73 | if allow: |
---|
74 | portal.manage_permission(ReplyToItem, ['Anonymous','Manager','Member'], 1) |
---|
75 | else: |
---|
76 | portal.manage_permission(ReplyToItem, ['Manager','Member'], 1) |
---|
77 | |
---|
78 | |
---|