incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [32/50] [abbrv] git commit: [#2502] ticket:300 Group changes by user, based on his subscriptions
Date Tue, 23 Apr 2013 16:42:36 GMT
[#2502] ticket:300 Group changes by user, based on his subscriptions


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

Branch: refs/heads/cj/5120
Commit: e802ccea1822cf597de8dfa487f7e7e29b53ff7a
Parents: bc4fc9f
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Apr 12 10:57:29 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Apr 22 19:40:26 2013 +0000

----------------------------------------------------------------------
 .../forgetracker/tests/functional/test_root.py     |   40 +++++++++++++++
 ForgeTracker/forgetracker/tracker_main.py          |   24 +++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e802ccea/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 b5d87a0..9ccc963 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -33,6 +33,7 @@ from alluratest.controller import TestController
 from allura import model as M
 from forgewiki import model as wm
 from forgetracker import model as tm
+from forgetracker.tracker_main import filtered_by_subscription
 
 from allura.lib.security import has_access
 from allura.lib import helpers as h
@@ -1165,6 +1166,45 @@ class TestFunctionalController(TrackerTestController):
                            third_ticket_changes])
         assert_equal(email, admin_email.kwargs.text)
 
+    def test_filtered_by_subscription(self):
+        self.new_ticket(summary='test first ticket', status='open')
+        self.new_ticket(summary='test second ticket', status='open')
+        self.new_ticket(summary='test third ticket', status='open')
+        tickets = []
+        users = []
+        tickets.append(tm.Ticket.query.get(summary='test first ticket'))
+        tickets.append(tm.Ticket.query.get(summary='test second ticket'))
+        tickets.append(tm.Ticket.query.get(summary='test third ticket'))
+        users.append(M.User.by_username('test-user-0'))
+        users.append(M.User.by_username('test-user-1'))
+        users.append(M.User.by_username('test-user-2'))
+        admin = M.User.by_username('test-admin')
+        tickets[0].subscribe(user=users[0])
+        tickets[1].subscribe(user=users[1])
+        tickets[2].subscribe(user=users[2])
+        ThreadLocalORMSession.flush_all()
+        M.MonQTask.run_ready()
+        ThreadLocalORMSession.flush_all()
+
+        # Pretend we're changing first and second ticket.
+        # Then we should notify test-user-0, test-user-1 and admin.
+        # test-user-2 shoudn't be notified
+        # (he has subscription to third ticket, but it didn't change).
+        # test-user-0 should see changes only for first ticket.
+        # test-user-1 - only for second.
+        # admin - for both (since he has tool subscription).
+        changes = {
+            tickets[0]._id: {'ticket': tickets[0], 'changes': 'Ticket 1 changes'},
+            tickets[1]._id: {'ticket': tickets[1], 'changes': 'Ticket 2 changes'},
+        }
+        filtered_changes = filtered_by_subscription(changes)
+        filtered_users = [uid for uid, data in filtered_changes.iteritems()]
+        assert_equal(sorted(filtered_users), sorted([u._id for u in users[:-1] + [admin]]))
+        ticket_ids = [t._id for t in tickets]
+        assert_equal(filtered_changes[users[0]._id], ticket_ids[0:1])
+        assert_equal(filtered_changes[users[1]._id], ticket_ids[1:2])
+        assert_equal(sorted(filtered_changes[admin._id]), sorted(ticket_ids[:-1]))
+
     def test_vote(self):
         r = self.new_ticket(summary='test vote').follow()
         assert_false(r.html.find('div', {'id': 'vote'}))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e802ccea/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 102a544..bb0fe7b 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1150,6 +1150,30 @@ class changelog(object):
         return t
 
 
+def filtered_by_subscription(tickets, project_id=None, app_config_id=None):
+    p_id = project_id if project_id else c.project._id
+    ac_id = app_config_id if app_config_id else c.app.config._id
+    ticket_ids = tickets.keys()
+    users = M.Mailbox.query.find(dict(project_id=p_id, app_config_id=ac_id))
+    users = [u.user_id for u in users]
+    filtered = {}
+    for uid in users:
+        params = dict(
+            user_id=uid,
+            project_id=p_id,
+            app_config_id=ac_id)
+        if M.Mailbox.subscribed(**params):
+            filtered[uid] = ticket_ids  # subscribed to entire tool, will see all changes
+            continue
+        for t_id, data in tickets.iteritems():
+            params.update({'artifact': data['ticket']})
+            if M.Mailbox.subscribed(**params):
+                if filtered.get('uid') is None:
+                    filtered[uid] = []
+                filtered[uid].append(t_id)
+    return filtered
+
+
 class TicketController(BaseController):
 
     def __init__(self, ticket_num=None):


Mime
View raw message