incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#4737] ticket:174 do not send edit notifications for post if notifications disabled for entire project
Date Fri, 28 Sep 2012 14:58:21 GMT
Updated Branches:
  refs/heads/master 3d42e7fe8 -> 3f844c9af


[#4737] ticket:174 do not send edit notifications for post if notifications disabled for entire
project


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

Branch: refs/heads/master
Commit: 3f844c9afc04159384c76f2ea8048e783a718b31
Parents: 3d42e7f
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Sep 24 17:18:03 2012 +0300
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Fri Sep 28 14:58:08 2012 +0000

----------------------------------------------------------------------
 Allura/allura/model/discuss.py               |    3 +++
 Allura/allura/tests/model/test_discussion.py |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f844c9a/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 12aa456..0f6fcf1 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -587,12 +587,15 @@ class Post(Message, VersionedArtifact, ActivityObject):
                     related_nodes=[self.app_config.project])
 
     def notify(self, file_info=None, check_dup=False):
+        if self.project.notifications_disabled:
+            return  # notifications disabled for entire project
         artifact = self.thread.artifact or self.thread
         n = Notification.query.get(
             _id=artifact.url() + self._id) if check_dup else None
         if not n:
             n = Notification.post(artifact, 'message', post=self,
                                   file_info=file_info)
+        if not n: return
         if (hasattr(artifact, "monitoring_email")
                 and artifact.monitoring_email):
             if hasattr(artifact, 'notify_post'):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f844c9a/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 03959f7..3124320 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -10,6 +10,7 @@ from cgi import FieldStorage
 from pylons import c, g, request, response
 from nose.tools import assert_raises, assert_equals, with_setup
 import mock
+from mock import patch
 
 from ming.orm import session, ThreadLocalORMSession
 from webob import Request, Response, exc
@@ -289,3 +290,23 @@ def test_post_url_paginated():
             url += '&page=%s' % page
         url += '#' + _p.slug
         assert _p.url_paginated() == url, _p.url_paginated()
+
+
+@with_setup(setUp, tearDown)
+def test_post_notify():
+    d = M.Discussion(shortname='test', name='test')
+    d.monitoring_email = 'darthvader@deathstar.org'
+    t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
+    with patch('allura.model.notification.Notification.send_simple') as send:
+        t.post('This is a post')
+        send.assert_called_with(d.monitoring_email)
+
+    c.app.config.project.notifications_disabled = True
+    with patch('allura.model.notification.Notification.send_simple') as send:
+        t.post('Another post')
+        try:
+            send.assert_called_with(d.monitoring_email)
+        except AssertionError:
+            pass  # method not called as expected
+        else:
+            assert False, 'send_simple must not be called'


Mime
View raw message