Пример #1
0
    def report_abuse(self, id):
        """
        When a user reports something as offensive, this action will mark it
        ready for moderation.  If the user reporting is a system administrator
        it will be marked, but also made invisible so that it no longer shows up
        """
        import ckan.model as model
        from ckanext.dgu.model.feedback import Feedback

        fb = Feedback.get(id)
        if fb:
            fb.moderated = False
            fb.moderation_required = True
            if is_sysadmin():
                fb.visible = False
                flash_notice(
                    "Queued. As you are an administrator, this item has been hidden"
                )
            else:
                flash_notice(
                    "Thank you for your feedback, the item has been queued for moderation"
                )
            model.Session.add(fb)
            model.Session.commit()

        h.redirect_to(request.referer or '/data')
Пример #2
0
    def report_abuse(self, id):
        """
        When a user reports something as offensive, this action will mark it
        ready for moderation.  If the user reporting is a system administrator
        it will be marked, but also made invisible so that it no longer shows up
        """
        import ckan.model as model
        from ckanext.dgu.model.feedback import Feedback

        fb = Feedback.get(id)
        if fb:
            fb.moderated = False
            fb.moderation_required = True
            if is_sysadmin():
                fb.visible = False
                flash_notice("Queued. As you are an administrator, this item has been hidden")
            else:
                flash_notice("Thank you for your feedback, the item has been queued for moderation")
            model.Session.add(fb)
            model.Session.commit()

        h.redirect_to(request.referer or '/data')
Пример #3
0
            delete, publish, delete_and_ban within the action param
        """
        import ckan.model as model
        from ckanext.dgu.model.feedback import Feedback, FeedbackBlockedUser

        def status(success, msg=''):
            return json.dumps({'success': success, 'message': msg})

        # Only system administrators may access this page.
        try:
            context = {'model':model,'user': c.user}
            check_access('feedback_update',context)
        except NotAuthorized, e:
            return status('error', 'Permission denied')

        fb = Feedback.get(id)
        if not fb:
            return status('error', 'Feedback not found')

        action = request.params.get('action', '')
        if not action:
            return status('error', 'Unknown action')

        fb.moderated_by = c.user

        # Perform the relevant action based on what we have been asked to do.
        if action == 'delete':
            fb.active = False
            model.Session.add(fb)
        elif action == 'delete_and_ban':
            fb.active = False
Пример #4
0
    def _get_form_data(self, package):
        """
        Extracts the parameters from the POST request and stores them
        in a feedback model.

        TODO: This should be in the logic layer.  Along with the
              appropriate auth.
        """
        from ckanext.dgu.lib.spam_check import is_spam, MOLLOM_SPAM, MOLLOM_HAM
        from ckanext.dgu.model.feedback import Feedback

        # TODO: This is a bit dense, could do with cleaning up.
        data = {'package_id': package.id, 'user_id': c.user}
        data["economic"] = asbool(request.POST.get('economic', False))
        data["economic_comment"] = request.POST.get('economic_comment', u'')
        data["social"] = asbool(request.POST.get('social', False))
        data["social_comment"] = request.POST.get('social_comment', u'')
        data["effective"] = asbool(request.POST.get('effective', False))
        data["effective_comment"] = request.POST.get('effective_comment', u'')
        data["other"] = asbool(request.POST.get('other', False))
        data["other_comment"] = request.POST.get('other_comment', u'')
        if request.POST.get('linked', '') == 'dontknow':
            data["linked"] = False
        else:
            data["linked"] = asbool(request.POST.get('linked', False))

        data["linked_comment"] = request.POST.get('linked_comment', u'')

        data["responding_as"] = request.POST.get('responding_as',
                                                 u'individual')
        if data["responding_as"] == 'organisation':
            data["organisation"] = request.POST.get('organisation', u'')
            data["organisation_name"] = request.POST.get(
                'organisation_name', u'')
        data["contact"] = asbool(request.POST.get('contact', False))

        # Concatenate all of the comments, and then do a spam check if we have
        # anything to send.
        comments = [
            data["economic_comment"] or '', data["social_comment"] or '',
            data["effective_comment"] or '', data["other_comment"] or '',
            data["linked_comment"] or ''
        ]
        content = [ct for ct in comments if ct.strip() != u""]
        if ''.join(content).strip():
            success, flag = is_spam('\n'.join(content), c.userobj)
        else:
            log.warning("No comments to send for spam check")
            success, flag = True, MOLLOM_HAM

        msg = "Thank you for your feedback"
        if not success:
            # If we fail to check spam, force into moderation
            data["moderation_required"] = True
            msg = "Thank you for your feedback. " \
                  "Your comments have been marked for moderation."
        else:
            data["spam_score"] = flag
            if flag == MOLLOM_SPAM:
                data["moderation_required"] = True
                data["visible"] = False
                msg = "Your post has been identified as spam and has not been posted."

        flash_notice(msg)
        return Feedback(**data)
Пример #5
0
            delete, publish, delete_and_ban within the action param
        """
        import ckan.model as model
        from ckanext.dgu.model.feedback import Feedback, FeedbackBlockedUser

        def status(success, msg=''):
            return json.dumps({'success': success, 'message': msg})

        # Only system administrators may access this page.
        try:
            context = {'model': model, 'user': c.user}
            check_access('feedback_update', context)
        except NotAuthorized, e:
            return status('error', 'Permission denied')

        fb = Feedback.get(id)
        if not fb:
            return status('error', 'Feedback not found')

        action = request.params.get('action', '')
        if not action:
            return status('error', 'Unknown action')

        fb.moderated_by = c.user

        # Perform the relevant action based on what we have been asked to do.
        if action == 'delete':
            fb.active = False
            model.Session.add(fb)
        elif action == 'delete_and_ban':
            fb.active = False