allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kentontay...@apache.org
Subject [allura] 05/12: [#8273] TG 2.3.0: root controller is only init'd once, so move dynamic code to _lookup; basetestroot now gives precedence to full root-based urls
Date Tue, 09 Apr 2019 17:02:40 GMT
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 311c0d544b73217fb0ba845cea0811daebb05209
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Thu Mar 21 17:57:25 2019 -0400

    [#8273] TG 2.3.0: root controller is only init'd once, so move dynamic code to _lookup;
basetestroot now gives precedence to full root-based urls
---
 Allura/allura/controllers/basetest_project_root.py | 41 ++++++++++++----------
 Allura/allura/controllers/root.py                  | 20 +++++++----
 Allura/allura/controllers/site_admin.py            |  3 +-
 Allura/allura/model/neighborhood.py                |  5 ---
 .../allura/tests/functional/test_neighborhood.py   |  4 +--
 Allura/allura/tests/functional/test_search.py      |  8 ++---
 6 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index 0a5047d..4d5cad3 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -42,10 +42,9 @@ log = logging.getLogger(__name__)
 
 
 class BasetestProjectRootController(WsgiDispatchController, ProjectController):
-    '''Root controller for testing -- it behaves just like a
-    ProjectController for test/ except that all tools are mounted,
-    on-demand, at the mount point that is the same as their entry point
-    name.
+    '''Root controller for testing -- it behaves just like the RootController
+    plus acts as shorthand for the ProjectController at /p/test/ plus all tools are mounted,
+    on-demand, at the mount point that is the same as their entry point name.
 
     Also, the test-admin is perpetually logged in here.
 
@@ -58,20 +57,20 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
     '''
 
     def __init__(self):
-        for n in M.Neighborhood.query.find():
-            if n.url_prefix.startswith('//'):
-                continue
-            n.bind_controller(self)
-            if n.url_prefix == '/p/':
-                self.p_nbhd = n
-
-        proxy_root = RootController()
+        self.p_nbhd = M.Neighborhood.query.get(url_prefix='/p/')
+        assert self.p_nbhd
+
         self.dispatch = DispatchTest()
         self.security = SecurityTests()
-        for attr in ('index', 'browse', 'auth', 'nf', 'error', 'categories', 'neighborhood',
'dashboard'):
-            setattr(self, attr, getattr(proxy_root, attr))
-        self.gsearch = proxy_root.search
-        self.rest = RestController()
+
+        # proxy root controller paths
+        self.real_root_controller = RootController()
+        for attr in dir(self.real_root_controller):
+            if not attr.startswith('_'):
+                setattr(self, attr, getattr(self.real_root_controller, attr))
+
+        # neighborhoods & projects handled in _lookup
+
         super(BasetestProjectRootController, self).__init__()
 
     def _setup_request(self):
@@ -90,8 +89,14 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
 
     @expose()
     def _lookup(self, name, *remainder):
-        if not h.re_project_name.match(name):
-            raise exc.HTTPNotFound, name
+        # first try a neighborhood path through the real root controller
+        try:
+            return self.real_root_controller._lookup(name, *remainder)
+        except exc.HTTPNotFound:
+            pass
+
+        # magic shorthand helper lookups so self.app.get('/wiki') instantiates a wiki and
calls /p/test/wiki controller
+
         subproject = M.Project.query.get(
             shortname=c.project.shortname + '/' + name,
             neighborhood_id=self.p_nbhd._id)
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index 7a6bee2..c4e1bd4 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -26,11 +26,13 @@ from tg.flash import TGFlash
 from tg import tmpl_context as c
 from tg import response
 from paste.deploy.converters import asbool
+from webob import exc
 
 from allura.app import SitemapEntry
 from allura.lib.base import WsgiDispatchController
 from allura.lib import plugin
 from allura.controllers.error import ErrorController
+from allura.controllers.project import NeighborhoodController
 from allura import model as M
 from allura.lib.widgets import project_list as plw
 from allura.ext.personal_dashboard.dashboard_main import DashboardController
@@ -77,16 +79,20 @@ class RootController(WsgiDispatchController):
     rest = RestController()
     categories = TroveCategoryController()
     dashboard = DashboardController()
-
+    browse = ProjectBrowseController()
+    
     def __init__(self):
-        n_url_prefix = '/%s/' % request.path.split('/')[1]
+        super(RootController, self).__init__()
+        self.nf.admin = SiteAdminController()
+        
+    @expose()
+    def _lookup(self, nbhd_mount, *remainder):
+        n_url_prefix = '/%s/' % nbhd_mount
         n = self._lookup_neighborhood(n_url_prefix)
         if n and not n.url_prefix.startswith('//'):
-            n.bind_controller(self)
-        self.browse = ProjectBrowseController()
-        self.nf.admin = SiteAdminController()
-
-        super(RootController, self).__init__()
+            return NeighborhoodController(n), remainder
+        else:
+            raise exc.HTTPNotFound
 
     def _lookup_neighborhood(self, url_prefix):
         n = M.Neighborhood.query.get(url_prefix=url_prefix)
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index d173800..76c09a0 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -65,7 +65,6 @@ class SiteAdminController(object):
 
     def __init__(self):
         self.task_manager = TaskManagerController()
-        c.site_admin_sidebar_menu = self.sidebar_menu()
         self.user = AdminUserDetailsController()
         self.delete_projects = DeleteProjectsController()
         self.site_notifications = SiteNotificationController()
@@ -75,6 +74,8 @@ class SiteAdminController(object):
                             neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
             require_access(c.project, 'admin')
 
+        c.site_admin_sidebar_menu = self.sidebar_menu()
+
     @expose()
     def _lookup(self, name, *remainder):
         for ep_name in sorted(g.entry_points['site_admin'].keys()):
diff --git a/Allura/allura/model/neighborhood.py b/Allura/allura/model/neighborhood.py
index 789f5ea..38356bf 100644
--- a/Allura/allura/model/neighborhood.py
+++ b/Allura/allura/model/neighborhood.py
@@ -152,11 +152,6 @@ class Neighborhood(MappedClass):
         return provider.register_project(
             self, shortname, project_name, user or getattr(c, 'user', None), user_project,
private_project, apps)
 
-    def bind_controller(self, controller):
-        from allura.controllers.project import NeighborhoodController
-        controller_attr = self.url_prefix[1:-1]
-        setattr(controller, controller_attr, NeighborhoodController(self))
-
     def get_custom_css(self):
         if self.allow_custom_css:
             return self.css
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index dd22da4..211b745 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -290,10 +290,10 @@ class TestNeighborhood(TestController):
         r = self.app.post('/adobe/_admin/update',
                           params=dict(name='Adobe', css='',
                                       homepage='# MozQ1', tracking_id='U-123456'),
-                          extra_environ=dict(username='root'))
+                          extra_environ=dict(username='root'), status=302)
         r = self.app.post('/adobe/adobe-1/admin/update',
                           params=dict(tracking_id='U-654321'),
-                          extra_environ=dict(username='root'))
+                          extra_environ=dict(username='root'), status=302)
         r = self.app.get('/adobe/adobe-1/admin/overview',
                          extra_environ=dict(username='root'))
         assert "_add_tracking('nbhd', 'U-123456');" in r, r
diff --git a/Allura/allura/tests/functional/test_search.py b/Allura/allura/tests/functional/test_search.py
index 374d5f3..118c0f0 100644
--- a/Allura/allura/tests/functional/test_search.py
+++ b/Allura/allura/tests/functional/test_search.py
@@ -23,11 +23,11 @@ class TestSearch(TestController):
 
     @patch('allura.lib.search.search')
     def test_global_search_controller(self, search):
-        self.app.get('/gsearch/')
+        self.app.get('/search/')
         assert not search.called, search.called
-        self.app.get('/gsearch/', params=dict(q='Root'))
+        self.app.get('/search/', params=dict(q='Root'))
         assert search.called, search.called
 
     def test_project_search_controller(self):
-        self.app.get('/search/')
-        self.app.get('/search/', params=dict(q='Root'))
+        self.app.get('/p/test/search/')
+        self.app.get('/p/test/search/', params=dict(q='Root'))


Mime
View raw message