-
Notifications
You must be signed in to change notification settings - Fork 17.7k
fix(mcp): serialize dashboard role permissions #41404
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
base: master
Are you sure you want to change the base?
Changes from all commits
0bd7ea3
f1ecd71
75f8215
aee35e9
84bbc70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,16 +21,19 @@ | |
|
|
||
| import logging | ||
| from importlib import import_module | ||
| from types import SimpleNamespace | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| import pytest | ||
| from fastmcp import Client | ||
| from fastmcp.exceptions import ToolError | ||
| from flask import g | ||
| from sqlalchemy.orm.exc import DetachedInstanceError | ||
|
|
||
| from superset.mcp_service.app import mcp | ||
| from superset.mcp_service.dashboard.schemas import ( | ||
| ListDashboardsRequest, | ||
| serialize_role_object, | ||
| ) | ||
| from superset.mcp_service.dashboard.tool.get_dashboard_info import ( | ||
| _refresh_request_user_for_permalink_access, | ||
|
|
@@ -134,6 +137,109 @@ async def test_list_dashboards_basic(mock_list, mcp_server): | |
| assert "slug" in data["columns_loaded"] | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_serializes_permission_view_names() -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a short docstring to this new test function describing the serializer behavior it validates. [custom_rule] Severity Level: Minor Why it matters? 🤔This is a newly added Python test function and it has no docstring. The custom rule requires new functions to be documented inline, so the suggestion identifies a real violation. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
**Line:** 140:140
**Comment:**
*Custom Rule: Add a short docstring to this new test function describing the serializer behavior it validates.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| permission_view = SimpleNamespace( | ||
| permission=SimpleNamespace(name="can_read"), | ||
| view_menu=SimpleNamespace(name="Dashboard"), | ||
| ) | ||
| role = SimpleNamespace(id=1, name="Gamma", permissions=[permission_view]) | ||
|
|
||
| role_info = serialize_role_object(role) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.model_dump() == { | ||
| "id": 1, | ||
| "name": "Gamma", | ||
| "permissions": ["can_read on Dashboard"], | ||
| } | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_skips_bad_permission_items() -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a docstring to this new test function so its edge-case intent is explicitly documented. [custom_rule] Severity Level: Minor Why it matters? 🤔This is a newly added Python test function and there is no docstring immediately under it. That violates the rule requiring new functions to include docstrings. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
**Line:** 157:157
**Comment:**
*Custom Rule: Add a docstring to this new test function so its edge-case intent is explicitly documented.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| class DetachedPermission: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a brief class docstring explaining the purpose of this helper class used in the test. [custom_rule] Severity Level: Minor Why it matters? 🤔This newly introduced helper class does not have a docstring. The custom rule explicitly requires new classes to be documented inline. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
**Line:** 158:158
**Comment:**
*Custom Rule: Add a brief class docstring explaining the purpose of this helper class used in the test.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| @property | ||
| def name(self) -> str: | ||
| raise DetachedInstanceError("detached permission") | ||
|
|
||
| permission_view = SimpleNamespace( | ||
| permission=SimpleNamespace(name="can_read"), | ||
| view_menu=SimpleNamespace(name="Dashboard"), | ||
| ) | ||
| role = SimpleNamespace( | ||
| id=1, | ||
| name="Gamma", | ||
| permissions=[ | ||
| permission_view, | ||
| DetachedPermission(), | ||
| SimpleNamespace(name="can_write"), | ||
| ], | ||
| ) | ||
|
|
||
| role_info = serialize_role_object(role) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.permissions == ["can_read on Dashboard", "can_write"] | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_handles_detached_permissions() -> None: | ||
| class DetachedRole: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a class docstring to describe why this detached-role test double exists. [custom_rule] Severity Level: Minor Why it matters? 🤔This is a newly added helper class inside a test function and it lacks a docstring. That matches the custom rule for new classes needing inline documentation. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
**Line:** 184:184
**Comment:**
*Custom Rule: Add a class docstring to describe why this detached-role test double exists.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| id = 1 | ||
| name = "Gamma" | ||
|
|
||
| @property | ||
| def permissions(self) -> list[object]: | ||
| raise DetachedInstanceError("detached permissions") | ||
|
|
||
| role_info = serialize_role_object(DetachedRole()) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.permissions is None | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_handles_non_iterable_permissions() -> None: | ||
| role = SimpleNamespace(id=1, name="Gamma", permissions=object()) | ||
|
|
||
| role_info = serialize_role_object(role) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.permissions == [] | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_stops_on_detached_permission_iterator() -> None: | ||
| class DetachedPermissionIterator: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Add a short docstring to this iterator helper class to clarify the failure scenario it simulates. [custom_rule] Severity Level: Minor Why it matters? 🤔This new helper class also lacks a docstring. Since the rule requires newly added classes to be documented, the suggestion is valid. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
**Line:** 208:208
**Comment:**
*Custom Rule: Add a short docstring to this iterator helper class to clarify the failure scenario it simulates.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| def __iter__(self) -> "DetachedPermissionIterator": | ||
| return self | ||
|
|
||
| def __next__(self) -> object: | ||
| raise DetachedInstanceError("detached permission iterator") | ||
|
|
||
| role = SimpleNamespace( | ||
| id=1, | ||
| name="Gamma", | ||
| permissions=DetachedPermissionIterator(), | ||
| ) | ||
|
|
||
| role_info = serialize_role_object(role) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.permissions == [] | ||
|
|
||
|
|
||
| def test_dashboard_role_serializer_skips_unnamed_permission_items() -> None: | ||
| role = SimpleNamespace( | ||
| id=1, | ||
| name="Gamma", | ||
| permissions=[ | ||
| SimpleNamespace(permission=SimpleNamespace(name="can_read")), | ||
| SimpleNamespace(view_menu=SimpleNamespace(name="Dashboard")), | ||
| ], | ||
| ) | ||
|
|
||
| role_info = serialize_role_object(role) | ||
|
|
||
| assert role_info is not None | ||
| assert role_info.permissions == [] | ||
|
|
||
|
|
||
| @patch("superset.daos.dashboard.DashboardDAO.list") | ||
| @pytest.mark.asyncio | ||
| async def test_list_dashboards_with_filters(mock_list, mcp_server): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.