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/13 12:44:18 UTC
[14/29] allura git commit: [#7880] ticket:809 Send notification after
moderator approves message
[#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/c0844800
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c0844800
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c0844800
Branch: refs/heads/ib/7685
Commit: c084480011662111d94d1d5bc81cb2b5583fcad5
Parents: 91e883f
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Jul 2 14:23:47 2015 +0300
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Jul 9 13:51:47 2015 +0000
----------------------------------------------------------------------
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/c0844800/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/c0844800/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/c0844800/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(