allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/2] allura git commit: [#8047] factor out a main_url() method and use it in spam filters to provide a better URL
Date Mon, 18 Jan 2016 19:11:34 GMT
[#8047] factor out a main_url() method and use it in spam filters to provide a better URL


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

Branch: refs/heads/db/8047
Commit: 8e334ce6851b198de753e531f68feb03b90ddd16
Parents: a7b79d9
Author: Dave Brondsema <dave@brondsema.net>
Authored: Mon Jan 18 14:07:33 2016 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Mon Jan 18 14:11:17 2016 -0500

----------------------------------------------------------------------
 Allura/allura/lib/spam/akismetfilter.py       |  7 +++++-
 Allura/allura/lib/spam/mollomfilter.py        |  9 +++++--
 Allura/allura/model/discuss.py                | 28 ++++++++++++++++++----
 Allura/allura/tests/unit/spam/test_akismet.py |  2 +-
 4 files changed, 37 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8e334ce6/Allura/allura/lib/spam/akismetfilter.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/spam/akismetfilter.py b/Allura/allura/lib/spam/akismetfilter.py
index 34f84d0..6f199d0 100644
--- a/Allura/allura/lib/spam/akismetfilter.py
+++ b/Allura/allura/lib/spam/akismetfilter.py
@@ -61,7 +61,12 @@ class AkismetSpamFilter(SpamFilter):
         kw['comment_content'] = text
         kw['comment_type'] = content_type
         if artifact:
-            kw['permalink'] = artifact.url()
+            try:
+                # if its a comment, get wiki, ticket, etc URL
+                url = artifact.main_url()
+            except:
+                url = artifact.url()
+            kw['permalink'] = url
         user = user or c.user
         if user:
             kw['comment_author'] = user.display_name or user.username

http://git-wip-us.apache.org/repos/asf/allura/blob/8e334ce6/Allura/allura/lib/spam/mollomfilter.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/spam/mollomfilter.py b/Allura/allura/lib/spam/mollomfilter.py
index 3651a94..88a34c8 100644
--- a/Allura/allura/lib/spam/mollomfilter.py
+++ b/Allura/allura/lib/spam/mollomfilter.py
@@ -67,10 +67,15 @@ class MollomSpamFilter(SpamFilter):
         log_msg = text
         kw['postBody'] = text
         if artifact:
+            try:
+                # if its a comment, get wiki, ticket, etc URL
+                url = artifact.main_url()
+            except:
+                url = artifact.url()
             # Should be able to send url, but can't right now due to a bug in
             # the PyMollom lib
-            # kw['url'] = artifact.url()
-            log_msg = artifact.url()
+            # kw['url'] = url
+            log_msg = url
         user = user or c.user
         if user:
             kw['authorName'] = user.display_name or user.username

http://git-wip-us.apache.org/repos/asf/allura/blob/8e334ce6/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index d90a14a..291f554 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -627,6 +627,28 @@ class Post(Message, VersionedArtifact, ActivityObject):
         else:  # pragma no cover
             return None
 
+    def parent_artifact(self):
+        """
+        :return: the artifact (e.g Ticket, Wiki Page) that this Post belongs to.  May return
None.
+        """
+        aref = ArtifactReference.query.get(_id=self.thread.ref_id)
+        if aref and aref.artifact:
+            return aref.artifact
+        else:
+            return None
+
+    def main_url(self):
+        """
+        :return: the URL for the artifact (e.g Ticket, Wiki Page) that this Post belongs
to,
+                 else the default thread URL
+        """
+        parent_artifact = self.parent_artifact()
+        if parent_artifact:
+            url = parent_artifact.url()
+        else:
+            url = self.thread.url()
+        return url
+
     def url_paginated(self):
         '''Return link to the thread with a #target that poins to this comment.
 
@@ -659,11 +681,7 @@ class Post(Message, VersionedArtifact, ActivityObject):
             page = find_i(posts) / limit
 
         slug = h.urlquote(self.slug)
-        aref = ArtifactReference.query.get(_id=self.thread.ref_id)
-        if aref and aref.artifact:
-            url = aref.artifact.url()
-        else:
-            url = self.thread.url()
+        url = self.main_url()
         if page == 0:
             return '%s?limit=%s#%s' % (url, limit, slug)
         return '%s?limit=%s&page=%s#%s' % (url, limit, page, slug)

http://git-wip-us.apache.org/repos/asf/allura/blob/8e334ce6/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 d821a66..1435c35 100644
--- a/Allura/allura/tests/unit/spam/test_akismet.py
+++ b/Allura/allura/tests/unit/spam/test_akismet.py
@@ -37,7 +37,7 @@ class TestAkismet(unittest.TestCase):
             # akismet can be successfully urlencoded
             urllib.urlencode(kw.get('data', {}))
         self.akismet.service.comment_check = mock.Mock(side_effect=side_effect)
-        self.fake_artifact = mock.Mock(**{'url.return_value': 'artifact url'})
+        self.fake_artifact = mock.Mock(**{'main_url.return_value': 'artifact url'})
         self.fake_user = mock.Mock(display_name=u'Søme User',
                                    email_addresses=['user@domain'])
         self.fake_headers = dict(


Mime
View raw message