You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2018/09/04 17:12:24 UTC

allura git commit: [#8224] move/create subscriptions when tickets are moved

Repository: allura
Updated Branches:
  refs/heads/master 280dab086 -> 5738de09c


[#8224] move/create subscriptions when tickets are moved


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

Branch: refs/heads/master
Commit: 5738de09c3c76dcf0bb9144b3ab861752e0547f9
Parents: 280dab0
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Aug 31 13:10:54 2018 -0400
Committer: Kenton Taylor <kt...@slashdotmedia.com>
Committed: Tue Sep 4 17:07:43 2018 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py       | 22 ++++++++-
 .../forgetracker/tests/functional/test_root.py  | 48 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/5738de09/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 3955391..29687d9 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1084,7 +1084,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
         attach_metadata['type'] = 'thumbnail'
         self._move_attach(attachments, attach_metadata, app_config)
 
-        # move ticket's discussion thread, thus all new commnets will go to a
+        # move ticket's discussion thread, thus all new comments will go to a
         # new ticket's feed
         self.discussion_thread.app_config_id = app_config._id
         self.discussion_thread.discussion_id = app_config.discussion_id
@@ -1103,6 +1103,26 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
         ticket = Ticket.query.find(dict(
             app_config_id=app_config._id, ticket_num=self.ticket_num)).first()
 
+        # move individual subscriptions
+        # (may cause an unnecessary subscription if user is already subscribed to destination tool)
+        Mailbox.query.update({
+            'artifact_index_id': ticket.index_id(),  # this is unique
+            'project_id': prior_app.project._id,  # include this to use an index
+        }, {'$set': {
+            'project_id': app_config.project_id,
+            'app_config_id': app_config._id,
+            'artifact_url': ticket.url(),
+            'artifact_title': h.get_first(ticket.index(), 'title'),
+        }}, multi=True)
+        # create subscriptions for 'All artifacts' tool-level subscriptions
+        tool_subs = Mailbox.query.find({'project_id': prior_app.project._id,
+                                        'app_config_id': prior_app.config._id,
+                                        'artifact_index_id': None,
+                                        }).all()
+        for tool_sub in tool_subs:
+            Mailbox.subscribe(user_id=tool_sub.user_id, project_id=app_config.project_id, app_config_id=app_config._id,
+                              artifact=ticket)
+
         # creating MovedTicket to be able to redirect from this url
         moved_ticket = MovedTicket(
             app_config_id=prior_app.config._id, ticket_num=prior_ticket_num,

http://git-wip-us.apache.org/repos/asf/allura/blob/5738de09/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 5e4fff4..adf39c3 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2269,6 +2269,54 @@ class TestFunctionalController(TrackerTestController):
         assert_in('[test:bugs]', n.subject)
         assert_in('[test:bugs]', n.reply_to_address)
 
+    @td.with_tool('test2', 'Tickets', 'features')
+    def test_move_ticket_subscriptions(self):
+        """Subscriptions should move along with the ticket"""
+        self.new_ticket(summary='test ticket')
+        self.new_ticket(summary='another test ticket')
+        p = M.Project.query.get(shortname='test')
+        bugs = p.app_instance('bugs')
+        p2 = M.Project.query.get(shortname='test2')
+        features = p2.app_instance('features')
+        admin = M.User.query.get(username='test-admin')
+        user = M.User.query.get(username='test-user')
+
+        # subscribe test-user to ticket #2
+        self.app.post('/p/test/bugs/2/subscribe', {'subscribe': True},
+                      extra_environ={'username': 'test-user'})
+        assert M.Mailbox.query.get(user_id=user._id,
+                                   project_id=p._id,
+                                   app_config_id=bugs.config._id,
+                                   artifact_title='Ticket 2',
+                                   artifact_url='/p/test/bugs/2/')
+
+        # remove test-admin's tool-wide subscription to test2/features so he can get a new individual one
+        M.Mailbox.query.remove({'user_id': admin._id,
+                                'project_id': p2._id,
+                                'app_config_id': features.config._id,
+                                'artifact_index_id': None,
+                                })
+
+        # move ticket to new project & tool: test/bugs/2 => test2/features/1
+        r = self.app.post('/p/test/bugs/2/move',
+                          params={'tracker': str(features.config._id)}).follow()
+        assert_equal(r.request.path, '/p/test2/features/1/')
+
+        # test-user should be subscribed to it
+        assert M.Mailbox.query.get(user_id=user._id,
+                                   project_id=p2._id,
+                                   app_config_id=features.config._id,
+                                   artifact_title='Ticket 1',
+                                   artifact_url='/p/test2/features/1/'),\
+            "Could not find moved subscription.  User's record is %s" % M.Mailbox.query.get(user_id=user._id)
+        # test-admin (who had a tool-level subscription) should be too
+        assert M.Mailbox.query.get(user_id=admin._id,
+                                   project_id=p2._id,
+                                   app_config_id=features.config._id,
+                                   artifact_title='Ticket 1',
+                                   artifact_url='/p/test2/features/1/'),\
+            "Could not find moved subscription.  Admin's record is %s" % M.Mailbox.query.get(user_id=admin._id)
+
     @td.with_tool('test2', 'Tickets', 'bugs2')
     def test_move_attachment(self):
         file_name = 'neo-icon-set-454545-256x350.png'