예제 #1
0
파일: admin.py 프로젝트: w0lramD/kuma
    def submit_ham(self, request, data):
        """Submit new ham to Akismet.

        This is done directly with the Akismet client rather than the form
        classes, so that bulk edits can be made in the admin list view.

        It will raise NotEnabled or AkismetError if something goes wrong.
        """
        client = Akismet()
        if not client.ready:
            raise self.NotEnabled("Akismet is not configured.")
        spam_submission = flag_is_active(request, constants.SPAM_SUBMISSIONS_FLAG)
        if not spam_submission:
            raise self.NotEnabled("Akismet spam submission is not enabled.")
        user_ip = data.pop("user_ip", "")
        user_agent = data.pop("user_agent", "")
        client.submit_ham(user_ip=user_ip, user_agent=user_agent, **data)
예제 #2
0
파일: admin.py 프로젝트: MekliCZ/kuma
    def submit_ham(self, request, data):
        """Submit new ham to Akismet.

        This is done directly with the Akismet client rather than the form
        classes, so that bulk edits can be made in the admin list view.

        It will raise NotEnabled or AkismetError if something goes wrong.
        """
        client = Akismet()
        if not client.ready:
            raise self.NotEnabled('Akismet is not configured.')
        spam_submission = flag_is_active(request,
                                         constants.SPAM_SUBMISSIONS_FLAG)
        if not spam_submission:
            raise self.NotEnabled('Akismet spam submission is not enabled.')
        user_ip = data.pop('user_ip', '')
        user_agent = data.pop('user_agent', '')
        client.submit_ham(user_ip=user_ip, user_agent=user_agent, **data)
예제 #3
0
파일: admin.py 프로젝트: tqrg-bot/kuma
    def submit_ham(self, request, data):
        """Submit new ham to Akismet.

        This is done directly with the Akismet client rather than the form
        classes, so that bulk edits can be made in the admin list view.

        It will raise NotEnabled or AkismetError if something goes wrong.
        """
        client = Akismet()
        if not client.ready:
            raise self.NotEnabled("Akismet is not configured.")
        raise self.NotEnabled("Akismet spam submission is not enabled.")
예제 #4
0
    def handle(self, *args, **options):
        dry_run = options['dry_run']

        # first get the deleted document logs for the last n days
        ttl = timezone.now() - timedelta(days=options['days'])
        logged_deletions = DocumentDeletionLog.objects.filter(
            timestamp__gte=ttl,
        ).filter(
            # They use "spam" or "junk"
            # deleting spam revisions;
            # the spam makes me cry.  -- willkg
            models.Q(reason__icontains='spam') |
            models.Q(reason__icontains='junk')
        )
        count = logged_deletions.count()
        self.stdout.write('Checking %s deleted document logs' % count)

        sender = get_user_model().objects.get(username=options['username'])
        self.stdout.write(u'Submitting spam to Akismet as user %s' % sender)

        akismet = Akismet()

        if not akismet.ready:
            raise CommandError('Akismet client is not ready')

        for i, logged_deletion in enumerate(logged_deletions.iterator(), 1):
            self.stdout.write('%d/%d: ' % (i, count), ending='')
            # get the deleted document in question
            document = Document.admin_objects.filter(
                locale=logged_deletion.locale,
                slug=logged_deletion.slug,
            ).first()

            if document is None:
                # no document found with that locale and slug,
                # probably purged at some point
                self.stderr.write(u'Ignoring locale %s and slug %s' %
                                  (logged_deletion.locale,
                                   logged_deletion.slug))
                continue

            if not document.deleted:
                # guess the document got undeleted at some point again,
                # ignoring..
                self.stderr.write(u'Ignoring undeleted document %s' % document)
                continue

            if not document.current_revision:
                # no current revision found, which means something is fishy
                # but we can't submit it as spam since we don't have a revision
                self.stderr.write(u'Ignoring document %s without current '
                                  u'revision' % document.pk)
                continue

            params = revision_akismet_parameters(document.current_revision)
            if dry_run:
                # we're in dry-run, so let's continue okay?
                self.stdout.write(u'Not submitting current revision %s of '
                                  u'document %s because of dry-mode' %
                                  (document.current_revision.pk, document.pk))
                continue
            try:
                akismet.submit_spam(**params)
            except AkismetError as exc:
                self.stderr.write(u'Akismet error while submitting current '
                                  u'revision %s of document %s: %s' %
                                  (document.current_revision.pk, document.pk,
                                   exc.debug_help))
            else:
                self.stdout.write(u'Successfully submitted current '
                                  u'revision %s of document %s' %
                                  (document.current_revision.pk, document.pk))
                submission = RevisionAkismetSubmission(
                    revision=document.current_revision,
                    sender=sender,
                    type=RevisionAkismetSubmission.SPAM_TYPE,
                )
                submission.save()
예제 #5
0
    def handle(self, *args, **options):
        dry_run = options['dry_run']

        # first get the deleted document logs for the last n days
        ttl = timezone.now() - timedelta(days=options['days'])
        logged_deletions = DocumentDeletionLog.objects.filter(
            # They use "spam"
            # deleting spam revisions;
            # the spam makes me cry.  -- willkg
            timestamp__gte=ttl,
            reason__icontains='spam'
        )
        count = logged_deletions.count()
        self.stdout.write('Checking %s deleted document logs' % count)

        sender = get_user_model().objects.get(username=options['username'])
        self.stdout.write('Submitting spam to Akismet as user %s' % sender)

        akismet = Akismet()

        if not akismet.ready:
            raise CommandError('Akismet client is not ready')

        for i, logged_deletion in enumerate(logged_deletions.iterator(), 1):
            self.stdout.write('%d/%d: ' % (i, count), ending='')
            # get the deleted document in question
            document = Document.admin_objects.filter(
                locale=logged_deletion.locale,
                slug=logged_deletion.slug,
            ).first()

            if document is None:
                # no document found with that locale and slug,
                # probably purged at some point
                self.stderr.write('Ignoring locale %s and slug %s' %
                                  (logged_deletion.locale,
                                   logged_deletion.slug))
                continue

            if not document.deleted:
                # guess the document got undeleted at some point again,
                # ignoring..
                self.stderr.write('Ignoring undeleted document %s' % document)
                continue

            if not document.current_revision:
                # no current revision found, which means something is fishy
                # but we can't submit it as spam since we don't have a revision
                self.stderr.write('Ignoring document %s without current '
                                  'revision' % document.pk)
                continue

            akismet_data = AkismetHistoricalData(document.current_revision)
            params = akismet_data.parameters
            if dry_run:
                # we're in dry-run, so let's continue okay?
                self.stdout.write('Not submitting current revision %s of '
                                  'document %s because of dry-mode' %
                                  (document.current_revision.pk, document.pk))
                continue
            try:
                akismet.submit_spam(**params)
            except AkismetError as exc:
                self.stderr.write('Akismet error while submitting current '
                                  'revision %s of document %s: %s' %
                                  (document.current_revision.pk, document.pk,
                                   exc.debug_help))
            else:
                self.stdout.write('Successfully submitted current '
                                  'revision %s of document %s' %
                                  (document.current_revision.pk, document.pk))
                submission = RevisionAkismetSubmission(
                    revision=document.current_revision,
                    sender=sender,
                    type=RevisionAkismetSubmission.SPAM_TYPE,
                )
                submission.save()