]> git.openstreetmap.org Git - osqa.git/commitdiff
Move reputation check to before collecting all data.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 11 May 2010 22:29:07 +0000 (22:29 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 11 May 2010 22:29:07 +0000 (22:29 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@228 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/akismet/startup.py

index cb449cc5877f6242b37c4327d591f5846d84a8d4..5f9ab84359f6ebbec70a69cfda96c2256518941b 100644 (file)
@@ -5,7 +5,8 @@ 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_TO_FOR_NO_SPAM_CHECK
 from forum.models.user import User
 
 import settings
@@ -13,7 +14,8 @@ 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:
+        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 and request.user.is_superuser and request.user.reputation >= REP_TO_FOR_NO_SPAM_CHECK)):
             comment = request.POST[param]
             user = request.user
 
@@ -32,18 +34,17 @@ def check_spam(param, comment_type):
                 })
 
             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