Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy menu_item href for nav bar #39282

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions airflow/auth/managers/base_auth_manager.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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