allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [01/50] git commit: [#2286] ticket:550 set prohibited tools per neighborhood
Date Tue, 25 Mar 2014 14:26:59 GMT
Repository: allura
Updated Branches:
  refs/heads/db/5995 ecba367f3 -> 552fb5678


[#2286] ticket:550 set prohibited tools per neighborhood


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

Branch: refs/heads/db/5995
Commit: 8424c067f01aa77e9a7cb351d8c69df6b5f7042d
Parents: 9ba1ada
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Wed Feb 26 14:11:02 2014 +0400
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Mar 4 21:39:37 2014 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                            |  2 ++
 Allura/allura/controllers/project.py            | 14 ++++++++++++
 Allura/allura/lib/widgets/forms.py              |  1 +
 Allura/allura/model/neighborhood.py             |  7 ++++++
 .../widgets/neighborhood_overview_form.html     |  2 ++
 .../tests/functional/test_neighborhood.py       | 23 +++++++++++++++++++-
 Allura/allura/tests/model/test_neighborhood.py  |  3 +++
 7 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index e5e9287..7746bc9 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -337,6 +337,8 @@ class Application(object):
         :rtype: bool
 
         """
+        if self.config.tool_name.lower() in self.project.neighborhood.get_prohibited_tools():
+            return False
         tools_list = [tool.tool_name.lower()
                       for tool in self.project.app_configs]
         return tools_list.count(self.config.tool_name.lower()) < self.max_instances

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index b83e881..c746c26 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -614,6 +614,20 @@ class NeighborhoodAdminController(object):
         tracking_id = kw.get('tracking_id', '')
         h.log_if_changed(nbhd, 'tracking_id', tracking_id,
                          'update neighborhood tracking_id')
+        prohibited_tools = kw.get('prohibited_tools', '')
+
+        result = True
+        if prohibited_tools.strip() != '':
+            for prohibited_tool in prohibited_tools.split(','):
+                if prohibited_tool.strip() not in g.entry_points['tool']:
+                    flash('Prohibited tools "%s" is invalid' %
+                      prohibited_tool.strip(), 'error')
+                    result = False
+
+        if result:
+            h.log_if_changed(nbhd, 'prohibited_tools', prohibited_tools,
+                            'update neighborhood prohibited tools')
+
         anchored_tools = kw.get('anchored_tools', '')
         validate_tools = dict()
         result = True

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 66b176a..4489a62 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -736,6 +736,7 @@ class NeighborhoodOverviewForm(ForgeForm):
         tracking_id = ew.TextField()
         project_list_url = ew.TextField(validator=fev.URL())
         anchored_tools = ffw.AutoResizeTextarea()
+        prohibited_tools = ffw.AutoResizeTextarea()
 
     def from_python(self, value, state):
         if value.features['css'] == "picker":

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/Allura/allura/model/neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/neighborhood.py b/Allura/allura/model/neighborhood.py
index 7b526d2..f46fc59 100644
--- a/Allura/allura/model/neighborhood.py
+++ b/Allura/allura/model/neighborhood.py
@@ -90,6 +90,7 @@ class Neighborhood(MappedClass):
         css=str,
         google_analytics=bool))
     anchored_tools = FieldProperty(str, if_missing='')
+    prohibited_tools = FieldProperty(str, if_missing='')
 
     def parent_security_context(self):
         return None
@@ -282,3 +283,9 @@ class Neighborhood(MappedClass):
         except Exception:
             log.warning("anchored_tools isn't valid", exc_info=True)
             return dict()
+
+    def get_prohibited_tools(self):
+        prohibited_tools = []
+        if self.prohibited_tools:
+            prohibited_tools = [tool.lower().strip() for tool in self.prohibited_tools.split(',')]
+        return prohibited_tools

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/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 c9d0f9d..0bd3215 100644
--- a/Allura/allura/templates/widgets/neighborhood_overview_form.html
+++ b/Allura/allura/templates/widgets/neighborhood_overview_form.html
@@ -56,6 +56,8 @@
 		Anchored tools will be inserted at the beginning of all projects, and cannot be removed
by a project.
 		If you change the anchored tools, already-inserted tools will stay on all those projects.
 Example: "wiki:Wiki, sometool:The Label"
 	</div>
+    <label class="grid-4">Prohibited tools</label>
+    <div class="grid-14">{{widget.display_field(widget.fields.prohibited_tools)}}</div>
     <label class="grid-4">&nbsp;</label>
     <div class="grid-14"><input type="submit" value="Save"/></div>
     {{lib.csrf_token()}}

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/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 e66445a..8eabb72 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -91,7 +91,8 @@ class TestNeighborhood(TestController):
             'homepage': '[Homepage]',
             'project_list_url': 'http://fake.org/project_list',
             'project_template': '{"name": "template"}',
-            'anchored_tools': 'wiki:Wiki'
+            'anchored_tools': 'wiki:Wiki',
+            'prohibited_tools': 'wiki, tickets'
 
         }
         self.app.post('/p/_admin/update', params=params,
@@ -111,6 +112,26 @@ class TestNeighborhood(TestController):
         assert check_log('change neighborhood project template to '
                          '{"name": "template"}')
         assert check_log('update neighborhood tracking_id')
+        assert check_log('update neighborhood prohibited tools')
+
+    def test_prohibited_tools(self):
+        self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                          prohibited_tools='wiki, tickets'),
+                          extra_environ=dict(username='root'))
+
+        r = self.app.get('/p/_admin/overview', extra_environ=dict(username='root'))
+        assert 'wiki, tickets' in r
+
+        r = self.app.get('/p/test/admin/tools')
+        assert ' <span class="tool_title">Wiki</span><br />' not in r
+        assert ' <span class="tool_title">Tickets</span><br />' not in
r
+
+        r = self.app.post('/p/_admin/update',
+                          params=dict(name='Projects',
+                          prohibited_tools='wiki, test'),
+                          extra_environ=dict(username='root'))
+        assert 'error' in self.webflash(r), self.webflash(r)
 
     @td.with_wiki
     def test_anchored_tools(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/8424c067/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 e5188ff..c18b608 100644
--- a/Allura/allura/tests/model/test_neighborhood.py
+++ b/Allura/allura/tests/model/test_neighborhood.py
@@ -88,3 +88,6 @@ def test_neighborhood():
     neighborhood.anchored_tools = 'wiki:Wiki, tickets:Tickets'
     assert neighborhood.get_anchored_tools()['wiki'] == 'Wiki'
     assert neighborhood.get_anchored_tools()['tickets'] == 'Tickets'
+
+    neighborhood.prohibited_tools = 'wiki, tickets'
+    assert neighborhood.get_prohibited_tools() == ['wiki', 'tickets']


Mime
View raw message