[#8192] if post is already destined for moderation queue and spammy, go 
straight to spam status


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

Branch: refs/heads/db/8192
Commit: 02dedc9f21b641d0113503f6b15b23d74ac4e292
Parents: b45d8f9
Author: Dave Brondsema <d...@brondsema.net>
Authored: Wed Mar 7 12:09:12 2018 -0500
Committer: Dave Brondsema <d...@brondsema.net>
Committed: Wed Mar 7 13:12:09 2018 -0500

----------------------------------------------------------------------
 Allura/allura/model/discuss.py                       | 15 ++++++++++++---
 .../forgediscussion/tests/functional/test_forum.py   |  7 ++++---
 .../forgetracker/tests/functional/test_root.py       | 15 ++++++++++++++-
 3 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/02dedc9f/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 32cf68e..61100e2 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -326,11 +326,19 @@ class Thread(Artifact, ActivityObject):
         if message_id is not None:
             kwargs['_id'] = message_id
         post = self.post_class()(**kwargs)
-        if ignore_security or not self.is_spam(post) and has_access(self, 
'unmoderated_post')():
+
+        # unmoderated post -> autoapprove
+        # unmoderated post but is spammy -> don't approve it, it goes into 
moderation
+        # moderated post -> moderation
+        # moderated post but is spammy -> mark as spam
+        spammy = self.is_spam(post)
+        if ignore_security or (not spammy and has_access(self, 
'unmoderated_post')):
             log.info('Auto-approving message from %s', c.user.username)
             file_info = kw.get('file_info', None)
             post.approve(file_info, notify=notify,
                          notification_text=notification_text)
+        elif not has_access(self, 'unmoderated_post') and spammy:
+            post.spam(submit_spam_feedback=False)  # no feedback since we're 
marking as spam automatically not manually
         else:
             self.notify_moderators(post)
         return post
@@ -786,9 +794,10 @@ class Post(Message, VersionedArtifact, ActivityObject):
             else:  # Send if no extra checks required
                 n.send_simple(artifact.monitoring_email)
 
-    def spam(self):
+    def spam(self, submit_spam_feedback=True):
         self.status = 'spam'
-        g.spam_checker.submit_spam(self.text, artifact=self, 
user=self.author())
+        if submit_spam_feedback:
+            g.spam_checker.submit_spam(self.text, artifact=self, 
user=self.author())
         session(self).flush(self)
         self.thread.update_stats()
 

http://git-wip-us.apache.org/repos/asf/allura/blob/02dedc9f/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 bf54413..929fc7f 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -491,17 +491,18 @@ class TestForum(TestController):
         opt_auth = select.find(text='*authenticated').parent
         opt_admin = select.find(text='Admin').parent
         r = self.app.post('/admin/discussion/update', params={
-            'card-0.value': opt_admin['value'],
             'card-0.id': 'admin',
+            'card-0.value': opt_admin['value'],
             'card-4.id': 'read',
             'card-4.value': opt_anon['value'],
+            'card-3.id': 'post',
             'card-3.value': opt_auth['value'],
             'card-3.new': opt_anon['value'],
-            'card-3.id': 'post'})
+        })
 
     @mock.patch('allura.model.discuss.g.spam_checker')
     def test_anonymous_post(self, spam_checker):
-        spam_checker.check.return_value = True
+        spam_checker.check.return_value = False
         self._set_anon_allowed()
         r = self.app.get('/discussion/create_topic/')
         f = r.html.find('form', {'action': 
'/p/test/discussion/save_new_topic'})

http://git-wip-us.apache.org/repos/asf/allura/blob/02dedc9f/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py 
b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 40afa8c..cb15819 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2592,7 +2592,7 @@ class TestEmailMonitoring(TrackerTestController):
     @patch('forgetracker.model.ticket.Notification.send_direct')
     @patch('allura.model.discuss.Thread.is_spam')
     def test_notifications_moderators(self, is_spam, send_direct):
-        is_spam.return_value = True
+        is_spam.return_value = False
         self.new_ticket(summary='test moderation', mount_point='/doc-bugs/')
         self.app.post('/doc-bugs/1/update_ticket', {
             'summary': 'test moderation',
@@ -2601,6 +2601,19 @@ class TestEmailMonitoring(TrackerTestController):
         send_direct.assert_called_with(
             str(M.User.query.get(username='test-admin')._id))
 
+    @td.with_tool('test', 'Tickets', 'doc-bugs', 
post_install_hook=post_install_hook)
+    @patch('forgetracker.model.ticket.Notification.send_direct')
+    @patch('allura.model.discuss.Thread.is_spam')
+    def test_notifications_off_spam(self, is_spam, send_direct):
+        # like test_notifications_moderators but no notification because it 
goes straight to spam status
+        is_spam.return_value = True
+        self.new_ticket(summary='test moderation', mount_point='/doc-bugs/')
+        self.app.post('/doc-bugs/1/update_ticket', {
+            'summary': 'test moderation',
+            'comment': 'test unmoderated post'
+        }, extra_environ=dict(username='*anonymous'))
+        assert not send_direct.called
+
     @patch('forgetracker.model.ticket.Notification.send_simple')
     def test_notifications_new(self, send_simple):
         self._set_options('NewTicketsOnly')

Reply via email to