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 | # Send notification e-mail on |
---|
16 | # Discussion_Reply |
---|
17 | def send_email(reply, context): |
---|
18 | # Check is notification active |
---|
19 | notify = getProp(context, "Enable_Notification", False) |
---|
20 | if not notify: |
---|
21 | return |
---|
22 | # Get parent object |
---|
23 | parent = reply.inReplyTo() |
---|
24 | mt = parent.meta_type |
---|
25 | while mt == 'Discussion Item': |
---|
26 | try: |
---|
27 | parent = parent.inReplyTo() |
---|
28 | mt = parent.meta_type |
---|
29 | except: |
---|
30 | break |
---|
31 | |
---|
32 | # Get discussion manager's email |
---|
33 | admin_email = getProp(context, "Email_Discussion_Manager", None) |
---|
34 | |
---|
35 | # Set sending email to creator's or admin's one |
---|
36 | creator = parent.Creator() |
---|
37 | if creator: |
---|
38 | creator = context.portal_membership.getMemberById(creator) |
---|
39 | try: |
---|
40 | email = creator.getProperty('email',None) |
---|
41 | except: |
---|
42 | email = admin_email |
---|
43 | if not email: |
---|
44 | email = admin_email |
---|
45 | else: |
---|
46 | email = admin_email |
---|
47 | # Combine and send email |
---|
48 | if email: |
---|
49 | organization_name = getProp(context, "Email_Subject_Prefix", "") |
---|
50 | subject = "New comment added" |
---|
51 | bottom_sign = "Support Team." |
---|
52 | if organization_name: |
---|
53 | subject = "[%s] %s" % (organization_name, subject) |
---|
54 | bottom_sign = "%s %s" % (organization_name, bottom_sign) |
---|
55 | |
---|
56 | body = context.comment_template(obj=parent, |
---|
57 | mto=email, |
---|
58 | msubject=subject, |
---|
59 | mfrom=admin_email, |
---|
60 | mbsign=bottom_sign) |
---|
61 | mh = context.MailHost |
---|
62 | mh.send(body) |
---|
63 | |
---|
64 | |
---|
65 | def publishDiscussion(self): |
---|
66 | roles = ['Anonymous'] |
---|
67 | self.review_state = "published" |
---|
68 | self.manage_permission('View', roles, acquire=1) |
---|
69 | self._p_changed = 1 |
---|
70 | |
---|
71 | |
---|
72 | def setAnonymCommenting(context, allow=False): |
---|
73 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
74 | if allow: |
---|
75 | portal.manage_permission(ReplyToItem, ['Anonymous','Manager','Member'], 1) |
---|
76 | else: |
---|
77 | portal.manage_permission(ReplyToItem, ['Manager','Member'], 1) |
---|
78 | |
---|
79 | |
---|