X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/ccff40dc85f2a45c234ba280ed62c55c1e19d408..178a88bfeb53a6b9520c74c10eea42073098902b:/forum_modules/akismet/startup.py diff --git a/forum_modules/akismet/startup.py b/forum_modules/akismet/startup.py index cb449cc..1e9e731 100644 --- a/forum_modules/akismet/startup.py +++ b/forum_modules/akismet/startup.py @@ -1,11 +1,13 @@ from django.utils.translation import ugettext as _ from django.http import HttpResponse, HttpResponseRedirect from django.utils import simplejson +from django.utils.encoding import smart_str from django.shortcuts import render_to_response from forum.modules.decorators import decorate from forum import views from lib.akismet import Akismet -from forum.settings import APP_URL, OSQA_VERSION, REP_TO_FOR_NO_SPAM_CHECK +from forum.settings import APP_URL, OSQA_VERSION +from settings import WORDPRESS_API_KEY, REP_FOR_NO_SPAM_CHECK from forum.models.user import User import settings @@ -13,9 +15,9 @@ import settings def check_spam(param, comment_type): def wrapper(origin, request, *args, **kwargs): - if request.POST and request.POST.get(param, None) and settings.WORDPRESS_API_KEY: - comment = request.POST[param] - user = request.user + if (request.POST and request.POST.get(param, None) and WORDPRESS_API_KEY) and (not request.user.is_authenticated() + or not (request.user.is_staff or request.user.is_superuser or request.user.reputation >= REP_FOR_NO_SPAM_CHECK)): + comment = smart_str(request.POST[param]) data = { "user_ip":request.META["REMOTE_ADDR"], @@ -24,26 +26,25 @@ def check_spam(param, comment_type): "comment":comment } - if user.is_authenticated(): + if request.user.is_authenticated(): data.update({ - "comment_author":request.user.username, + "comment_author":smart_str(request.user.username), "comment_author_email":request.user.email, "comment_author_url":request.user.website, }) api = Akismet(settings.WORDPRESS_API_KEY, APP_URL, "OSQA/%s" % OSQA_VERSION) - if not user.is_authenticated() or (user.reputation < settings.REP_TO_FOR_NO_SPAM_CHECK and not user.is_staff and not user.is_superuser): - if api.comment_check(comment, data): - if request.is_ajax(): - response = { - 'success': False, - 'error_message': _("Sorry, but akismet thinks your %s is spam.") % comment_type - } - return HttpResponse(simplejson.dumps(response), mimetype="application/json") - else: - return render_to_response('modules/akismet/foundspam.html', { - 'action_name': comment_type - }) + if api.comment_check(comment, data): + if request.is_ajax(): + response = { + 'success': False, + 'error_message': _("Sorry, but akismet thinks your %s is spam.") % comment_type + } + return HttpResponse(simplejson.dumps(response), mimetype="application/json") + else: + return render_to_response('modules/akismet/foundspam.html', { + 'action_name': comment_type + }) return origin(request, *args, **kwargs) return wrapper