You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/23 17:02:07 UTC
git commit: Fix bugs related to subclassed Apps
Updated Branches:
refs/heads/tv/fix-subclassed-app [created] eaf996775
Fix bugs related to subclassed Apps
* Ensure an App's artifact class can be found even if it's in a different package
* Make static App assets 'inheritable'
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/eaf99677
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/eaf99677
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/eaf99677
Branch: refs/heads/tv/fix-subclassed-app
Commit: eaf996775dc7012fde81367a0d9dd8d996901b32
Parents: 88b2500
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Thu Jan 23 16:01:32 2014 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Jan 23 16:01:32 2014 +0000
----------------------------------------------------------------------
Allura/allura/controllers/site_admin.py | 7 ++++---
Allura/allura/lib/custom_middleware.py | 14 +++++++-------
Allura/allura/lib/helpers.py | 8 ++++++--
Allura/allura/tests/test_helpers.py | 8 ++++----
4 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/eaf99677/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index e6e374c..e2680dd 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -144,11 +144,12 @@ class SiteAdminController(object):
project_id=project._id)
return True
- tool_package = h.get_tool_package(appconf.tool_name)
+ tool_packages = h.get_tool_packages(appconf.tool_name)
classes = set()
for depth, cls in dfs(M.Artifact, build_model_inheritance_graph()):
- if cls.__module__.startswith(tool_package + '.'):
- classes.add(cls)
+ for pkg in tool_packages:
+ if cls.__module__.startswith(pkg + '.'):
+ classes.add(cls)
for cls in classes:
for artifact in cls.query.find({"app_config_id": appconf._id}):
if artifact.url() == urlparse(url).path:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/eaf99677/Allura/allura/lib/custom_middleware.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py
index 3f65e6c..2a07e58 100644
--- a/Allura/allura/lib/custom_middleware.py
+++ b/Allura/allura/lib/custom_middleware.py
@@ -69,13 +69,13 @@ class StaticFilesMiddleware(object):
for prefix, ep in self.directories:
if environ['PATH_INFO'].startswith(prefix):
filename = environ['PATH_INFO'][len(prefix):]
- file_path = pkg_resources.resource_filename(
- ep.module_name, os.path.join(
- 'nf',
- ep.name.lower(),
- filename))
- return fileapp.FileApp(file_path, [
- ('Access-Control-Allow-Origin', '*')])
+ resource_path = os.path.join('nf', ep.name.lower(), filename)
+ resource_cls = ep.load().has_resource(resource_path)
+ if resource_cls:
+ file_path = pkg_resources.resource_filename(
+ resource_cls.__module__, resource_path)
+ return fileapp.FileApp(file_path, [
+ ('Access-Control-Allow-Origin', '*')])
filename = environ['PATH_INFO'][len(self.script_name):]
file_path = pkg_resources.resource_filename(
'allura', os.path.join(
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/eaf99677/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 18cdc53..72c8695 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -788,10 +788,14 @@ def log_if_changed(artifact, attr, new_val, message):
setattr(artifact, attr, new_val)
-def get_tool_package(tool_name):
+def get_tool_packages(tool_name):
"Return package for given tool (e.g. 'forgetracker' for 'tickets')"
+ from allura.app import Application
app = g.entry_points['tool'].get(tool_name.lower())
- return app.__module__.split('.')[0] if app else ''
+ if not app:
+ return []
+ classes = set(app.mro()) - {Application, object}
+ return [cls.__module__.split('.')[0] for cls in classes]
def get_first(d, key):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/eaf99677/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index d89df75..69f5a09 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -271,10 +271,10 @@ def test_log_if_changed():
assert AuditLogMock.logs[0] == 'updated value'
-def test_get_tool_package():
- assert h.get_tool_package('tickets') == 'forgetracker'
- assert h.get_tool_package('Tickets') == 'forgetracker'
- assert h.get_tool_package('wrong_tool') == ''
+def test_get_tool_packages():
+ assert h.get_tool_packages('tickets') == ['forgetracker']
+ assert h.get_tool_packages('Tickets') == ['forgetracker']
+ assert h.get_tool_packages('wrong_tool') == []
def test_get_first():