Skip to content

Commit 1c9c5c6

Browse files
authored
Fix get_menu_items in FAB auth manager (apache#47688)
1 parent 2fa9230 commit 1c9c5c6

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,33 +447,27 @@ def get_menu_items(self, *, user: User) -> list[MenuItem]:
447447
{
448448
"resource_type": "List Users",
449449
"text": "Users",
450-
"href": AUTH_MANAGER_FASTAPI_APP_PREFIX
451-
+ url_for(f"{self.security_manager.user_view.__class__.__name__}.list", _external=False),
450+
"href": f"{AUTH_MANAGER_FASTAPI_APP_PREFIX}/users/list/",
452451
},
453452
{
454453
"resource_type": "List Roles",
455454
"text": "Roles",
456-
"href": AUTH_MANAGER_FASTAPI_APP_PREFIX
457-
+ url_for("CustomRoleModelView.list", _external=False),
455+
"href": f"{AUTH_MANAGER_FASTAPI_APP_PREFIX}/roles/list/",
458456
},
459457
{
460458
"resource_type": "Actions",
461459
"text": "Actions",
462-
"href": AUTH_MANAGER_FASTAPI_APP_PREFIX + url_for("ActionModelView.list", _external=False),
460+
"href": f"{AUTH_MANAGER_FASTAPI_APP_PREFIX}/actions/list/",
463461
},
464462
{
465463
"resource_type": "Resources",
466464
"text": "Resources",
467-
"href": AUTH_MANAGER_FASTAPI_APP_PREFIX + url_for("ResourceModelView.list", _external=False),
465+
"href": f"{AUTH_MANAGER_FASTAPI_APP_PREFIX}/resources/list/",
468466
},
469467
{
470468
"resource_type": "Permission Pairs",
471469
"text": "Permissions",
472-
"href": AUTH_MANAGER_FASTAPI_APP_PREFIX
473-
+ url_for(
474-
"PermissionPairModelView.list",
475-
_external=False,
476-
),
470+
"href": f"{AUTH_MANAGER_FASTAPI_APP_PREFIX}/permissions/list/",
477471
},
478472
]
479473

providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ def test_logout(self, mock_logout_user, auth_manager_with_appbuilder):
592592

593593
@mock.patch.object(FabAuthManager, "_is_authorized", return_value=True)
594594
def test_get_menu_items(self, _, auth_manager_with_appbuilder, flask_app):
595-
with flask_app.app_context():
596-
auth_manager_with_appbuilder.register_views()
597-
result = auth_manager_with_appbuilder.get_menu_items(user=Mock())
598-
assert len(result) == 5
599-
assert all(item.href.startswith(AUTH_MANAGER_FASTAPI_APP_PREFIX) for item in result)
595+
auth_manager_with_appbuilder.register_views()
596+
result = auth_manager_with_appbuilder.get_menu_items(user=Mock())
597+
assert len(result) == 5
598+
assert all(item.href.startswith(AUTH_MANAGER_FASTAPI_APP_PREFIX) for item in result)

0 commit comments

Comments
 (0)