Ignore:
Timestamp:
Jul 31, 2009 3:30:02 PM (15 years ago)
Author:
liebster
Message:

Added "report abuse" feature contributed by jcbrand.

Location:
quintagroup.plonecomments/trunk/quintagroup/plonecomments/browser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/browser/comments.pt

    r822 r1201  
    44                   isAnon view/is_anonymous; 
    55                   ifModerate view/is_moderation_enabled; 
    6                    isModerationAllowed view/can_moderate" 
     6                   isModerationAllowed view/can_moderate; 
     7                   isAuthenticatedReportAbuseEnabled view/authenticated_report_abuse_enabled; 
     8                   isAjaxReportAbuseEnabled view/ajax_report_abuse_enabled; 
     9                   isAnonymousReportAbuseEnabled view/anonymous_report_abuse_enabled; 
     10                   isReportAbuseEnabled python:isAnonymousReportAbuseEnabled or not isAnon and isAuthenticatedReportAbuseEnabled" 
    711                   i18n:domain="plone"> 
    812    <div class="discussion" 
     
    3640                tal:define="indent python:reply_dict['depth']*2; 
    3741                            reply python:reply_dict['object']; 
     42                            comment_id python:reply_dict['object'].id; 
    3843                            isPublished python:reply.review_state=='published';" 
    3944                tal:attributes="style string:margin-left:${indent}em;"> 
     
    9095                           /> 
    9196                </form> 
     97                <tal:if tal:condition="python:isReportAbuseEnabled and isPublished"> 
     98                    <form class="report_abuse" 
     99                          name="report_abuse" 
     100                          method="post" 
     101                          style="display: inline;" 
     102                          tal:attributes="action string:${reply/absolute_url}/report_abuse_form#discussion"> 
     103                        <input type="hidden" name="comment_id" tal:attributes="value comment_id" /> 
     104                        <input class="standalone" 
     105                            type="submit" 
     106                            value="Report Abuse" 
     107                            tal:define="onclick string:javascript:render_abuse_report_form(${comment_id})" 
     108                            tal:attributes="onclick python:isAjaxReportAbuseEnabled and onclick or ''; 
     109                                            id string:input-render-abuse-cancel-${comment_id}" 
     110                            i18n:attributes="value label_report_abuse;" 
     111                            /> 
     112                    </form> 
     113                    <span tal:attributes="id string:span-reply-form-holder-${comment_id}" 
     114                            tal:condition="isReportAbuseEnabled"> 
     115                        <metal:macro use-macro="here/report_abuse_form/macros/form"/> 
     116                    </span> 
     117                    <span tal:attributes="id string:span-abuse-count-holder-${comment_id}"></span> 
     118                </tal:if> 
    92119                <form name="publish_discussion" 
    93120                      action="" 
     
    108135                     i18n:domain="quintagroup.plonecomments" 
    109136                     tal:condition="not:isPublished">Comment must be approved before replies to comment accepted.</div> 
    110  
    111137            </div> 
    112138        </tal:getreplies> 
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/browser/comments.py

    r822 r1201  
    33from Acquisition import aq_inner 
    44from AccessControl import getSecurityManager 
     5 
     6from Products.CMFPlone.utils import IndexIterator 
    57from Products.CMFPlone.utils import getToolByName 
     8from Products.CMFFormController.ControllerState import ControllerState 
     9from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
     10from quintagroup.plonecomments.utils import manage_mails 
    611 
    7 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    812from plone.app.layout.viewlets import comments 
     13from plone.app.kss.plonekssview import PloneKSSView 
    914 
    1015class CommentsViewlet(comments.CommentsViewlet): 
    1116    """A custom version of the comments viewlet 
    1217    """ 
    13  
    1418    render = ViewPageTemplateFile('comments.pt') 
    1519 
     
    5256 
    5357        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() 
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/browser/configure.zcml

    r820 r1201  
    22    xmlns="http://namespaces.zope.org/zope" 
    33    xmlns:browser="http://namespaces.zope.org/browser" 
     4    xmlns:kss="http://namespaces.zope.org/kss" 
    45    i18n_domain="quintagroup.plonecomments"> 
    56 
     7    <browser:page 
     8        for="*" 
     9        attribute="submit_abuse_report" 
     10        class=".comments.CommentsKSS" 
     11        name="kss_submit_abuse_report" 
     12        permission="zope2.View" 
     13        />  
     14 
     15    <kss:action 
     16        name="remove_abuse_report_form" 
     17        command_factory="selector" 
     18        jsfile="../skins/quintagroup_plonecomments/qcomments.js" 
     19        /> 
     20 
    621</configure> 
Note: See TracChangeset for help on using the changeset viewer.