source: products/qPloneComments/trunk/browser/comments.py @ 2284

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

Merged revisions 1946-1951,1957-1962,1964-1965,1967-1970,1972-1986,1990-1993,2199-2200 via svnmerge from
http://svn.quintagroup.com/products/qPloneComments/branches/jcbrand-abuseFeature

........

r1946 | jcbrand | 2009-04-01 16:52:52 +0300 (Срд, 01 Апр 2009) | 3 lines


Add enable_report_abuse property to propertiestool.xml
Add checkbox for this property on the prefs_comments_setup_form.cpt

........

r1947 | jcbrand | 2009-04-01 17:29:20 +0300 (Срд, 01 Апр 2009) | 2 lines


Add report_abuse.pt containing the report_abuse form.

........

r1948 | jcbrand | 2009-04-01 17:30:35 +0300 (Срд, 01 Апр 2009) | 2 lines


Add utility method necesary for the report abuse form.

........

r1949 | jcbrand | 2009-04-01 17:31:05 +0300 (Срд, 01 Апр 2009) | 2 lines


Add the report abuse button and form (hidden).

........

r1950 | jcbrand | 2009-04-01 17:43:31 +0300 (Срд, 01 Апр 2009) | 1 line


Add qcomments.kss and register

........

r1951 | jcbrand | 2009-04-01 17:43:54 +0300 (Срд, 01 Апр 2009) | 1 line


Add qcomments.js and register

........

r1957 | jcbrand | 2009-04-02 12:52:54 +0300 (Чтв, 02 Апр 2009) | 2 lines


Add new mail action for the enable_report_abuse state.

........

r1958 | jcbrand | 2009-04-02 12:54:05 +0300 (Чтв, 02 Апр 2009) | 2 lines


Add a form and new hidden input containing 'comment_id'

........

r1959 | jcbrand | 2009-04-02 12:59:12 +0300 (Чтв, 02 Апр 2009) | 2 lines


Add CommentsKSS kss class and submit_abuse_report method.

........

r1960 | jcbrand | 2009-04-02 13:00:14 +0300 (Чтв, 02 Апр 2009) | 2 lines


Bugfix, preventDefault for all the forms.

........

r1961 | jcbrand | 2009-04-02 13:00:30 +0300 (Чтв, 02 Апр 2009) | 2 lines


remove comment_id passing.

........

r1962 | jcbrand | 2009-04-02 13:00:53 +0300 (Чтв, 02 Апр 2009) | 2 lines


get values from request if able.

........

r1964 | jcbrand | 2009-04-02 13:01:18 +0300 (Чтв, 02 Апр 2009) | 2 lines


Add comments.CommentsKSS

........

r1965 | jcbrand | 2009-04-02 13:01:39 +0300 (Чтв, 02 Апр 2009) | 2 lines


Include browser.

........

r1967 | jcbrand | 2009-04-02 14:26:07 +0300 (Чтв, 02 Апр 2009) | 1 line


Add email template for the report_abuse function

........

r1968 | jcbrand | 2009-04-02 14:26:41 +0300 (Чтв, 02 Апр 2009) | 2 lines


Use the new email template.

........

r1969 | jcbrand | 2009-04-02 14:29:41 +0300 (Чтв, 02 Апр 2009) | 3 lines


Register remove_abuse_report_form as a kss command.
Add new code to it that adds an optional html. (Used for status message)

........

r1970 | jcbrand | 2009-04-02 15:18:24 +0300 (Чтв, 02 Апр 2009) | 3 lines


Add form action.
Add place holder for abuse count info.

........

r1972 | jcbrand | 2009-04-02 16:08:42 +0300 (Чтв, 02 Апр 2009) | 2 lines


Add new portal_properties settings.

........

r1973 | jcbrand | 2009-04-02 19:39:27 +0300 (Чтв, 02 Апр 2009) | 1 line


Add controller python script for abuse reports

........

r1974 | jcbrand | 2009-04-02 19:39:55 +0300 (Чтв, 02 Апр 2009) | 1 line


Add validation script for abuse reporting

........

r1975 | jcbrand | 2009-04-02 19:40:43 +0300 (Чтв, 02 Апр 2009) | 1 line


Add template and metadata for rendering the report abuse form. Moved the macro form report_abuse.pt to this template

........

r1976 | jcbrand | 2009-04-02 19:41:22 +0300 (Чтв, 02 Апр 2009) | 1 line


remove old template

........

r1977 | jcbrand | 2009-04-02 19:41:52 +0300 (Чтв, 02 Апр 2009) | 3 lines


Fix form action.
Fix bug with form nesting.

........

r1978 | jcbrand | 2009-04-02 19:42:46 +0300 (Чтв, 02 Апр 2009) | 1 line


Add new utility methods. Use newly registered kss command

........

r1979 | jcbrand | 2009-04-02 19:43:20 +0300 (Чтв, 02 Апр 2009) | 2 lines


Bugfixes after the introduction of new portal_properties props.

........

r1980 | jcbrand | 2009-04-02 19:44:14 +0300 (Чтв, 02 Апр 2009) | 2 lines


Bugfixes

........

r1981 | jcbrand | 2009-04-02 19:44:31 +0300 (Чтв, 02 Апр 2009) | 2 lines


Register the remove_abuse_report_form kss action.

........

r1982 | jcbrand | 2009-04-03 11:41:32 +0300 (Птн, 03 Апр 2009) | 2 lines


Fix bug whereby emails were sent twice

........

r1983 | jcbrand | 2009-04-03 11:42:08 +0300 (Птн, 03 Апр 2009) | 1 line


Bugfixes related to anonymous comment adding

........

r1984 | jcbrand | 2009-04-03 11:59:44 +0300 (Птн, 03 Апр 2009) | 2 lines


Add macro for the captcha widget.

........

r1985 | jcbrand | 2009-04-03 12:00:22 +0300 (Птн, 03 Апр 2009) | 2 lines


Render a new captcha after hiding form.

........

r1986 | jcbrand | 2009-04-03 12:00:32 +0300 (Птн, 03 Апр 2009) | 2 lines


Change fade out time.

........

r1990 | jcbrand | 2009-04-03 13:37:13 +0300 (Птн, 03 Апр 2009) | 1 line


Add test suite

........

r1991 | jcbrand | 2009-04-03 13:37:38 +0300 (Птн, 03 Апр 2009) | 1 line


remove redundant line

........

r1992 | jcbrand | 2009-04-03 13:48:21 +0300 (Птн, 03 Апр 2009) | 1 line


bugfix

........

r1993 | jcbrand | 2009-04-03 13:56:51 +0300 (Птн, 03 Апр 2009) | 1 line


remove explicit microseconds

........

r2199 | jcbrand | 2009-07-25 02:07:58 +0300 (Сбт, 25 Июл 2009) | 1 line


Fixed a bug with syntax recognition of an older version of jquery

........

r2200 | jcbrand | 2009-07-25 02:08:58 +0300 (Сбт, 25 Июл 2009) | 1 line


Log email errors, so that the report abuse form still closes

........

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1import urllib, md5 #hashlib
2
3from Acquisition import aq_inner
4from AccessControl import getSecurityManager
5
6from Products.CMFPlone.utils import IndexIterator
7from Products.CMFPlone.utils import getToolByName
8from Products.CMFFormController.ControllerState import ControllerState
9from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
10from Products.qPloneComments.utils import manage_mails
11
12from plone.app.layout.viewlets import comments
13from plone.app.kss.plonekssview import PloneKSSView
14
15class CommentsViewlet(comments.CommentsViewlet):
16    """A custom version of the comments viewlet
17    """
18    render = ViewPageTemplateFile('comments.pt')
19
20    def is_moderation_enabled(self):
21        """ Returns a boolean indicating whether the user has enabled moderation
22            in the qPloneComments configlet
23        """
24        portal_properties = getToolByName(self.context, 'portal_properties')
25        try:
26            return portal_properties.qPloneComments.getProperty('enable_moderation', None)
27        except AttributeError:
28            return False
29
30    def can_moderate(self):
31        """ Returns a boolean indicating whether the user has the 'Moderate Discussion'
32            permission
33        """
34        return getSecurityManager().checkPermission('Moderate Discussion', aq_inner(self.context))
35
36    def getGravatar(self, reply):
37        purl = getToolByName(self.context, 'portal_url')
38        default = purl() + '/defaultUser.gif' 
39        email = ''
40
41        creator = reply.Creator()
42        if creator and not creator=='Anonymous User':
43            mtool = getToolByName(self.context, "portal_membership")
44            member = mtool.getMemberById(creator)
45            email = member and member.getProperty('email','') or ''
46        else:
47            email = reply.getProperty('email',d='')
48        if not email:
49            return default
50
51        size = 40
52        gravatar_url = "http://www.gravatar.com/avatar.php?"
53        # construct the url
54        gravatar_url += urllib.urlencode({'gravatar_id':md5.md5(email).hexdigest(), 
55            'default':default, 'size':str(size)})
56
57        return gravatar_url
58
59    def authenticated_report_abuse_enabled(self):
60        """ """
61        portal_properties = getToolByName(self.context, 'portal_properties')
62        prop_sheet = portal_properties['qPloneComments']
63        value =  prop_sheet.getProperty('enable_authenticated_report_abuse', False)
64        return value
65
66    def anonymous_report_abuse_enabled(self):
67        """ """
68        portal_properties = getToolByName(self.context, 'portal_properties')
69        prop_sheet = portal_properties['qPloneComments']
70        value =  prop_sheet.getProperty('enable_anonymous_report_abuse', False)
71        return value
72
73    def ajax_report_abuse_enabled(self):
74        """ """
75        portal_properties = getToolByName(self.context, 'portal_properties')
76        prop_sheet = portal_properties['qPloneComments']
77        value =  prop_sheet.getProperty('enable_ajax_report_abuse', False)
78        return value
79
80    def email_from_address(self):
81        """ """
82        portal_url = getToolByName(self.context, 'portal_url')
83        portal = portal_url.getPortalObject()
84        return portal.email_from_address
85
86    def member(self):
87        """ """
88        pm = getToolByName(self.context, 'portal_membership')
89        return pm.getAuthenticatedMember()
90
91    def tabindex(self):
92        """ Needed for BBB, tabindex has been deprecated.
93        """
94        return IndexIterator()
95
96    def portal_url(self):
97        """ """
98        return getToolByName(self.context, 'portal_url')
99
100
101
102class CommentsKSS(PloneKSSView):
103    """ Operations on the report abuse form using KSS.
104    """   
105
106    def submit_abuse_report(self):
107        """ Send an email with the abuse report message and hide abuse report form.
108        """
109        errors = {}
110        context = aq_inner(self.context)
111        request = context.REQUEST
112        portal = getToolByName(self.context, 'portal_url').getPortalObject()
113        if hasattr(context, 'captcha_validator'):
114            dummy_controller_state = ControllerState(
115                                            id='comments.pt',
116                                            context=context,
117                                            button='submit',
118                                            status='success',
119                                            errors={},
120                                            next_action=None,)
121            # get the form controller
122            controller = portal.portal_form_controller
123            # send the validate script to the form controller with the dummy state object
124            controller_state = controller.validate(dummy_controller_state, request, ['captcha_validator',])
125            errors.update(controller_state.errors)
126
127        message = request.get('message')
128        if not message:
129            errors.update({'message': 'Please provide a message'})
130
131        mtool = getToolByName(self.context, "portal_membership")
132        member = mtool.getAuthenticatedMember()
133        comment_id = self.context.request.get('comment_id')
134        ksscore = self.getCommandSet('core')
135        if errors:
136            html = self.macroContent('context/report_abuse_form/macros/form',
137                                     errors=errors,
138                                     show_form=True,
139                                     tabindex=IndexIterator(),
140                                     member=member,
141                                     **request.form)
142            node = ksscore.getHtmlIdSelector('span-reply-form-holder-%s' % comment_id)
143            ksscore.replaceInnerHTML(node,  html)
144            return self.render()
145
146        # report_abuse(context, context, message, comment)
147        manage_mails(context, self.context, 'report_abuse')
148
149        html = self.macroContent('context/report_abuse_form/macros/form',
150                                 tabindex=IndexIterator(),
151                                 member=member,
152                                 **request.form)
153        node = ksscore.getHtmlIdSelector('span-reply-form-holder-%s' % comment_id)
154        html = '<br/><span style="color:red">You have reported this comment for abuse.</span>'
155        self.commands.addCommand('remove_abuse_report_form', 
156                                 node, 
157                                 comment_id=comment_id, 
158                                 html=html)
159
160        node = ksscore.getHtmlIdSelector('div-captcha-%s' % comment_id)
161        html = self.macroContent('context/report_abuse_form/macros/captcha',
162                                 **request.form)
163        ksscore.replaceInnerHTML(node,  html)
164        return self.render()
165
Note: See TracBrowser for help on using the repository browser.