You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2012/12/01 00:20:42 UTC

git commit: [#5382] WIP

Updated Branches:
  refs/heads/tv/5382 [created] d7977568c


[#5382] WIP


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d7977568
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d7977568
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d7977568

Branch: refs/heads/tv/5382
Commit: d7977568c98d235c26749761b868107a02bb75dd
Parents: 7bed302
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Nov 30 23:20:26 2012 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Nov 30 23:20:26 2012 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py |    2 +
 Allura/allura/lib/app_globals.py     |   31 +++++++++++++++++++++++++++++
 requirements-sf.txt                  |    1 +
 3 files changed, 34 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7977568/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 005169e..653bdd0 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -183,8 +183,10 @@ class ThreadController(BaseController):
         if not kw['text']:
             flash('Your post was not saved. You must provide content.', 'error')
             redirect(request.referer)
+
         file_info = kw.get('file_info', None)
         p = self.thread.add_post(**kw)
+        is_spam = g.akismet.check(kw['text'], artifact=p, user=c.user)
         if hasattr(file_info, 'file'):
             p.attach(
                 file_info.filename, file_info.file, content_type=file_info.type,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7977568/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 1789855..58d20a1 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -165,6 +165,37 @@ class Globals(object):
         self._zarkov = None
 
     @LazyProperty
+    def akismet(self):
+        akismet_key = config.get('spam.akismet_key')
+        if akismet_key:
+            import akismet
+
+            class Akismet(akismet.Akismet):
+                def check(self, text, artifact=None, user=None, content_type='comment', **kw):
+                    log_msg = text
+                    kw['comment_type'] = content_type
+                    if artifact:
+                        kw['permalink'] = artifact.url()
+                        log_msg = artifact.url()
+                    user = user or c.user
+                    if user:
+                        kw['comment_author'] = user.display_name or user.username
+                        kw['comment_author_email'] = user.email_addresses[0] if user.email_addresses else ''
+                    kw['user_ip'] = request.environ['REMOTE_ADDR']
+                    kw['user_agent'] = request.environ['HTTP_USER_AGENT']
+                    kw['referrer'] = request.environ['HTTP_REFERER']
+                    res = self.comment_check(text, data=kw, build_data=False)
+                    log.info("spam=%s (akismet): %s" % (str(res), log_msg))
+                    return res
+
+            akismet = Akismet(akismet_key, config.get('base_url'))
+            akismet.verify_key()
+        else:
+            import mock
+            akismet = mock.Mock(**{'check.return_value': False})
+        return akismet
+
+    @LazyProperty
     def director(self):
         """Return activitystream director"""
         if asbool(config.get('activitystream.recording.enabled', False)):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7977568/requirements-sf.txt
----------------------------------------------------------------------
diff --git a/requirements-sf.txt b/requirements-sf.txt
index 79ac3bd..4305dde 100644
--- a/requirements-sf.txt
+++ b/requirements-sf.txt
@@ -1,5 +1,6 @@
 # requirements for the SF instance
 
+akismet==0.2.0
 amqplib==0.6.1
 kombu==1.0.4
 coverage==3.5a1-20110413