You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/07/02 15:04:24 UTC

[1/2] allura git commit: [#7880] ticket:809 Send notification after moderator approves message

Repository: allura
Updated Branches:
  refs/heads/ib/7880 [created] 03bed4666


[#7880] ticket:809 Send notification after moderator approves message


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

Branch: refs/heads/ib/7880
Commit: 960c6c3a174a666e9a116e902fa55f34ec07e1e4
Parents: 14edf90
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 2 14:23:47 2015 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 14:23:47 2015 +0300

----------------------------------------------------------------------
 Allura/allura/controllers/discuss.py |  8 ++------
 Allura/allura/model/discuss.py       | 27 +++++++++++++++++++++------
 Allura/allura/model/notification.py  | 14 ++++++++------
 3 files changed, 31 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/960c6c3a/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 568ca5a..28cfcb6 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -359,7 +359,7 @@ class PostController(BaseController):
             self.post.spam()
         elif kw.pop('approve', None):
             if self.post.status != 'ok':
-                self.post.approve(notify=False)
+                self.post.approve()
                 g.spam_checker.submit_ham(
                     self.post.text, artifact=self.post, user=c.user)
                 self.post.thread.post_to_feed(self.post)
@@ -478,13 +478,9 @@ class ModerationController(BaseController):
                     elif spam and posted.status != 'spam':
                         posted.spam()
                     elif approve and posted.status != 'ok':
-                        posted.status = 'ok'
+                        posted.approve()
                         g.spam_checker.submit_ham(
                             posted.text, artifact=posted, user=c.user)
-                        posted.thread.last_post_date = max(
-                            posted.thread.last_post_date,
-                            posted.mod_date)
-                        posted.thread.num_replies += 1
                         posted.thread.post_to_feed(posted)
         redirect(request.referer)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/960c6c3a/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 326a140..a704da7 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -714,16 +714,31 @@ class Post(Message, VersionedArtifact, ActivityObject):
                                        related_nodes=[self.app_config.project],
                                        tags=['comment'])
 
-    def notify(self, file_info=None, check_dup=False, notification_text=None):
+    def notify(self, file_info=None, notification_text=None):
         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
+        msg_id = artifact.url() + self._id
+        notification_params = dict(
+            post=self,
+            text=notification_text,
+            file_info=file_info)
+        n = Notification.query.get(_id=msg_id)
+        if n and 'Moderation action required' in n.subject:
+            # Existing notification for this artifact is for moderators only,
+            # this means artifact was not auto approved, and all the
+            # subscribers did not receive notification. Now, moderator approved
+            # artifact/post, so we should re-send actual notification
+            msg_id = u'approved-' + msg_id
+            n = Notification.query.get(_id=msg_id)
+            if n:
+                # 'approved' notification also exists, re-send
+                n.fire_notification_task(artifact, 'message')
+            else:
+                # 'approved' notification does not exist, create
+                notification_params['message_id'] = msg_id
         if not n:
-            n = Notification.post(artifact, 'message',
-                                  post=self, text=notification_text,
-                                  file_info=file_info)
+            n = Notification.post(artifact, 'message', **notification_params)
         if not n:
             return
         if (hasattr(artifact, "monitoring_email")

http://git-wip-us.apache.org/repos/asf/allura/blob/960c6c3a/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 4241c42..ca1a850 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -110,15 +110,18 @@ class Notification(MappedClass):
     @classmethod
     def post(cls, artifact, topic, **kw):
         '''Create a notification and  send the notify message'''
-        import allura.tasks.notification_tasks
         n = cls._make_notification(artifact, topic, **kw)
         if n:
             # make sure notification is flushed in time for task to process it
             session(n).flush(n)
-            allura.tasks.notification_tasks.notify.post(
-                n._id, artifact.index_id(), topic)
+            n.fire_notification_task(artifact, topic)
         return n
 
+    def fire_notification_task(self, artifact, topic):
+        import allura.tasks.notification_tasks
+        allura.tasks.notification_tasks.notify.post(
+            self._id, artifact.index_id(), topic)
+
     @classmethod
     def post_user(cls, user, artifact, topic, **kw):
         '''Create a notification and deliver directly to a user's flash
@@ -168,10 +171,9 @@ class Notification(MappedClass):
             if post.parent_id and not subject.lower().startswith('re:'):
                 subject = 'Re: ' + subject
             author = post.author()
-            msg_id = artifact.url() + post._id
+            msg_id = kwargs.get('message_id') or artifact.url() + post._id
             parent_msg_id = artifact.url() + \
-                post.parent_id if post.parent_id else artifact.message_id(
-                )
+                post.parent_id if post.parent_id else artifact.message_id()
             d = dict(
                 _id=msg_id,
                 from_address=str(


[2/2] allura git commit: [#7880] ticket:809 Fix test for moderation controller

Posted by je...@apache.org.
[#7880] ticket:809 Fix test for moderation controller


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

Branch: refs/heads/ib/7880
Commit: 03bed4666544736c2d250a0a0d4092490f9889e6
Parents: 960c6c3
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 2 15:56:43 2015 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Jul 2 15:56:43 2015 +0300

----------------------------------------------------------------------
 .../controllers/test_discussion_moderation_controller.py |  1 +
 Allura/allura/tests/unit/patches.py                      | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/03bed466/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
index 5f88b0a..58c98ef 100644
--- a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
+++ b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py
@@ -28,6 +28,7 @@ from allura.tests.unit import patches
 
 class TestWhenModerating(WithDatabase):
     patches = [patches.fake_app_patch,
+               patches.fake_user_patch,
                patches.fake_redirect_patch,
                patches.fake_request_patch,
                patches.disable_notifications_patch]

http://git-wip-us.apache.org/repos/asf/allura/blob/03bed466/Allura/allura/tests/unit/patches.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/patches.py b/Allura/allura/tests/unit/patches.py
index 41cb403..afd5758 100644
--- a/Allura/allura/tests/unit/patches.py
+++ b/Allura/allura/tests/unit/patches.py
@@ -18,7 +18,11 @@
 from mock import Mock, patch
 from pylons import tmpl_context as c
 
-from allura.tests.unit.factories import create_project, create_app_config
+from allura.tests.unit.factories import (
+    create_project,
+    create_app_config,
+    create_user,
+)
 
 
 def fake_app_patch(test_case):
@@ -31,6 +35,11 @@ def fake_app_patch(test_case):
     return patch.object(c, 'app', app, create=True)
 
 
+def fake_user_patch(test_case):
+    user = create_user(username='my_user')
+    return patch.object(c, 'user', user, create=True)
+
+
 def project_app_loading_patch(test_case):
     test_case.fake_app = Mock()
     test_case.project_app_instance_function = Mock()