1 | ## Script (Python) "report_abuse" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind state=state |
---|
7 | ##bind subpath=traverse_subpath |
---|
8 | ##parameters=message,text_format='plain',username=None,password=None |
---|
9 | ##title=Reply to content |
---|
10 | |
---|
11 | from Products.PythonScripts.standard import url_quote_plus |
---|
12 | from Products.CMFCore.utils import getToolByName |
---|
13 | from Products.CMFPlone import MessageFactory |
---|
14 | from Products.CMFPlone import PloneMessageFactory |
---|
15 | from quintagroup.plonecomments.utils import manage_mails |
---|
16 | |
---|
17 | _ = MessageFactory('quintagroup.plonecomments') |
---|
18 | |
---|
19 | req = context.REQUEST |
---|
20 | mtool = getToolByName(context, 'portal_membership') |
---|
21 | dtool = getToolByName(context, 'portal_discussion') |
---|
22 | pp = getToolByName(context,'portal_properties') |
---|
23 | |
---|
24 | isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_report_abuse', False) |
---|
25 | |
---|
26 | if username or password: |
---|
27 | # The user username/password inputs on on the comment form were used, |
---|
28 | # which might happen when anonymous commenting is enabled. If they typed |
---|
29 | # something in to either of the inputs, we send them to 'logged_in'. |
---|
30 | # 'logged_in' will redirect them back to this script if authentication |
---|
31 | # succeeds with a query string which will post the message appropriately |
---|
32 | # and show them the result. if 'logged_in' fails, the user will be |
---|
33 | # presented with the stock login failure page. This all depends |
---|
34 | # heavily on cookiecrumbler, but I believe that is a Plone requirement. |
---|
35 | came_from = '%s?subject=%s&body_text=%s' % (req['URL'], subject, body_text) |
---|
36 | came_from = url_quote_plus(came_from) |
---|
37 | portal_url = context.portal_url() |
---|
38 | |
---|
39 | return req.RESPONSE.redirect( |
---|
40 | '%s/logged_in?__ac_name=%s' |
---|
41 | '&__ac_password=%s' |
---|
42 | '&came_from=%s' % (portal_url, |
---|
43 | url_quote_plus(username), |
---|
44 | url_quote_plus(password), |
---|
45 | came_from, |
---|
46 | ) |
---|
47 | ) |
---|
48 | |
---|
49 | comment_creator = req.get('Creator', None) |
---|
50 | if isForAnonymous and comment_creator: |
---|
51 | # Get entered anonymous name |
---|
52 | comment_creator = comment_creator |
---|
53 | else: |
---|
54 | member = mtool.getAuthenticatedMember() |
---|
55 | comment_creator = member.getUserName() |
---|
56 | |
---|
57 | if mtool.isAnonymousUser(): |
---|
58 | email = req.get('email', '') |
---|
59 | else: |
---|
60 | email = mtool.getAuthenticatedMember().getProperty('email') |
---|
61 | |
---|
62 | tb = dtool.getDiscussionFor(context) |
---|
63 | |
---|
64 | # Send notification e-mail |
---|
65 | manage_mails(context, context, 'report_abuse') |
---|
66 | |
---|
67 | # return to the discussable object. |
---|
68 | redirect_target = context.plone_utils.getDiscussionThread(tb)[0] |
---|
69 | view = redirect_target.getTypeInfo().getActionInfo('object/view', |
---|
70 | redirect_target)['url'] |
---|
71 | |
---|
72 | portal_status_message=_(u'Your abuse report has been sent.') |
---|
73 | context.plone_utils.addPortalMessage(portal_status_message) |
---|
74 | target = '%s' % view |
---|
75 | return req.RESPONSE.redirect(target) |
---|
76 | |
---|