]> git.openstreetmap.org Git - osqa.git/commitdiff
added the "Minimum reputation to not have your posts checked for spam." field to...
authorqw3rty <qw3rty@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 11 May 2010 19:50:01 +0000 (19:50 +0000)
committerqw3rty <qw3rty@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 11 May 2010 19:50:01 +0000 (19:50 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@224 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/akismet/startup.py

index 2035ea0dcb3b146297a6a43d27fb175bcc53ddbd..cb449cc5877f6242b37c4327d591f5846d84a8d4 100644 (file)
@@ -5,7 +5,9 @@ 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
+from forum.settings import APP_URL, OSQA_VERSION, REP_TO_FOR_NO_SPAM_CHECK
+from forum.models.user import User
+
 import settings
 
 
@@ -13,6 +15,8 @@ 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
+
             data = {
                 "user_ip":request.META["REMOTE_ADDR"],
                 "user_agent":request.environ['HTTP_USER_AGENT'],
@@ -20,7 +24,7 @@ def check_spam(param, comment_type):
                 "comment":comment
             }
 
-            if request.user.is_authenticated():
+            if user.is_authenticated():
                 data.update({
                     "comment_author":request.user.username,
                     "comment_author_email":request.user.email,
@@ -28,17 +32,18 @@ def check_spam(param, comment_type):
                 })
 
             api = Akismet(settings.WORDPRESS_API_KEY, APP_URL, "OSQA/%s" % OSQA_VERSION)
-            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 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
+                        })
                     
         return origin(request, *args, **kwargs)
     return wrapper