You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/05/24 19:04:42 UTC
[06/50] git commit: [#6219] Add public-only options for tracker email
monitoring
[#6219] Add public-only options for tracker email monitoring
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d786c637
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d786c637
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d786c637
Branch: refs/heads/db/6255
Commit: d786c63781f86b2c02e4d9baaeab448061a33771
Parents: e34ca49
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue May 21 19:43:40 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue May 21 19:43:40 2013 +0000
----------------------------------------------------------------------
ForgeTracker/forgetracker/model/ticket.py | 9 +-
.../forgetracker/tests/functional/test_root.py | 123 +++++++++++++--
ForgeTracker/forgetracker/tracker_main.py | 29 ++--
ForgeTracker/forgetracker/widgets/admin.py | 5 +-
4 files changed, 141 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d786c637/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 7bd2386..fa470be 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -461,7 +461,10 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
@property
def notify_post(self):
- return c.app.config.options.get('TicketMonitoringType') == 'AllTicketChanges'
+ monitoring_type = c.app.config.options.get('TicketMonitoringType')
+ return monitoring_type == 'AllTicketChanges' or (
+ monitoring_type == 'AllPublicTicketChanges' and
+ not self.private)
def get_custom_user(self, custom_user_field_name):
fld = None
@@ -549,7 +552,9 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
Thread.new(discussion_id=self.app_config.discussion_id,
ref_id=self.index_id())
n = Notification.post(artifact=self, topic='metadata', text=description, subject=subject)
- if monitoring_email and n:
+ if monitoring_email and n and (not self.private or
+ self.app.config.options.get('TicketMonitoringType') in (
+ 'NewTicketsOnly', 'AllTicketChanges')):
n.send_simple(monitoring_email)
Feed.post(
self,
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d786c637/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 2bd1747..8d2deb0 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -26,7 +26,7 @@ import allura
from mock import patch
from nose.tools import assert_true, assert_false, assert_equal, assert_in
-from nose.tools import assert_raises
+from nose.tools import assert_raises, assert_not_in
from formencode.variabledecode import variable_encode
from alluratest.controller import TestController
@@ -1227,7 +1227,7 @@ class TestFunctionalController(TrackerTestController):
'TicketMonitoringEmail': 'monitoring@email.com',
'TicketMonitoringType': 'AllTicketChanges',
})
- self.new_ticket(summary='test first ticket', status='open', _milestone='2.0')
+ self.new_ticket(summary='test first ticket', status='open', _milestone='2.0', private=True)
ThreadLocalORMSession.flush_all()
M.MonQTask.run_ready()
ThreadLocalORMSession.flush_all()
@@ -1257,6 +1257,82 @@ class TestFunctionalController(TrackerTestController):
monitoring_email_text = monitoring_email[0].kwargs.text
assert_equal(admin_email_text, monitoring_email_text)
+ def test_bulk_edit_notifications_monitoring_email_public_only(self):
+ """Test that private tickets are not included in bulk edit
+ 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', _milestone='2.0')
+ 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(dict(status='open')).all()
+ M.MonQTask.query.remove()
+ self.app.post('/p/test/bugs/update_tickets', {
+ '__search': '',
+ '__ticket_ids': [t._id for t in tickets],
+ 'status': 'accepted'})
+ 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 edit changes 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)
+
+ def test_bulk_edit_monitoring_email_all_private_edits(self):
+ """Test that no monitoring email is sent if the "public only"
+ option is selected, and only private tickets were updated.
+ """
+ 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(dict(status='open')).all()
+ M.MonQTask.query.remove()
+ self.app.post('/p/test/bugs/update_tickets', {
+ '__search': '',
+ '__ticket_ids': [t._id for t in tickets],
+ 'status': 'accepted'})
+ 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 edit changes 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 test_filtered_by_subscription(self):
self.new_ticket(summary='test first ticket', status='open')
self.new_ticket(summary='test second ticket', status='open')
@@ -1873,23 +1949,28 @@ class TestEmailMonitoring(TrackerTestController):
@patch('forgetracker.model.ticket.Notification.send_simple')
def test_notifications_new(self, send_simple):
self._set_options('NewTicketsOnly')
- self.new_ticket(summary='test')
- self.app.post('/bugs/1/update_ticket',{
- 'summary':'test',
- 'description':'update',
- })
+ self.new_ticket(summary='test', private=True)
send_simple.assert_called_once_with(self.test_email)
+ @patch('forgetracker.model.ticket.Notification.send_simple')
+ def test_notifications_new_public_only(self, send_simple):
+ """Test that notification not sent for new private ticket
+ if "public only" option selected.
+ """
+ self._set_options('NewPublicTicketsOnly')
+ self.new_ticket(summary='test', private=True)
+ assert not send_simple.called
+
@patch('forgetracker.tracker_main.M.Notification.send_simple')
def test_notifications_all(self, send_simple):
self._set_options()
self.new_ticket(summary='test')
send_simple.assert_called_once_with(self.test_email)
send_simple.reset_mock()
- response = self.app.post(
- '/bugs/1/update_ticket',
- {'summary': 'test',
- 'description': 'update'})
+ response = self.app.post('/bugs/1/update_ticket', {
+ 'summary': 'test',
+ 'description': 'update',
+ 'private': '1'})
assert send_simple.call_count == 1, send_simple.call_count
send_simple.assert_called_with(self.test_email)
send_simple.reset_mock()
@@ -1906,6 +1987,25 @@ class TestEmailMonitoring(TrackerTestController):
assert send_simple.call_count == 1, send_simple.call_count
send_simple.assert_called_with(self.test_email)
+ @patch('forgetracker.tracker_main.M.Notification.send_simple')
+ def test_notifications_all_public_only(self, send_simple):
+ """Test that notifications are not sent for private tickets
+ if "public only" option selected.
+ """
+ self._set_options('AllPublicTicketChanges')
+ self.new_ticket(summary='test')
+ send_simple.assert_called_once_with(self.test_email)
+ send_simple.reset_mock()
+ self.app.post('/bugs/1/update_ticket', {
+ 'summary': 'test',
+ 'description': 'update 1'})
+ send_simple.assert_called_once_with(self.test_email)
+ send_simple.reset_mock()
+ self.app.post('/bugs/1/update_ticket', {
+ 'summary': 'test',
+ 'description': 'update 2',
+ 'private': '1'})
+ assert not send_simple.called
@patch('forgetracker.tracker_main.M.Notification.send_simple')
def test_notifications_off(self, send_simple):
@@ -1920,6 +2020,7 @@ class TestEmailMonitoring(TrackerTestController):
self.new_ticket(summary='test')
assert send_simple.call_count == 0, send_simple.call_count
+
class TestCustomUserField(TrackerTestController):
def setUp(self):
super(TestCustomUserField, self).setUp()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d786c637/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index f76cf74..17f3b6b 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -172,7 +172,8 @@ class ForgeTrackerApp(Application):
ConfigOption('EnableVoting', bool, False),
ConfigOption('TicketMonitoringEmail', str, ''),
ConfigOption('TicketMonitoringType',
- schema.OneOf('NewTicketsOnly', 'AllTicketChanges'), None)
+ schema.OneOf('NewTicketsOnly', 'AllTicketChanges',
+ 'NewPublicTicketsOnly', 'AllPublicTicketChanges'), None)
]
searchable=True
tool_label='Tickets'
@@ -862,17 +863,23 @@ class RootController(BaseController, FeedController):
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')
- def all_changes():
- for t_id in changed_tickets.keys():
- yield (changed_tickets[t_id], changes[t_id])
- tmpl_context['data'].update({'changes': all_changes()})
- mail.update(dict(
- message_id = h.gen_message_id(),
- text = tmpl.render(tmpl_context),
- destinations = [monitoring_email]))
- mail_tasks.sendmail.post(**mail)
+ visible_changes = []
+ for t_id, t in changed_tickets.items():
+ if (not t.private or
+ c.app.config.options.get('TicketMonitoringType') ==
+ 'AllTicketChanges'):
+ visible_changes.append(
+ (changed_tickets[t_id], changes[t_id]))
+ if visible_changes:
+ tmpl_context['data'].update({'changes': visible_changes})
+ mail.update(dict(
+ message_id = h.gen_message_id(),
+ text = tmpl.render(tmpl_context),
+ destinations = [monitoring_email]))
+ mail_tasks.sendmail.post(**mail)
c.app.globals.invalidate_bin_counts()
ThreadLocalORMSession.flush_all()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d786c637/ForgeTracker/forgetracker/widgets/admin.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/admin.py b/ForgeTracker/forgetracker/widgets/admin.py
index 1e13d2f..09bc443 100644
--- a/ForgeTracker/forgetracker/widgets/admin.py
+++ b/ForgeTracker/forgetracker/widgets/admin.py
@@ -44,7 +44,10 @@ class OptionsAdmin(ff.AdminForm):
grid_width='7',
options=[
ew.Option(py_value='NewTicketsOnly', label='New tickets only'),
- ew.Option(py_value='AllTicketChanges', label='All ticket changes')]),
+ ew.Option(py_value='NewPublicTicketsOnly', label='New public tickets only'),
+ ew.Option(py_value='AllTicketChanges', label='All ticket changes'),
+ ew.Option(py_value='AllPublicTicketChanges', label='All public ticket changes'),
+ ]),
ffw.MarkdownEdit(
name='TicketHelpNew',
label='Help text to display on new ticket page',