You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/12/16 18:09:53 UTC
[14/36] git commit: [#6958] Added order param to tool install API
[#6958] Added order param to tool install API
Signed-off-by: Cory Johns <ad...@users.sf.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/56e0caf8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/56e0caf8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/56e0caf8
Branch: refs/heads/cj/6821
Commit: 56e0caf8deeec66b0a98577f76671a5d0bbc73c1
Parents: 4d30024
Author: Cory Johns <ad...@users.sf.net>
Authored: Mon Dec 9 20:39:44 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Dec 12 04:32:53 2013 +0000
----------------------------------------------------------------------
Allura/allura/ext/admin/admin_main.py | 45 +++++++++++++++++++++--
Allura/allura/tests/functional/test_admin.py | 45 +++++++++++++++++++++++
2 files changed, 87 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56e0caf8/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index f559da9..88eb0cc 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -21,6 +21,7 @@ from datetime import datetime
from urlparse import urlparse
import json
import os
+from operator import itemgetter
import pkg_resources
from pylons import tmpl_context as c, app_globals as g
@@ -725,7 +726,7 @@ class ProjectAdminRestController(BaseController):
@expose('json:')
@require_post()
- def install_tool(self, tool=None, mount_point=None, mount_label=None, **kw):
+ def install_tool(self, tool=None, mount_point=None, mount_label=None, order=None, **kw):
"""API for installing tools in current project.
Requires a valid tool, mount point and mount label names.
@@ -740,7 +741,8 @@ class ProjectAdminRestController(BaseController):
{
'tool': 'tickets',
'mount_point': 'mountpoint',
- 'mount_label': 'mountlabel'
+ 'mount_label': 'mountlabel',
+ 'order': 'first|last|alpha_tool'
}
Example output (in successful case)::
@@ -769,10 +771,47 @@ class ProjectAdminRestController(BaseController):
'info': 'Incorrect mount point name, or mount point already exists.'
}
+ if order is None:
+ order = 'last'
+ mounts = [{
+ 'ordinal': ac.options.ordinal,
+ 'label': ac.options.mount_label,
+ 'mount': ac.options.mount_point,
+ 'type': ac.tool_name.lower(),
+ } for ac in c.project.app_configs]
+ subs = {p.shortname: p for p in M.Project.query.find({'parent_id': c.project._id})}
+ for sub in subs.values():
+ mounts.append({
+ 'ordinal': sub.ordinal,
+ 'mount': sub.shortname,
+ 'type': 'sub-project',
+ })
+ mounts.sort(key=itemgetter('ordinal'))
+ if order == 'first':
+ ordinal = 0
+ elif order == 'last':
+ ordinal = len(mounts)
+ elif order == 'alpha_tool':
+ tool = tool.lower()
+ for i, mount in enumerate(mounts):
+ if mount['type'] == tool and mount['label'] > mount_label:
+ ordinal = i
+ break
+ else:
+ ordinal = len(mounts)
+ mounts.insert(ordinal, {'ordinal': ordinal, 'type': 'new'})
+ for i, mount in enumerate(mounts):
+ if mount['type'] == 'new':
+ pass
+ elif mount['type'] == 'sub-project':
+ subs[mount['mount']].ordinal = i
+ else:
+ c.project.app_config(mount['mount']).options.ordinal = i
+
data = {
'install': 'install',
'ep_name': tool,
- 'ordinal': len(installable_tools) + len(c.project.direct_subprojects),
+ 'ordinal': ordinal,
'mount_point': mount_point,
'mount_label': mount_label
}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56e0caf8/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 6953dfe..d4e5192 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -1123,3 +1123,48 @@ class TestRestInstallTool(TestRestApiBase):
params=data)
assert_equals(r.status, '401 Unauthorized')
+ def test_order(self):
+ def get_labels():
+ project = M.Project.query.get(shortname='test')
+ labels = []
+ for mount in project.ordered_mounts(include_hidden=True):
+ if 'ac' in mount:
+ labels.append(mount['ac'].options.mount_label)
+ elif 'sub' in mount:
+ labels.append(mount['sub'].name)
+ return labels
+ assert_equals(get_labels(), ['Admin', 'Search', 'Activity', 'A Subproject'])
+
+ data = [
+ {
+ 'tool': 'tickets',
+ 'mount_point': 'ticketsmount1',
+ 'mount_label': 'ta',
+ },
+ {
+ 'tool': 'tickets',
+ 'mount_point': 'ticketsmount2',
+ 'mount_label': 'tc',
+ 'order': 'last'
+ },
+ {
+ 'tool': 'tickets',
+ 'mount_point': 'ticketsmount3',
+ 'mount_label': 'tb',
+ 'order': 'alpha_tool'
+ },
+ {
+ 'tool': 'tickets',
+ 'mount_point': 'ticketsmount4',
+ 'mount_label': 't1',
+ 'order': 'first'
+ },
+ ]
+ for datum in data:
+ r = self.api_post('/rest/p/test/admin/install_tool/', **datum)
+ assert_equals(r.json['success'], True)
+ assert_equals(r.json['info'],
+ 'Tool %s with mount_point %s and mount_label %s was created.'
+ % (datum['tool'], datum['mount_point'], datum['mount_label']))
+
+ assert_equals(get_labels(), ['t1', 'Admin', 'Search', 'Activity', 'A Subproject', 'ta', 'tb', 'tc'])