incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [40/50] git commit: [#5081] ticket:190 mass edit stores a ticket revision
Date Sun, 04 Nov 2012 19:53:14 GMT
[#5081] ticket:190 mass edit stores a ticket revision


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

Branch: refs/heads/cj/4691
Commit: 1cb2f4f9fd37316ad31cde917fd393ea307e7ad0
Parents: 760828d
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Oct 15 14:33:48 2012 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Mon Oct 22 17:24:54 2012 +0000

----------------------------------------------------------------------
 .../forgetracker/tests/functional/test_root.py     |   39 +++++++++++++
 .../tests/unit/test_root_controller.py             |   16 ++++++
 ForgeTracker/forgetracker/tracker_main.py          |   42 ++++++++++++++-
 3 files changed, 96 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1cb2f4f9/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 22199dc..1ac0f7f 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -155,6 +155,45 @@ class TestFunctionalController(TrackerTestController):
         response = form.submit().follow()
         assert 'Test Admin' in response
 
+    def test_mass_edit(self):
+        ticket_view = self.new_ticket(summary='First Ticket').follow()
+        ticket_view = self.new_ticket(summary='Second Ticket').follow()
+        M.MonQTask.run_ready()
+        first_ticket = tm.Ticket.query.find({
+            'summary': 'First Ticket'}).first()
+        second_ticket = tm.Ticket.query.find({
+            'summary': 'Second Ticket'}).first()
+        r = self.app.get('/p/test/bugs/edit/?q=ticket')
+        self.app.post('/p/test/bugs/update_tickets', {
+                      'selected': first_ticket._id,
+                      '_milestone': '2.0',
+                      })
+        r = self.app.get('/p/test/bugs/1/')
+        assert '<li><strong>Milestone</strong>: 1.0 --&gt; 2.0</li>'
in r
+        r = self.app.get('/p/test/bugs/2/')
+        assert '<li><strong>Milestone</strong>: 1.0 --&gt; 2.0</li>'
not in r
+        self.app.post('/p/test/bugs/update_tickets', {
+                      'selected': '%s,%s' % (
+                          first_ticket._id,
+                          second_ticket._id),
+                      '_milestone': '1.0',
+                      })
+        r = self.app.get('/p/test/bugs/1/')
+        assert '<li><strong>Milestone</strong>: 2.0 --&gt; 1.0</li>'
in r
+        r = self.app.get('/p/test/bugs/2/')
+        assert '<li><strong>Milestone</strong>: 2.0 --&gt; 1.0</li>'
not in r
+
+        self.app.post('/p/test/bugs/update_tickets', {
+                      'selected': '%s,%s' % (
+                          first_ticket._id,
+                          second_ticket._id),
+                      'status': 'accepted',
+                      })
+        r = self.app.get('/p/test/bugs/1/')
+        assert '<li><strong>Status</strong>: open --&gt; accepted</li>'
in r
+        r = self.app.get('/p/test/bugs/2/')
+        assert '<li><strong>Status</strong>: open --&gt; accepted</li>'
in r
+
     def test_private_ticket(self):
         ticket_view = self.new_ticket(summary='Public Ticket').follow()
         assert_true('<label class="simple">Private:</label> No' in ticket_view)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1cb2f4f9/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_root_controller.py b/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
index eb8b2b8..695cada 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_root_controller.py
@@ -7,6 +7,7 @@ from pylons import c
 from forgetracker.tests.unit import TrackerTestWithModel
 from forgetracker.model import Ticket, Globals
 from forgetracker import tracker_main
+import unittest
 
 
 class WithUserAndBugsApp(TrackerTestWithModel):
@@ -82,3 +83,18 @@ def create_ticket(summary, custom_fields):
                     custom_fields=custom_fields)
     session(ticket).flush()
     return ticket
+
+
+class test_change_text(unittest.TestCase):
+    def test_get_label(self):
+        self.assertEqual('Milestone', tracker_main.get_label('_milestone'))
+        self.assertEqual('Ticket Number', tracker_main.get_label('ticket_num'))
+        self.assertEqual('Summary', tracker_main.get_label('summary'))
+        self.assertEqual('Status', tracker_main.get_label('status'))
+        self.assertEqual('Owner', tracker_main.get_label('assigned_to'))
+        self.assertEqual(None, tracker_main.get_label('test'))
+
+    def test_get_change_text(self):
+        self.assertEqual(
+            '- **test**: value2 --> value1\n',
+            tracker_main.get_change_text('test', 'value1', 'value2'))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1cb2f4f9/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 4ea24f8..b42b3ae 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -84,6 +84,26 @@ def _mongo_col_to_solr_col(name):
             if name == field['name']:
                 return field['sortable_name']
 
+
+def get_label(name):
+    for column in mongo_columns():
+        if column['name'] == name:
+            return column['label']
+    if name == 'assigned_to_id':
+        return 'Owner'
+
+
+def get_change_text(name, new_value, old_value):
+    changes = changelog()
+    changes[name] = old_value
+    changes[name] = new_value
+    tpl_fn = pkg_resources.resource_filename(
+        'forgetracker', 'data/ticket_changed_tmpl')
+    return h.render_genshi_plaintext(
+        tpl_fn,
+        changelist=changes.get_changed())
+
+
 class W:
     thread=w.Thread(
         page=None, limit=None, page_size=None, count=None,
@@ -627,11 +647,31 @@ class RootController(BaseController):
             if v: custom_values[k] = v
 
         for ticket in tickets:
+            message = ''
             for k, v in values.iteritems():
+                if k == 'assigned_to_id':
+                    new_user = M.User.query.get(_id=v)
+                    old_user = M.User.query.get(_id=getattr(ticket, k))
+                    if new_user:
+                        message += get_change_text(
+                            get_label(k),
+                            new_user.username,
+                            old_user.username)
+                else:
+                    message += get_change_text(
+                        get_label(k),
+                        v,
+                        getattr(ticket, k))
                 setattr(ticket, k, v)
             for k, v in custom_values.iteritems():
+                message += get_change_text(
+                    get_label(k),
+                    v,
+                    ticket.custom_fields[k])
                 ticket.custom_fields[k] = v
-
+            if message != '':
+                ticket.discussion_thread.post(message)
+                ticket.commit()
         ThreadLocalORMSession.flush_all()
 
 # tickets


Mime
View raw message