1 | from Products.CMFCore.utils import getToolByName |
---|
2 | |
---|
3 | # Get apropriate property from (propery_sheeet) configlet |
---|
4 | def getProp(self, prop_name, marker=None): |
---|
5 | result = marker |
---|
6 | pp = getToolByName(self, 'portal_properties') |
---|
7 | config_ps = getattr(pp, 'qPloneComments', None) |
---|
8 | if config_ps: |
---|
9 | result = getattr(config_ps, prop_name, marker) |
---|
10 | return result |
---|
11 | |
---|
12 | |
---|
13 | # Send notification e-mail on Discussion_Reply |
---|
14 | # Possible values for state: ["approve", "published"] |
---|
15 | def send_email(reply, context, state="approve"): |
---|
16 | # Check is notification active |
---|
17 | notify = False |
---|
18 | if state=="approve": |
---|
19 | notify = getProp(context, "enable_approve_notification", False) |
---|
20 | elif state=="published": |
---|
21 | notify = getProp(context, "enable_published_notification", False) |
---|
22 | if not notify: |
---|
23 | return 0 |
---|
24 | |
---|
25 | # Get parent object |
---|
26 | parent = reply.inReplyTo() |
---|
27 | mt = parent.meta_type |
---|
28 | while mt == 'Discussion Item': |
---|
29 | try: |
---|
30 | parent = parent.inReplyTo() |
---|
31 | mt = parent.meta_type |
---|
32 | except: |
---|
33 | break |
---|
34 | |
---|
35 | # Get portal admin e-mail |
---|
36 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
37 | from_address = portal.getProperty('email_from_address') |
---|
38 | |
---|
39 | # Get email address based on state |
---|
40 | to_address = None |
---|
41 | if state=="published": |
---|
42 | creator_id = parent.Creator() |
---|
43 | if creator_id: |
---|
44 | mtool = getToolByName(context, 'portal_membership') |
---|
45 | creator = mtool.getMemberById(creator_id) |
---|
46 | if creator: |
---|
47 | to_address = creator.getProperty('email', None) |
---|
48 | elif state=="approve": |
---|
49 | to_address = getProp(context, "email_discussion_manager", None) |
---|
50 | |
---|
51 | # Combine and send email |
---|
52 | if to_address: |
---|
53 | if state=="published": |
---|
54 | template = getattr(context, 'published_comment_template') |
---|
55 | elif state=="approve": |
---|
56 | template = getattr(context, 'approve_comment_template') |
---|
57 | |
---|
58 | organization_name = getProp(context, "email_subject_prefix", "") |
---|
59 | message = template(obj=parent, mto=to_address, |
---|
60 | mfrom=from_address, organization_name=organization_name) |
---|
61 | try: |
---|
62 | host = context.MailHost |
---|
63 | host.send( message ) |
---|
64 | except: |
---|
65 | return 0 |
---|
66 | return 1 |
---|
67 | |
---|
68 | |
---|
69 | def publishDiscussion(self): |
---|
70 | roles = ['Anonymous'] |
---|
71 | self.review_state = "published" |
---|
72 | self.manage_permission('View', roles, acquire=1) |
---|
73 | self._p_changed = 1 |
---|
74 | self.reindexObject() |
---|
75 | |
---|
76 | |
---|
77 | def setAnonymCommenting(context, allow=False): |
---|
78 | portal = getToolByName(context, 'portal_url').getPortalObject() |
---|
79 | if allow: |
---|
80 | portal.manage_permission('Reply to item', ['Anonymous','Manager','Member'], 1) |
---|
81 | else: |
---|
82 | portal.manage_permission('Reply to item', ['Manager','Member'], 1) |
---|
83 | |
---|
84 | |
---|