Skip to content

Commit

Permalink
Copy menu_item href for nav bar (#39282)
Browse files Browse the repository at this point in the history
Co-authored-by: Jed Cunningham <jedcunningham@apache.org>
(cherry picked from commit 25f901a)
  • Loading branch information
bbovenzi authored and jedcunningham committed Apr 27, 2024
1 parent 368ff13 commit cddaf23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 4 additions & 6 deletions airflow/auth/managers/base_auth_manager.py
Expand Up @@ -398,12 +398,10 @@ def filter_permitted_menu_items(self, menu_items: list[MenuItem]) -> list[MenuIt
accessible_items = []
for menu_item in items:
menu_item_copy = MenuItem(
name=menu_item.name,
icon=menu_item.icon,
label=menu_item.label,
childs=[],
baseview=menu_item.baseview,
cond=menu_item.cond,
**{
**menu_item.__dict__,
"childs": [],
}
)
if menu_item.childs:
accessible_children = []
Expand Down
16 changes: 15 additions & 1 deletion tests/auth/managers/test_base_auth_manager.py
Expand Up @@ -300,7 +300,15 @@ def test_filter_permitted_menu_items(self, mock_security_manager, auth_manager):
mock_security_manager.has_access.side_effect = [True, False, True, True, False]

menu = Menu()
menu.add_link("item1")
menu.add_link(
# These may not all be valid types, but it does let us check each attr is copied
name="item1",
href="h1",
icon="i1",
label="l1",
baseview="b1",
cond="c1",
)
menu.add_link("item2")
menu.add_link("item3")
menu.add_link("item3.1", category="item3")
Expand All @@ -313,6 +321,12 @@ def test_filter_permitted_menu_items(self, mock_security_manager, auth_manager):
assert result[1].name == "item3"
assert len(result[1].childs) == 1
assert result[1].childs[0].name == "item3.1"
# check we've copied every attr
assert result[0].href == "h1"
assert result[0].icon == "i1"
assert result[0].label == "l1"
assert result[0].baseview == "b1"
assert result[0].cond == "c1"

@patch.object(EmptyAuthManager, "security_manager")
def test_filter_permitted_menu_items_twice(self, mock_security_manager, auth_manager):
Expand Down

0 comments on commit cddaf23

Please sign in to comment.