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/11/01 21:11:00 UTC

[3/4] git commit: [#6804] ticket:468 added api to install tools

[#6804] ticket:468 added api to install tools


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

Branch: refs/heads/master
Commit: 343065aa499124a230293a3715dbe278a112600d
Parents: 2ccaae5
Author: coldmind <so...@yandex.ru>
Authored: Tue Oct 29 23:13:30 2013 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Nov 1 19:54:33 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py     | 36 ++++++++++++++++++++++++++++++
 Allura/allura/ext/admin/admin_main.py |  7 ++++--
 2 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/343065aa/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 3953865..0472e79 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -294,3 +294,39 @@ class ProjectRestController(object):
     @expose('json:')
     def index(self, **kw):
         return c.project.__json__()
+
+    @expose('json:')
+    def install_tool(self, tool, mount_point, mount_label, **kw):
+        from allura.ext.admin.admin_main import ProjectAdminController
+        from allura.ext.admin.admin_main import AdminApp
+        controller = ProjectAdminController()
+
+        if not tool or not mount_point or not mount_label:
+            return {'success': False,
+                    'info': 'All arguments required.'
+                    }
+
+        installable_tools = AdminApp.installable_tools_for(c.project)
+        tools_names = [t['name'] for t in installable_tools]
+        if not tool in tools_names:
+            return {'success': False,
+                    'info': 'Incorrect tool name.'
+                    }
+        if not h.re_tool_mount_point.match(tool) or c.project.app_instance(mount_point) is not None:
+            return {'success': False,
+                    'info': 'Incorrect mount point name, or mount point already exists.'
+                    }
+
+        data = {
+            'install': 'install',
+            'ep_name': tool,
+            # TODO:
+            'ordinal': '1',
+            'mount_point': mount_point,
+            'mount_label': mount_label
+        }
+        controller.update_mounts(new=data, called_by_api=True)
+        return {'success': True,
+                'info': 'Tool %s with mount_point %s and mount_label %s was created.'
+                        % (tool, mount_point, mount_label)
+        }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/343065aa/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 d94303d..86fb96e 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -578,7 +578,7 @@ class ProjectAdminController(BaseController):
     @h.vardec
     @expose()
     @require_post()
-    def update_mounts(self, subproject=None, tool=None, new=None, **kw):
+    def update_mounts(self, subproject=None, tool=None, new=None, called_by_api=False, **kw):
         if subproject is None: subproject = []
         if tool is None: tool = []
         for sp in subproject:
@@ -634,7 +634,10 @@ class ProjectAdminController(BaseController):
             flash('%s: %s' % (exc.__class__.__name__, exc.args[0]),
                   'error')
         g.post_event('project_updated')
-        redirect('tools')
+        if not called_by_api:
+            redirect('tools')
+        else:
+            return True
 
     @expose('jinja:allura.ext.admin:templates/export.html')
     def export(self, tools=None):