From 5c06353fa369e58dbd55ff52c612a7ddf256c342 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 3 Dec 2024 21:32:46 -0600 Subject: [PATCH] fix: add option for People entry in the Admin menu --- src/wuttaweb/menus.py | 72 ++++++++++++++++++++++++++----------------- tests/test_menus.py | 13 ++++++-- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/src/wuttaweb/menus.py b/src/wuttaweb/menus.py index c1c47dc..8e824be 100644 --- a/src/wuttaweb/menus.py +++ b/src/wuttaweb/menus.py @@ -142,38 +142,54 @@ class MenuHandler(GenericHandler): The return value for this method should be a *single* dict, which will ultimately be one element of the final list of 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. """ + items = [] + + if kwargs.get('include_people'): + items.extend([ + { + 'title': "All People", + 'route': 'people', + 'perm': 'people.list', + }, + ]) + + items.extend([ + { + 'title': "Users", + 'route': 'users', + 'perm': 'users.list', + }, + { + 'title': "Roles", + 'route': 'roles', + 'perm': 'roles.list', + }, + {'type': 'sep'}, + { + 'title': "App Info", + 'route': 'appinfo', + 'perm': 'appinfo.list', + }, + { + 'title': "Raw Settings", + 'route': 'settings', + 'perm': 'settings.list', + }, + { + 'title': "Upgrades", + 'route': 'upgrades', + 'perm': 'upgrades.list', + }, + ]) + return { 'title': "Admin", 'type': 'menu', - 'items': [ - { - 'title': "Users", - 'route': 'users', - 'perm': 'users.list', - }, - { - 'title': "Roles", - 'route': 'roles', - 'perm': 'roles.list', - }, - {'type': 'sep'}, - { - 'title': "App Info", - 'route': 'appinfo', - 'perm': 'appinfo.list', - }, - { - 'title': "Raw Settings", - 'route': 'settings', - 'perm': 'settings.list', - }, - { - 'title': "Upgrades", - 'route': 'upgrades', - 'perm': 'upgrades.list', - }, - ], + 'items': items, } ############################## diff --git a/tests/test_menus.py b/tests/test_menus.py index c3244bc..84c4ee5 100644 --- a/tests/test_menus.py +++ b/tests/test_menus.py @@ -14,8 +14,17 @@ class TestMenuHandler(WebTestCase): self.handler = mod.MenuHandler(self.config) 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): menus = self.handler.make_menus(self.request)