allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [41/50] git commit: [#5656] ticket:358 Respect new email monitoring types
Date Tue, 28 May 2013 16:01:33 GMT
[#5656] ticket:358 Respect new email monitoring types


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

Branch: refs/heads/cj/5913
Commit: 82f675f705b860fe3806f28d530dbb139e8156da
Parents: ed74e25
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu May 23 14:45:33 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri May 24 18:42:27 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py          |   22 +++--
 .../forgetracker/tests/functional/test_root.py     |   87 +++++++++++++++
 2 files changed, 101 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82f675f7/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 24a5d08..bc2d0c2 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -266,18 +266,24 @@ class Globals(MappedClass):
                 destinations = [str(user._id)]))
             mail_tasks.sendmail.post(**mail)
 
-        if c.app.config.options.get('TicketMonitoringType') == 'AllTicketChanges':
+        if c.app.config.options.get('TicketMonitoringType') in (
+                'AllTicketChanges', 'AllPublicTicketChanges'):
             monitoring_email = c.app.config.options.get('TicketMonitoringEmail')
-            tmpl_context['tickets'] = ({
+            tmpl_context['tickets'] = [{
                     'original_num': original_ticket_nums[_id],
                     'destination_num': moved_tickets[_id].ticket_num,
                     'summary': moved_tickets[_id].summary
-                } for _id in moved_tickets.keys())
-            mail.update(dict(
-                message_id = h.gen_message_id(),
-                text = tmpl.render(tmpl_context),
-                destinations = [monitoring_email]))
-            mail_tasks.sendmail.post(**mail)
+                } for _id, t in moved_tickets.iteritems()
+                  if (not t.private or
+                      c.app.config.options.get('TicketMonitoringType') ==
+                      'AllTicketChanges')]
+            if len(tmpl_context['tickets']) > 0:
+                mail.update(dict(
+                    message_id = h.gen_message_id(),
+                    text = tmpl.render(tmpl_context),
+                    destinations = [monitoring_email]))
+                mail_tasks.sendmail.post(**mail)
+
         moved_from = '%s/%s' % (c.project.shortname, c.app.config.options.mount_point)
         moved_to = '%s/%s' % (tracker.project.shortname, tracker.options.mount_point)
         text = 'Tickets moved from %s to %s' % (moved_from, moved_to)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/82f675f7/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 1f4acf4..b7e7dd8 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2396,6 +2396,93 @@ class TestBulkMove(TrackerTestController):
         monitoring_email_text = monitoring_email[0].kwargs.text
         assert_equal(admin_email_text, monitoring_email_text)
 
+    @td.with_tool('test2', 'Tickets', 'bugs2')
+    def test_monitoring_email_public_only(self):
+        """Test that private tickets are not included in bulk move
+        notifications if the "public only" option is selected.
+        """
+        self.app.post('/admin/bugs/set_options', params={
+            'TicketMonitoringEmail': 'monitoring@email.com',
+            'TicketMonitoringType': 'AllPublicTicketChanges',
+        })
+        self.new_ticket(summary='test first ticket', status='open')
+        self.new_ticket(summary='test second ticket', status='open', private=True)
+        ThreadLocalORMSession.flush_all()
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        tickets = [
+            tm.Ticket.query.find({'summary': 'test first ticket'}).first(),
+            tm.Ticket.query.find({'summary': 'test second ticket'}).first()]
+        M.MonQTask.query.remove()
+        p = M.Project.query.get(shortname='test2')
+        tracker = p.app_instance('bugs2')
+        self.app.post('/p/test/bugs/move_tickets', {
+                'tracker': str(tracker.config._id),
+                '__ticket_ids': [t._id for t in tickets],
+                '__search': '',
+            })
+        M.MonQTask.run_ready()
+        emails = M.MonQTask.query.find(dict(task_name='allura.tasks.mail_tasks.sendmail')).all()
+        assert_equal(len(emails), 2)  # one for admin and one for monitoring email
+        for email in emails:
+            assert_equal(email.kwargs.subject, '[test:bugs] Mass ticket moving by Test Admin')
+        admin = M.User.by_username('test-admin')
+        admin_email = M.MonQTask.query.find({
+            'task_name': 'allura.tasks.mail_tasks.sendmail',
+            'kwargs.destinations': str(admin._id)
+        }).all()
+        monitoring_email = M.MonQTask.query.find({
+            'task_name': 'allura.tasks.mail_tasks.sendmail',
+            'kwargs.destinations': 'monitoring@email.com'
+        }).all()
+        assert_equal(len(admin_email), 1)
+        assert_equal(len(monitoring_email), 1)
+        admin_email_text = admin_email[0].kwargs.text
+        monitoring_email_text = monitoring_email[0].kwargs.text
+        assert_in('second ticket', admin_email_text)
+        assert_not_in('second ticket', monitoring_email_text)
+
+    @td.with_tool('test2', 'Tickets', 'bugs2')
+    def test_monitoring_email_all_private_moved(self):
+        """Test that no monitoring email is sent if the "public only"
+        option is selected, and only private tickets were moved.
+        """
+        self.app.post('/admin/bugs/set_options', params={
+            'TicketMonitoringEmail': 'monitoring@email.com',
+            'TicketMonitoringType': 'AllPublicTicketChanges',
+        })
+        self.new_ticket(summary='test first ticket', status='open', private=True)
+        self.new_ticket(summary='test second ticket', status='open', private=True)
+        ThreadLocalORMSession.flush_all()
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+        tickets = [
+            tm.Ticket.query.find({'summary': 'test first ticket'}).first(),
+            tm.Ticket.query.find({'summary': 'test second ticket'}).first()]
+        M.MonQTask.query.remove()
+        p = M.Project.query.get(shortname='test2')
+        tracker = p.app_instance('bugs2')
+        self.app.post('/p/test/bugs/move_tickets', {
+                'tracker': str(tracker.config._id),
+                '__ticket_ids': [t._id for t in tickets],
+                '__search': '',
+            })
+        M.MonQTask.run_ready()
+        emails = M.MonQTask.query.find(dict(task_name='allura.tasks.mail_tasks.sendmail')).all()
+        assert_equal(len(emails), 1)  # only admin email sent
+        for email in emails:
+            assert_equal(email.kwargs.subject, '[test:bugs] Mass ticket moving by Test Admin')
+        admin = M.User.by_username('test-admin')
+        admin_email = M.MonQTask.query.find({
+            'task_name': 'allura.tasks.mail_tasks.sendmail',
+            'kwargs.destinations': str(admin._id)
+        }).all()
+        monitoring_email = M.MonQTask.query.find({
+            'task_name': 'allura.tasks.mail_tasks.sendmail',
+            'kwargs.destinations': 'monitoring@email.com'
+        }).all()
+        assert_equal(len(admin_email), 1)
+        assert_equal(len(monitoring_email), 0)
 
 def sidebar_contains(response, text):
     sidebar_menu = response.html.find('div', attrs={'id': 'sidebar'})


Mime
View raw message