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 | # Possible values for state: ["approve", "published"] |
---|
17 | def send_email(reply, context, state="approve"): |
---|
18 | # Check is notification active |
---|
19 | send_result = 0 |
---|
20 | notify = False |
---|
21 | if state=="approve": |
---|
22 | notify = getProp(context, "Enable_Approve_Notification", False) |
---|
23 | elif state=="published": |
---|
24 | notify = getProp(context, "Enable_Published_Notification", False) |
---|
25 | if not notify: |
---|
26 | return send_result |
---|
27 | |
---|
28 | # Get parent object |
---|
29 | parent = reply.inReplyTo() |
---|
30 | mt = parent.meta_type |
---|
31 | while mt == 'Discussion Item': |
---|
32 | try: |
---|
33 | parent = parent.inReplyTo() |
---|
34 | mt = parent.meta_type |
---|
35 | except: |
---|
36 | break |
---|
37 | |
---|
38 | # Get portal admin e-mail |
---|
39 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
40 | from_address = portal.getProperty('email_from_address') |
---|
41 | |
---|
42 | # Get email address based on state |
---|
43 | to_address = None |
---|
44 | if state=="published": |
---|
45 | creator = parent.Creator() |
---|
46 | if creator: |
---|
47 | mtool = getToolByName(context, 'portal_membership') |
---|
48 | creator = mtool.getMemberById(creator) |
---|
49 | to_address = creator.getProperty('email', None) |
---|
50 | elif state=="approve": |
---|
51 | to_address = getProp(context, "Email_Discussion_Manager", None) |
---|
52 | |
---|
53 | # Combine and send email |
---|
54 | if to_address: |
---|
55 | if state=="published": |
---|
56 | template = getattr(context, 'published_comment_template') |
---|
57 | elif state=="approve": |
---|
58 | template = getattr(context, 'approve_comment_template') |
---|
59 | |
---|
60 | organization_name = getProp(context, "Email_Subject_Prefix", "") |
---|
61 | message = template(obj=parent, mto=to_address, |
---|
62 | mfrom=from_address, organization_name=organization_name) |
---|
63 | try: |
---|
64 | host = context.MailHost |
---|
65 | host.send( message ) |
---|
66 | send_result = 1 |
---|
67 | except: |
---|
68 | send_result = 0 |
---|
69 | return send_result |
---|
70 | |
---|
71 | |
---|
72 | def publishDiscussion(self): |
---|
73 | roles = ['Anonymous'] |
---|
74 | self.review_state = "published" |
---|
75 | self.manage_permission('View', roles, acquire=1) |
---|
76 | self._p_changed = 1 |
---|
77 | |
---|
78 | |
---|
79 | def setAnonymCommenting(context, allow=False): |
---|
80 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
81 | if allow: |
---|
82 | portal.manage_permission(ReplyToItem, ['Anonymous','Manager','Member'], 1) |
---|
83 | else: |
---|
84 | portal.manage_permission(ReplyToItem, ['Manager','Member'], 1) |
---|
85 | |
---|
86 | |
---|