allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/5] git commit: [#4943] ticket:246 add default tools to neighborhood-level setting
Date Thu, 31 Jan 2013 16:47:20 GMT
[#4943] ticket:246 add default tools to neighborhood-level setting


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

Branch: refs/heads/db/4943
Commit: b02c5c3a2466090713b37bdba24bb8d43630bd6b
Parents: 1db5fec
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Fri Jan 11 08:32:15 2013 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Jan 30 18:59:09 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py               |   19 +++++++
 .../allura/ext/admin/templates/project_tools.html  |    5 +-
 Allura/allura/lib/widgets/forms.py                 |    1 +
 Allura/allura/model/neighborhood.py                |   14 +++++
 Allura/allura/model/project.py                     |   40 ++++++++++++--
 Allura/allura/public/nf/js/project_tools.js        |    2 +-
 .../widgets/neighborhood_overview_form.html        |    2 +
 .../allura/tests/functional/test_neighborhood.py   |   38 +++++++++++++-
 Allura/allura/tests/model/test_neighborhood.py     |    5 ++
 Allura/allura/tests/model/test_project.py          |   10 ++++
 10 files changed, 126 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 1fec125..0932b2b 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -521,6 +521,25 @@ class NeighborhoodAdminController(object):
         tracking_id = kw.get('tracking_id', '')
         h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                         'update neighborhood tracking_id')
+        default_tools = kw.get('default_tools', '')
+        validate_tools = dict()
+        result = True
+        if default_tools.strip() != '':
+            try:
+                validate_tools = dict((tool.split(':')[0].lower(), tool.split(':')[1]) for
tool in default_tools.replace(' ', '').split(','))
+            except Exception:
+                flash('Default tools "%s" is invalid' % default_tools,'error')
+                result = False
+
+
+        for tool in validate_tools.keys():
+            if not h.re_path_portion.match(tool):
+                flash('Default tools "%s" is invalid' % default_tools,'error')
+                result = False
+        if result:
+            h.log_if_changed(nbhd, 'default_tools', default_tools,
+                             'update neighborhood default tools')
+
         if icon is not None and icon != '':
             if self.neighborhood.icon:
                 self.neighborhood.icon.delete()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/ext/admin/templates/project_tools.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_tools.html b/Allura/allura/ext/admin/templates/project_tools.html
index 5c62cde..857dfee 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -51,7 +51,8 @@
             {% set app = mount['ac'].load()(c.project, mount['ac']) %}
             {% set links = app.admin_menu() %}
             {% set label = mount['ac'].options['mount_label'] if mount['ac'].options['mount_label']
!= 'Tool Name' else mount['ac'].options['mount_point'] %}
-            <div class="fleft">
+
+            <div class="fleft {%if app.tool_label.lower() in app.project.neighborhood.get_default_tools().keys()%}isnt_sorted{%endif%}">
                 <ul class="deck">
                     <li class="tcenter">
                         <span class="tool_title">{{ label }}</span><br />
@@ -62,7 +63,7 @@
                         <a href="{{ link.url }}" class="{{ link.className }}">{{ link.label
}}</a>
                     </li>
                     {% endfor %}
-                    {% if app.uninstallable %}
+                    {% if app.uninstallable and not (app.tool_label.lower() in app.project.neighborhood.get_default_tools().keys())
%}
                     <li>
                       <form method="post" action="update_mounts" id="mounts_edit_2-{{loop.index0}}">
                         <input type="hidden" class="mount_point"

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 0579de6..797fdc0 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -641,6 +641,7 @@ class NeighborhoodOverviewForm(ForgeForm):
         icon = ew.FileField()
         tracking_id = ew.TextField()
         project_list_url = ew.TextField(validator=fev.URL())
+        default_tools = ffw.AutoResizeTextarea()
 
     def from_python(self, value, state):
         if value.features['css'] == "picker":

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/model/neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/neighborhood.py b/Allura/allura/model/neighborhood.py
index 37c2216..b9303ff 100644
--- a/Allura/allura/model/neighborhood.py
+++ b/Allura/allura/model/neighborhood.py
@@ -66,6 +66,7 @@ class Neighborhood(MappedClass):
         max_projects=S.Int,
         css=str,
         google_analytics=bool))
+    default_tools = FieldProperty(str, if_missing='summary:Summary, files:Files, reviews:Reviews,
support:Support')
 
     def parent_security_context(self):
         return None
@@ -236,3 +237,16 @@ class Neighborhood(MappedClass):
 
     def migrate_css_for_picker(self):
         self.css = ""
+
+    def get_default_tools(self):
+        default_tools = self.default_tools.replace(' ', '').split(',')
+        try:
+            return dict((tool.split(':')[0].lower(), tool.split(':')[1]) for tool in default_tools)
+        except Exception:
+            return dict()
+
+    def get_default_tools_order(self):
+        if not len(self.default_tools.strip()):
+            return []
+        default_tools = self.default_tools.replace(' ', '').split(',')
+        return [tool.split(':')[0].lower() for tool in default_tools]

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 2f73ebb..da5e363 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -391,9 +391,13 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         from allura.app import SitemapEntry
         entries = []
 
+        default_tools_order =self.neighborhood.get_default_tools_order()
+        i = len(default_tools_order)
+        self.install_default_tools()
+
         # Set menu mode
-        delta_ordinal = 0
-        max_ordinal = 0
+        delta_ordinal = i
+        max_ordinal = i
 
         if self.is_user_project:
             entries.append({'ordinal': delta_ordinal, 'entry':SitemapEntry('Profile', "%sprofile/"
% self.url(), ui_icon="tool-home")})
@@ -421,7 +425,10 @@ class Project(MappedClass, ActivityNode, ActivityObject):
                     entry = sm.bind_app(app)
                     entry.tool_name = ac.tool_name
                     entry.ui_icon = 'tool-%s' % entry.tool_name.lower()
-                    ordinal = int(ac.options.get('ordinal', 0)) + delta_ordinal
+                    if not self.is_nbhd_project and (entry.tool_name.lower() in default_tools_order):
+                        ordinal = default_tools_order.index(entry.tool_name.lower())
+                    else:
+                        ordinal = int(ac.options.get('ordinal', 0)) + delta_ordinal
                     if ordinal > max_ordinal:
                         max_ordinal = ordinal
                     entries.append({'ordinal':ordinal,'entry':entry})
@@ -433,6 +440,20 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         entries = sorted(entries, key=lambda e: e['ordinal'])
         return [e['entry'] for e in entries]
 
+    def install_default_tools(self):
+        default_tools = self.neighborhood.get_default_tools()
+        default_tools_order =self.neighborhood.get_default_tools_order()
+        installed_tools = [tool.tool_name.lower() for tool in self.app_configs]
+        i = 0
+        if not self.is_nbhd_project:
+            for tool in default_tools_order:
+                if tool not in installed_tools:
+                    try:
+                        self.install_app(tool, tool, default_tools[tool], i)
+                    except Exception:
+                        log.error(tool + ' is not available')
+                i += 1
+
     def grouped_navbar_entries(self):
         """Return a ``allura.app.SitemapEntry`` list suitable for rendering
         the project navbar with tools grouped together by tool type.
@@ -578,14 +599,21 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         '''Returns an array of a projects mounts (tools and sub-projects) in
         toolbar order.'''
         result = []
+        default_tools_order = self.neighborhood.get_default_tools_order()
+        i = len(default_tools_order)
+        self.install_default_tools()
+
         for sub in self.direct_subprojects:
-            result.append({'ordinal':int(sub.ordinal), 'sub':sub, 'rank':1})
+            result.append({'ordinal': int(sub.ordinal + i), 'sub': sub, 'rank': 1})
         for ac in self.app_configs:
             App = g.entry_points['tool'].get(ac.tool_name)
             if include_hidden or App and not App.hidden:
-                ordinal = ac.options.get('ordinal', 0)
+                if not self.is_nbhd_project and (ac.tool_name.lower() in default_tools_order):
+                    ordinal = default_tools_order.index(ac.tool_name.lower())
+                else:
+                    ordinal = int(ac.options.get('ordinal', 0)) + i
                 rank = 0 if ac.options.get('mount_point', None) == 'home' else 1
-                result.append({'ordinal':int(ordinal), 'ac':ac, 'rank':rank})
+                result.append({'ordinal': int(ordinal), 'ac': ac, 'rank': rank})
         return sorted(result, key=lambda e: (e['ordinal'], e['rank']))
 
     def first_mount(self, required_access=None):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/public/nf/js/project_tools.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/project_tools.js b/Allura/allura/public/nf/js/project_tools.js
index 7263434..89fed8e 100644
--- a/Allura/allura/public/nf/js/project_tools.js
+++ b/Allura/allura/public/nf/js/project_tools.js
@@ -55,7 +55,7 @@
         return false;
     });
     // sorting
-    $('#sortable').sortable({items: ".fleft"}).bind( "sortupdate", function (e) {
+    $('#sortable').sortable({items: ".fleft:not(.isnt_sorted)"}).bind( "sortupdate", function
(e) {
         var sortables = $('#sortable .fleft');
         var tools = 0;
         var subs = 0;

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/templates/widgets/neighborhood_overview_form.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/neighborhood_overview_form.html b/Allura/allura/templates/widgets/neighborhood_overview_form.html
index 8e80efd..b105e94 100644
--- a/Allura/allura/templates/widgets/neighborhood_overview_form.html
+++ b/Allura/allura/templates/widgets/neighborhood_overview_form.html
@@ -32,6 +32,8 @@
     {% endif %}
     <label class="grid-4">Project List URL</label>
     <div class="grid-14">{{widget.display_field(widget.fields.project_list_url)}}</div>
+    <label class="grid-4">Default tools (Example: wiki:Wiki,tickets:Tracker)</label>
+    <div class="grid-14">{{widget.display_field(widget.fields.default_tools)}}</div>
     <label class="grid-4">&nbsp;</label>
     <div class="grid-14"><input type="submit" value="Save"/></div>
   </form>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 537731b..786b768 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -80,7 +80,8 @@ class TestNeighborhood(TestController):
             'tracking_id': 'U-123456',
             'homepage': '[Homepage]',
             'project_list_url': 'http://fake.org/project_list',
-            'project_template': '{"name": "template"}'
+            'project_template': '{"name": "template"}',
+            'default_tools': 'wiki:Wiki'
 
         }
         self.app.post('/p/_admin/update', params=params,
@@ -101,6 +102,41 @@ class TestNeighborhood(TestController):
                          '{"name": "template"}')
         assert check_log('update neighborhood tracking_id')
 
+    @td.with_wiki
+    def test_default_tools(self):
+        neighborhood = M.Neighborhood.query.get(name='Projects')
+
+        r = self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                                      default_tools='wiki:Wiki, tickets:Ticket'),
+                          extra_environ=dict(username='root'))
+        assert 'error' not in self.webflash(r)
+        r = self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                                      default_tools='w!iki:Wiki, tickets:Ticket'),
+                          extra_environ=dict(username='root'))
+        assert 'error' in self.webflash(r)
+        assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+
+        r = self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                                      default_tools='wiki:Wiki,'),
+                          extra_environ=dict(username='root'))
+        assert 'error' in self.webflash(r)
+        assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+
+        r = self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                                      default_tools='badname,'),
+                          extra_environ=dict(username='root'))
+        assert 'error' in self.webflash(r)
+        assert_equal(neighborhood.default_tools, 'wiki:Wiki, tickets:Ticket')
+
+        r = self.app.get('/p/test/admin/tools')
+        assert '<div class="fleft isnt_sorted">' in r
+        delete_tool = r.html.find('a', {'class':'mount_delete'})
+        assert_equal(len(delete_tool), 1)
+
     def test_show_title(self):
         r = self.app.get('/adobe/_admin/overview', extra_environ=dict(username='root'))
         neighborhood = M.Neighborhood.query.get(name='Adobe')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/tests/model/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_neighborhood.py b/Allura/allura/tests/model/test_neighborhood.py
index bd69a2d..63cf3ee 100644
--- a/Allura/allura/tests/model/test_neighborhood.py
+++ b/Allura/allura/tests/model/test_neighborhood.py
@@ -66,3 +66,8 @@ def test_neighborhood():
     assert neighborhood.allow_custom_css
     neighborhood.features['css'] = 'custom'
     assert neighborhood.allow_custom_css
+
+    neighborhood.default_tools = 'wiki:Wiki, tickets:Tickets'
+    assert neighborhood.get_default_tools()['wiki'] == 'Wiki'
+    assert neighborhood.get_default_tools()['tickets'] == 'Tickets'
+    assert neighborhood.get_default_tools_order() == ['wiki', 'tickets']

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b02c5c3a/Allura/allura/tests/model/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_project.py b/Allura/allura/tests/model/test_project.py
index b077ad5..df58fb9 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -11,6 +11,7 @@ from allura.lib import helpers as h
 from allura.tests import decorators as td
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.lib.exceptions import ToolError
+from mock import Mock
 
 
 def setUp():
@@ -69,3 +70,12 @@ def test_subproject():
     ThreadLocalORMSession.flush_all()
     sp.delete()
     ThreadLocalORMSession.flush_all()
+
+@td.with_wiki
+def test_default_tools():
+    c.project.neighborhood.default_tools = 'wiki:Wiki, tickets:Ticket'
+    c.project.install_app = Mock()
+    assert c.project.sitemap()[0].label == 'Wiki'
+    assert c.project.install_app.call_args[0][0] == 'tickets'
+    assert c.project.ordered_mounts()[0]['ac'].tool_name == 'Wiki'
+    assert c.project.install_app.call_args[0][0] == 'tickets'


Mime
View raw message