incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/50] git commit: [#4339] ticket:237 'POST' handler for moving the ticket
Date Tue, 22 Jan 2013 23:23:18 GMT
[#4339] ticket:237 'POST' handler for moving the ticket


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

Branch: refs/heads/cj/4691
Commit: a615d2757c935be774d7630bb75b38e2e975a7a2
Parents: 8b41346
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Dec 17 12:38:08 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Fri Jan 18 21:53:18 2013 +0000

----------------------------------------------------------------------
 .../forgetracker/tests/functional/test_root.py     |   22 +++++++++++
 ForgeTracker/forgetracker/tracker_main.py          |   28 ++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a615d275/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 ad41056..2a01c0c 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1068,6 +1068,28 @@ class TestFunctionalController(TrackerTestController):
         expected = set(['test/bugs', 'test/bugs2', 'test2/bugs', 'test2/bugs2'])
         assert trackers == expected, trackers
 
+    def test_move_ticket_bad_data(self):
+        self.new_ticket(summary='test')
+        r = self.app.post('/p/test/bugs/1/move').follow()  # empty POST
+        assert 'Select valid tracker' in r, r
+        r = self.app.post('/p/test/bugs/1/move',
+                params={'tracker': 'invalid tracker id'}).follow()
+        assert 'Select valid tracker' in r,r
+        p = M.Project.query.get(shortname='test')
+        tracker = p.app_instance('bugs')
+        r = self.app.post('/p/test/bugs/1/move',
+                params={'tracker': str(tracker.config._id)}).follow()
+        assert 'Ticket already in a selected tracker' in r, r
+
+    def test_move_ticket_access(self):
+        self.new_ticket(summary='test')
+        self.app.get('/p/test/bugs/1/move',
+                extra_environ={'username': 'test-user'},
+                status=403)
+        self.app.post('/p/test/bugs/1/move',
+                extra_environ={'username': 'test-user'},
+                status=403)
+
 
 class TestMilestoneAdmin(TrackerTestController):
     def _post(self, params, **kw):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a615d275/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 626c035..e1db32b 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -15,6 +15,7 @@ from tg.decorators import with_trailing_slash, without_trailing_slash
 from pylons import g, c, request, response
 from formencode import validators
 from bson import ObjectId
+from bson.errors import InvalidId
 from webhelpers import feedgenerator as FG
 
 from ming import schema
@@ -1270,10 +1271,35 @@ class TicketController(BaseController):
     @expose('jinja:forgetracker:templates/tracker/move_ticket.html')
     def move(self, **post_data):
         require_access(self.ticket.app, 'admin')
+        if request.method == 'POST':
+            t_id = str(post_data.pop('tracker', ''))
+            try:
+                t_id = ObjectId(t_id)
+            except InvalidId:
+                t_id = None
+
+            tracker = M.AppConfig.query.get(_id=t_id)
+            if tracker is None:
+                flash('Select valid tracker', 'error')
+                redirect(request.referer)
+
+            if tracker == self.ticket.app.config:
+                flash('Ticket already in a selected tracker', 'info')
+                redirect(request.referer)
+
+            if not has_access(tracker, 'admin')():
+                flash('You should have admin access to destination tracker', 'error')
+                redirect(request.referer)
+
+            # new_ticket = self.ticket.move(tracker)
+            new_ticket = self.ticket
+            flash('Ticket successfully moved')
+            redirect(new_ticket.url())
+
         # collect all 'Tickets' instances in all user project for which his has admin perms
         trackers = []
         projects = c.user.my_projects()
-        projects = ifilter(lambda p: has_access(p, 'admin'), projects)
+        projects = ifilter(lambda p: has_access(p, 'admin')(), projects)
         for p in projects:
             for ac in p.app_configs:
                 if ac.tool_name == 'Tickets':


Mime
View raw message