allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] allura git commit: [#8047] akismet ham/spam report sends original user, and not current request info
Date Mon, 18 Jan 2016 19:11:33 GMT
Repository: allura
Updated Branches:
  refs/heads/db/8047 [created] 8e334ce68


[#8047] akismet ham/spam report sends original user, and not current request info


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

Branch: refs/heads/db/8047
Commit: a7b79d9bed9c78d13220d6b886d7e8d08f71356f
Parents: 26799a1
Author: Dave Brondsema <dave@brondsema.net>
Authored: Mon Jan 18 13:58:42 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Jan 18 13:58:42 2016 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py          |  6 ++---
 Allura/allura/lib/spam/akismetfilter.py       | 16 +++++++------
 Allura/allura/model/discuss.py                |  2 +-
 Allura/allura/tests/unit/spam/test_akismet.py | 26 +++++++++++++---------
 4 files changed, 28 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a7b79d9b/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 4c0c748..c22e772 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -357,8 +357,7 @@ class PostController(BaseController):
         elif kw.pop('approve', None):
             if self.post.status != 'ok':
                 self.post.approve()
-                g.spam_checker.submit_ham(
-                    self.post.text, artifact=self.post, user=c.user)
+                g.spam_checker.submit_ham(self.post.text, artifact=self.post, user=self.post.author())
                 self.post.thread.post_to_feed(self.post)
         self.thread.update_stats()
         return dict(result='success')
@@ -473,8 +472,7 @@ class ModerationController(BaseController):
                         posted.spam()
                     elif approve and posted.status != 'ok':
                         posted.approve()
-                        g.spam_checker.submit_ham(
-                            posted.text, artifact=posted, user=c.user)
+                        g.spam_checker.submit_ham(posted.text, artifact=posted, user=posted.author())
                         posted.thread.post_to_feed(posted)
         redirect(request.referer)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/a7b79d9b/Allura/allura/lib/spam/akismetfilter.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/spam/akismetfilter.py b/Allura/allura/lib/spam/akismetfilter.py
index 4913970..34f84d0 100644
--- a/Allura/allura/lib/spam/akismetfilter.py
+++ b/Allura/allura/lib/spam/akismetfilter.py
@@ -57,7 +57,7 @@ class AkismetSpamFilter(SpamFilter):
             config.get('spam.key'), config.get('base_url'))
         self.service.verify_key()
 
-    def get_data(self, text, artifact=None, user=None, content_type='comment', **kw):
+    def get_data(self, text, artifact=None, user=None, content_type='comment', request=None,
**kw):
         kw['comment_content'] = text
         kw['comment_type'] = content_type
         if artifact:
@@ -65,11 +65,11 @@ class AkismetSpamFilter(SpamFilter):
         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'] = utils.ip_address(request)
-        kw['user_agent'] = request.headers.get('USER_AGENT')
-        kw['referrer'] = request.headers.get('REFERER')
+            kw['comment_author_email'] = user.email_addresses[0] if user.email_addresses
else ''
+        if request:
+            kw['user_ip'] = utils.ip_address(request)
+            kw['user_agent'] = request.headers.get('USER_AGENT')
+            kw['referrer'] = request.headers.get('REFERER')
         # kw will be urlencoded, need to utf8-encode
         for k, v in kw.items():
             kw[k] = h.really_unicode(v).encode('utf8')
@@ -81,7 +81,9 @@ class AkismetSpamFilter(SpamFilter):
                                          data=self.get_data(text=text,
                                                             artifact=artifact,
                                                             user=user,
-                                                            content_type=content_type),
+                                                            content_type=content_type,
+                                                            request=request,
+                                                            ),
                                          build_data=False)
         log.info("spam=%s (akismet): %s" % (str(res), log_msg))
         return res

http://git-wip-us.apache.org/repos/asf/allura/blob/a7b79d9b/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 69bf556..d90a14a 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -755,7 +755,7 @@ class Post(Message, VersionedArtifact, ActivityObject):
     def spam(self):
         self.status = 'spam'
         self.thread.num_replies = max(0, self.thread.num_replies - 1)
-        g.spam_checker.submit_spam(self.text, artifact=self, user=c.user)
+        g.spam_checker.submit_spam(self.text, artifact=self, user=self.author())
 
 
 class DiscussionAttachment(BaseAttachment):

http://git-wip-us.apache.org/repos/asf/allura/blob/a7b79d9b/Allura/allura/tests/unit/spam/test_akismet.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/spam/test_akismet.py b/Allura/allura/tests/unit/spam/test_akismet.py
index 79802c3..d821a66 100644
--- a/Allura/allura/tests/unit/spam/test_akismet.py
+++ b/Allura/allura/tests/unit/spam/test_akismet.py
@@ -117,21 +117,27 @@ class TestAkismet(unittest.TestCase):
             data=expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetfilter.c')
-    @mock.patch('allura.lib.spam.akismetfilter.request')
-    def test_submit_spam(self, request, c):
-        request.headers = self.fake_headers
-        request.remote_addr = 'some ip'
+    def test_submit_spam(self, c):
         c.user = None
+
         self.akismet.submit_spam(self.content)
+
+        # no IP addr, UA, etc, since this isn't the original request
+        expected_data = dict(comment_content=u'spåm text'.encode('utf8'),
+                             comment_type='comment',
+                             )
         self.akismet.service.submit_spam.assert_called_once_with(
-            self.content, data=self.expected_data, build_data=False)
+            self.content, data=expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetfilter.c')
-    @mock.patch('allura.lib.spam.akismetfilter.request')
-    def test_submit_ham(self, request, c):
-        request.headers = self.fake_headers
-        request.remote_addr = 'some ip'
+    def test_submit_ham(self, c):
         c.user = None
+
         self.akismet.submit_ham(self.content)
+
+        # no IP addr, UA, etc, since this isn't the original request
+        expected_data = dict(comment_content=u'spåm text'.encode('utf8'),
+                             comment_type='comment',
+                             )
         self.akismet.service.submit_ham.assert_called_once_with(
-            self.content, data=self.expected_data, build_data=False)
+            self.content, data=expected_data, build_data=False)


Mime
View raw message