3
0
Fork 0

fix: add option for People entry in the Admin menu

This commit is contained in:
Lance Edgar 2024-12-03 21:32:46 -06:00
parent 352afc1e22
commit 5c06353fa3
2 changed files with 55 additions and 30 deletions

View file

@ -142,11 +142,22 @@ class MenuHandler(GenericHandler):
The return value for this method should be a *single* dict, The return value for this method should be a *single* dict,
which will ultimately be one element of the final list of which will ultimately be one element of the final list of
dicts as described in :class:`MenuHandler`. dicts as described in :class:`MenuHandler`.
:param include_people: You can pass this flag to indicate the
admin menu should contain an entry for the "People" view.
""" """
return { items = []
'title': "Admin",
'type': 'menu', if kwargs.get('include_people'):
'items': [ items.extend([
{
'title': "All People",
'route': 'people',
'perm': 'people.list',
},
])
items.extend([
{ {
'title': "Users", 'title': "Users",
'route': 'users', 'route': 'users',
@ -173,7 +184,12 @@ class MenuHandler(GenericHandler):
'route': 'upgrades', 'route': 'upgrades',
'perm': 'upgrades.list', 'perm': 'upgrades.list',
}, },
], ])
return {
'title': "Admin",
'type': 'menu',
'items': items,
} }
############################## ##############################

View file

@ -14,8 +14,17 @@ class TestMenuHandler(WebTestCase):
self.handler = mod.MenuHandler(self.config) self.handler = mod.MenuHandler(self.config)
def test_make_admin_menu(self): def test_make_admin_menu(self):
menus = self.handler.make_admin_menu(self.request)
self.assertIsInstance(menus, dict) # no people entry by default
menu = self.handler.make_admin_menu(self.request)
self.assertIsInstance(menu, dict)
routes = [item.get('route') for item in menu['items']]
self.assertNotIn('people', routes)
# but we can request it
menu = self.handler.make_admin_menu(self.request, include_people=True)
routes = [item.get('route') for item in menu['items']]
self.assertIn('people', routes)
def test_make_menus(self): def test_make_menus(self):
menus = self.handler.make_menus(self.request) menus = self.handler.make_menus(self.request)