allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: SF-176 Whitelist posts for members of a project (spam)
Date Mon, 18 Apr 2016 18:05:07 GMT
Repository: allura
Updated Branches:
  refs/heads/master eb61cbe7c -> ec3cf88fd


SF-176  Whitelist posts for members of a project (spam)


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

Branch: refs/heads/master
Commit: ec3cf88fd702806563fecaa608450da7d28f08a4
Parents: eb61cbe
Author: Heith Seewald <heiths@gmail.com>
Authored: Mon Apr 18 12:52:51 2016 -0400
Committer: Heith Seewald <heiths@gmail.com>
Committed: Mon Apr 18 12:52:51 2016 -0400

----------------------------------------------------------------------
 Allura/allura/model/discuss.py                      |  3 ++-
 .../forgediscussion/tests/functional/test_forum.py  | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ec3cf88f/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 82e1da1..36dc160 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -288,7 +288,8 @@ class Thread(Artifact, ActivityObject):
         return p
 
     def is_spam(self, post):
-        if c.user in c.project.users_with_role('Admin', 'Developer'):
+        roles = [r.name for r in c.project.named_roles]
+        if c.user in c.project.users_with_role(*roles):
             return False
         else:
             return g.spam_checker.check(post.text, artifact=post, user=c.user)

http://git-wip-us.apache.org/repos/asf/allura/blob/ec3cf88f/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index 566db32..6475514 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -25,7 +25,9 @@ from email.mime.image import MIMEImage
 from email.mime.multipart import MIMEMultipart
 
 import pkg_resources
+from ming.odm import ThreadLocalORMSession
 from pylons import tmpl_context as c
+
 from nose.tools import assert_equal, assert_in, assert_not_in, assert_true, assert_false
 import feedparser
 
@@ -33,6 +35,7 @@ from allura import model as M
 from allura.tasks import mail_tasks
 from alluratest.controller import TestController
 from allura.lib import helpers as h
+from allura.tests import decorators as td
 
 from forgediscussion import model as FM
 
@@ -516,6 +519,19 @@ class TestForum(TestController):
         link = '<a href="%s">[%s]</a>' % (post.thread.url() + '?limit=25#' +
post.slug, post.shorthand_id())
         assert link in r, link
 
+    @td.with_tool('test2', 'Discussion', 'discussion')
+    @mock.patch('allura.model.discuss.g.spam_checker')
+    def test_is_spam(self, spam_checker):
+        spam_checker.check.return_value = True
+        c.user = M.User.query.get(username="test-user")
+        role = M.ProjectRole(project_id=c.project._id, name='TestRole')
+        M.ProjectRole.by_user(c.user, upsert=True).roles.append(role._id)
+        ThreadLocalORMSession.flush_all()
+        t = M.Thread()
+        p = M.Post()
+        assert_in('TestRole', [r.name for r in c.project.named_roles])
+        assert_false(t.is_spam(p))
+
     def test_thread(self):
         r = self.app.get('/discussion/create_topic/')
         f = r.html.find(


Mime
View raw message