You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2019/03/18 19:06:55 UTC

[allura] branch master updated (a25329c -> d064082)

This is an automated email from the ASF dual-hosted git repository.

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


    from a25329c  Use correct vars in flash error message, when trying to send too many messages
     new bb964aa  Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links
     new 407f92d  fixup! Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links
     new d064082  Remove unused menus() function

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/app.py                              | 32 ++++++++----
 Allura/allura/model/project.py                    | 63 +++++------------------
 Allura/allura/tests/functional/test_home.py       |  2 +-
 ForgeLink/forgelink/tests/functional/test_root.py | 23 +++++++++
 4 files changed, 59 insertions(+), 61 deletions(-)


[allura] 01/03: Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links

Posted by ke...@apache.org.
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 bb964aac288a0d93e1ba87039a2caf605a6ab626
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Mar 15 11:18:19 2019 -0400

    Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links
---
 Allura/allura/app.py                              | 32 ++++++++++++++++-------
 Allura/allura/model/project.py                    | 23 +++++++---------
 ForgeLink/forgelink/tests/functional/test_root.py | 23 ++++++++++++++++
 3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 07b67d8..b687be0 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -98,9 +98,18 @@ class SitemapEntry(object):
     """
 
     def __init__(self, label, url=None, children=None, className=None,
-                 ui_icon=None, small=None, tool_name=None, matching_urls=None, extra_html_attrs=None):
-        """Create a new SitemapEntry.
-
+                 ui_icon=None, small=None, tool_name=None, matching_urls=None, extra_html_attrs=None, mount_point=None):
+        """
+        Create a new SitemapEntry.
+
+        :param label: the name
+        :param url: the url
+        :param children: optional, list of SitemapEntry objects
+        :param className: optional, HTML class
+        :param tool_name: optional, tool_name (used for top-level menu items)
+        :param matching_urls: list of urls to consider "active" in menu display
+        :param extra_html_attrs: dict to show as HTML attributes
+        :param mount_point: used only for tracking project menu admin options
         """
         self.label = label
         self.className = className
@@ -111,6 +120,7 @@ class SitemapEntry(object):
         self.ui_icon = ui_icon
         self.children = children or []
         self.tool_name = tool_name
+        self.mount_point = mount_point
         self.matching_urls = matching_urls or []
         self.extra_html_attrs = extra_html_attrs or {}
 
@@ -155,13 +165,15 @@ class SitemapEntry(object):
             lbl = lbl(app)
         if url is not None:
             url = basejoin(app.url, url)
-        return SitemapEntry(lbl, url, [
-            ch.bind_app(app) for ch in self.children],
-            className=self.className,
-            ui_icon=self.ui_icon,
-            small=self.small,
-            tool_name=self.tool_name,
-            matching_urls=self.matching_urls)
+        return SitemapEntry(lbl, url,
+                            [ch.bind_app(app) for ch in self.children],
+                            className=self.className,
+                            ui_icon=self.ui_icon,
+                            small=self.small,
+                            tool_name=self.tool_name,
+                            matching_urls=self.matching_urls,
+                            mount_point=app.config.options.mount_point,
+                            )
 
     def extend(self, sitemap_entries):
         """Extend our children with ``sitemap_entries``.
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 8fa6167..8738db1 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -682,32 +682,27 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         anchored_tools = self.neighborhood.get_anchored_tools()
         children = []
 
-        def make_entry(s, mount_point):
+        def make_entry(s):
             entry = dict(name=s.label,
                          url=s.url,
                          icon=s.ui_icon or 'tool-admin',
                          tool_name=s.tool_name or 'sub',
-                         mount_point=mount_point,
+                         mount_point=s.mount_point,
                          is_anchored=s.tool_name in anchored_tools.keys(),
                          )
-            if admin_options and s.tool_name and mount_point:
+            if admin_options and s.tool_name and s.mount_point:
                 try:
-                    entry['admin_options'] = ProjectAdminRestController().admin_options(mount_point)['options']
+                    entry['admin_options'] = ProjectAdminRestController().admin_options(s.mount_point)['options']
                 except exc.HTTPError:
-                    log.debug('Could not get admin_options mount_point for tool: %s', s.url)
+                    log.debug('Could not get admin_options mount_point for tool: %s', s.url, exc_info=True)
             if admin_options and not s.tool_name:
                 entry['admin_options'] = [dict(text='Subproject Admin', href=s.url + 'admin', className=None)]
             return entry
 
         for s in self.grouped_navbar_entries():
+            entry = make_entry(s)
             if s.children:
-                mount_point = None
-            else:
-                _offset = -2 if s.url.endswith("/") else -1
-                mount_point = s.url.split('/')[_offset]
-            entry = make_entry(s, mount_point=mount_point)
-            if s.children:
-                entry['children'] = [make_entry(child, mount_point=child.url.split('/')[-2]) for child in s.children]
+                entry['children'] = [make_entry(child) for child in s.children]
             children.append(entry)
 
         response = dict(grouping_threshold=grouping_threshold, menu=children)
@@ -746,13 +741,13 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                 if tool_name not in grouped_nav:
                     child = deepcopy(e)
                     # change label to be the tool name (type)
-                    e.label = g.entry_points['tool'][
-                        tool_name].tool_label + u' \u25be'
+                    e.label = g.entry_points['tool'][tool_name].tool_label + u' \u25be'
                     # add tool url to list of urls that will match this nav entry
                     # have to do this before changing the url to the list page
                     e.matching_urls.append(e.url)
                     # change url to point to tool list page
                     e.url = self.url() + '_list/' + tool_name
+                    e.mount_point = None
                     e.children.append(child)
                     grouped_nav[tool_name] = e
                 else:
diff --git a/ForgeLink/forgelink/tests/functional/test_root.py b/ForgeLink/forgelink/tests/functional/test_root.py
index c861748..0167fda 100644
--- a/ForgeLink/forgelink/tests/functional/test_root.py
+++ b/ForgeLink/forgelink/tests/functional/test_root.py
@@ -126,3 +126,26 @@ class TestConfigOptions(TestController):
 
         resp = self.app.get('/p/test/admin/')
         assert_in('http://foo.bar/baz', str(resp.html.find(id='top_nav')))
+
+    def _check_configurable(self, admin_nav_data):
+        for menu_item in admin_nav_data['menu']:
+            if menu_item['tool_name'] == 'link':
+                assert_in({'className': 'admin_modal',
+                           'text': 'Options',
+                           'href': '/p/test/admin/link/options'},
+                          menu_item['admin_options'])
+                break
+        else:
+            raise AssertionError(u"Didn't find 'link' tool in {}".format(admin_nav_data['menu']))
+
+    @td.with_link
+    def test_menu_configurable(self):
+        admin_nav_data = self.app.get('/p/test/_nav.json?admin_options=true').json
+        self._check_configurable(admin_nav_data)
+
+        response = self.app.get('/admin/link/options')
+        response.form['url'] = 'http://foo.bar/baz'
+        response.form.submit()
+
+        admin_nav_data = self.app.get('/p/test/_nav.json?admin_options=true').json
+        self._check_configurable(admin_nav_data)


[allura] 02/03: fixup! Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links

Posted by ke...@apache.org.
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 407f92ded68398d5809fd2fce97efeacd23f0230
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Mar 15 12:03:57 2019 -0400

    fixup! Track menu mount_point explicitly, fixes [#8270] regression of unconfigurable external links
---
 Allura/allura/model/project.py              | 5 ++++-
 Allura/allura/tests/functional/test_home.py | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 8738db1..8804ade 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -590,8 +590,9 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                 ordinal = sub.ordinal + delta_ordinal
                 if ordinal > max_ordinal:
                     max_ordinal = ordinal
+                mount_point = sub.shortname.split('/')[-1]
                 entries.append({'ordinal': sub.ordinal + delta_ordinal,
-                               'entry': SitemapEntry(sub.name, sub.url())})
+                                'entry': SitemapEntry(sub.name, sub.url(), mount_point=mount_point)})
 
         for ac in self.app_configs + [a.config for a in new_tools]:
             if per_tool_limit:
@@ -759,6 +760,8 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                     elif len(grouped_nav[tool_name].children) == SITEMAP_PER_TOOL_LIMIT - 1:
                         e.url = self.url() + '_list/' + tool_name
                         e.label = 'More...'
+                        e.mount_point = None
+                        e.extra_html_attrs = {}
                         grouped_nav[tool_name].children.append(e)
         return grouped_nav.values()
 
diff --git a/Allura/allura/tests/functional/test_home.py b/Allura/allura/tests/functional/test_home.py
index e8eb577..0dee4c7 100644
--- a/Allura/allura/tests/functional/test_home.py
+++ b/Allura/allura/tests/functional/test_home.py
@@ -127,7 +127,7 @@ class TestProjectHome(TestController):
         menu = response.json['menu']
         wiki_menu = [m for m in menu if m['tool_name'] == 'wiki'][0]
         assert_equal(len(wiki_menu['children']), 10)
-        assert_in({'url': '/p/test/_list/wiki', 'name': 'More...', 'mount_point': '_list',
+        assert_in({'url': '/p/test/_list/wiki', 'name': 'More...', 'mount_point': None,
                    'icon': 'tool-wiki', 'tool_name': 'wiki', 'is_anchored': False}, wiki_menu['children'])
 
     @td.with_wiki


[allura] 03/03: Remove unused menus() function

Posted by ke...@apache.org.
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 d0640825a25a8e4be9f208ad60fdf1b270a11d64
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Mar 15 12:04:17 2019 -0400

    Remove unused menus() function
---
 Allura/allura/model/project.py | 35 -----------------------------------
 1 file changed, 35 deletions(-)

diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 8804ade..106f776 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -496,41 +496,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         return list(roles)
 
     @classmethod
-    def menus(cls, projects):
-        '''Return a dict[project_id] = sitemap of sitemaps, efficiently'''
-        from allura.app import SitemapEntry
-        pids = [p._id for p in projects]
-        project_index = dict((p._id, p) for p in projects)
-        entry_index = dict((pid, []) for pid in pids)
-        q_subprojects = cls.query.find(dict(
-            parent_id={'$in': pids},
-            deleted=False))
-        for sub in q_subprojects:
-            entry_index[sub.parent_id].append(
-                dict(ordinal=sub.ordinal, entry=SitemapEntry(sub.name, sub.url())))
-        q_app_configs = AppConfig.query.find(dict(
-            project_id={'$in': pids}))
-        for ac in q_app_configs:
-            App = ac.load()
-            project = project_index[ac.project_id]
-            app = App(project, ac)
-            if app.is_visible_to(c.user):
-                for sm in app.main_menu():
-                    entry = sm.bind_app(app)
-                    entry.ui_icon = 'tool-%s' % ac.tool_name
-                    ordinal = ac.options.get('ordinal', 0)
-                    entry_index[ac.project_id].append(
-                        {'ordinal': ordinal, 'entry': entry})
-
-        sitemaps = dict((pid, []) for pid in pids)
-        for pid, entries in entry_index.iteritems():
-            entries.sort(key=lambda e: e['ordinal'])
-            sitemap = sitemaps[pid]
-            for e in entries:
-                sitemap.append(e['entry'])
-        return sitemaps
-
-    @classmethod
     def icon_urls(cls, projects):
         '''Return a dict[project_id] = icon_url, efficiently'''
         project_index = dict((p._id, p) for p in projects)