source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/skins/quintagroup_plonecomments/report_abuse.cpy @ 1201

Last change on this file since 1201 was 1201, checked in by liebster, 15 years ago

Added "report abuse" feature contributed by jcbrand.

File size: 2.8 KB
Line 
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
11from Products.PythonScripts.standard import url_quote_plus
12from Products.CMFCore.utils import getToolByName
13from Products.CMFPlone import MessageFactory
14from Products.CMFPlone import PloneMessageFactory
15from quintagroup.plonecomments.utils import manage_mails
16
17_ = MessageFactory('quintagroup.plonecomments')
18
19req = context.REQUEST
20mtool = getToolByName(context, 'portal_membership')
21dtool = getToolByName(context, 'portal_discussion')
22pp = getToolByName(context,'portal_properties')
23
24isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_report_abuse', False)
25
26if 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
49comment_creator = req.get('Creator', None)
50if isForAnonymous and comment_creator:
51    # Get entered anonymous name
52    comment_creator = comment_creator
53else:
54    member = mtool.getAuthenticatedMember()
55    comment_creator = member.getUserName()
56
57if mtool.isAnonymousUser():
58    email = req.get('email', '')
59else:
60    email = mtool.getAuthenticatedMember().getProperty('email')
61
62tb = dtool.getDiscussionFor(context)
63
64# Send notification e-mail
65manage_mails(context, context, 'report_abuse')
66
67# return to the discussable object.
68redirect_target = context.plone_utils.getDiscussionThread(tb)[0]
69view = redirect_target.getTypeInfo().getActionInfo('object/view',
70                                                   redirect_target)['url']
71
72portal_status_message=_(u'Your abuse report has been sent.')
73context.plone_utils.addPortalMessage(portal_status_message)
74target = '%s' % view
75return req.RESPONSE.redirect(target)
76
Note: See TracBrowser for help on using the repository browser.