allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [11/42] git commit: [#6328] ticket:448 Set In-Reply-To to parent's Message-ID
Date Tue, 29 Oct 2013 22:23:12 GMT
[#6328] ticket:448 Set In-Reply-To to parent's Message-ID


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

Branch: refs/heads/cj/6692
Commit: 734bf8a3dea5a35542e7b06d0e5893b19980b0eb
Parents: 9e35b6f
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Oct 22 14:29:32 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Thu Oct 24 18:59:28 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py                           |  8 +++++---
 Allura/allura/model/artifact.py                        |  6 +++++-
 Allura/allura/model/notification.py                    |  7 +++++--
 Allura/allura/tests/model/test_artifact.py             | 11 +++++++++++
 .../forgetracker/tests/functional/test_root.py         | 13 +++++++++++++
 5 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/734bf8a3/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 76bedbc..601f24d 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -412,15 +412,17 @@ def diff_text(t1, t2, differ=None):
             result += t1_words[i1:i2]
     return ' '.join(result).replace('\n', '<br/>\n')
 
-def gen_message_id():
+def gen_message_id(_id=None):
+    if not _id:
+        _id = nonce(40)
     if getattr(c, 'project', None):
         parts = c.project.url().split('/')[1:-1]
     else:
         parts = ['mail']
     if getattr(c, 'app', None):
-        addr = '%s.%s' % (nonce(40), c.app.config.options['mount_point'])
+        addr = '%s.%s' % (_id, c.app.config.options['mount_point'])
     else:
-        addr = nonce(40)
+        addr = _id
     return '%s@%s.sourceforge.net' % (
         addr, '.'.join(reversed(parts)))
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/734bf8a3/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 733f2b0..084ed9e 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -424,6 +424,10 @@ class Artifact(MappedClass):
     def get_mail_footer(self, notification, toaddr):
         return MailFooter.standard(notification)
 
+    def message_id(self):
+        '''Persistent, email-friendly (Message-ID header) id of this artifact'''
+        return h.gen_message_id(self._id)
+
 
 class Snapshot(Artifact):
     """A snapshot of an :class:`Artifact <allura.model.artifact.Artifact>`, used in
:class:`VersionedArtifact <allura.model.artifact.VersionedArtifact>`"""
@@ -467,7 +471,7 @@ class Snapshot(Artifact):
 
     def shorthand_id(self):
         return '%s#%s' % (self.original().shorthand_id(), self.version)
-    
+
     @property
     def attachments(self):
         orig = self.original()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/734bf8a3/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index f1449fe..95b51ba 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -160,14 +160,16 @@ 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
+            parent_msg_id = artifact.url() + post.parent_id if post.parent_id else artifact.message_id()
             d = dict(
-                _id=artifact.url()+post._id,
+                _id=msg_id,
                 from_address=str(author._id) if author != User.anonymous() else None,
                 reply_to_address='"%s" <%s>' % (
                     subject_prefix, getattr(artifact, 'email_address', u'noreply@in.sf.net')),
                 subject=subject_prefix + subject,
                 text=text,
-                in_reply_to=post.parent_id,
+                in_reply_to=parent_msg_id,
                 author_id=author._id,
                 pubdate=datetime.utcnow())
         elif topic == 'flash':
@@ -182,6 +184,7 @@ class Notification(MappedClass):
                 h.get_first(idx, 'title'),
                 getattr(artifact, 'email_address', u'noreply@in.sf.net'))
             d = dict(
+                message_id=artifact.message_id(),
                 from_address=reply_to,
                 reply_to_address=reply_to,
                 subject=subject_prefix + subject,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/734bf8a3/Allura/allura/tests/model/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index 639b247..cc27a7b 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -29,6 +29,7 @@ from nose import with_setup
 
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming.orm import Mapper
+from bson import ObjectId
 
 import allura
 from allura import model as M
@@ -133,6 +134,16 @@ def test_gen_messageid():
     assert re.match(r'[0-9a-zA-Z]*.wiki@test.p.sourceforge.net', h.gen_message_id())
 
 @with_setup(setUp, tearDown)
+def test_gen_messageid_with_id_set():
+    oid = ObjectId()
+    assert re.match(r'%s.wiki@test.p.sourceforge.net' % str(oid), h.gen_message_id(oid))
+
+@with_setup(setUp, tearDown)
+def test_artifact_messageid():
+    p = WM.Page(title='T')
+    assert re.match(r'%s.wiki@test.p.sourceforge.net' % str(p._id), p.message_id())
+
+@with_setup(setUp, tearDown)
 def test_versioning():
     pg = WM.Page(title='TestPage3')
     pg.commit()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/734bf8a3/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 ef53280..cfd2a61 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2682,3 +2682,16 @@ class TestStats(TrackerTestController):
     def test_stats(self):
         r = self.app.get('/bugs/stats/', status=200)
         assert_in('# tickets: 0', r.body)
+
+
+class TestNotifications(TrackerTestController):
+
+    def test_notification_email_grouping(self):
+        ticket_view = self.new_ticket(summary='Test Ticket')
+        ThreadLocalORMSession.flush_all()
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        email = M.MonQTask.query.find(dict(task_name='allura.tasks.mail_tasks.sendmail')).first()
+        ticket = tm.Ticket.query.get(ticket_num=1)
+        assert_equal(email.kwargs.message_id, ticket.message_id())
+        assert_equal(email.kwargs.in_reply_to, None)


Mime
View raw message