bito-code-review[bot] commented on code in PR #41753:
URL: https://github.com/apache/superset/pull/41753#discussion_r3539917258


##########
superset/mcp_service/guest_scope.py:
##########
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Embedded-guest data-query authorization for MCP chart tools.
+
+Chart *resolution* is scoped for guests by the core ``ChartFilter`` (mirroring
+``DashboardAccessFilter``). This module handles the remaining MCP-layer 
concern:
+attaching the embedded dashboard context to a chart's data query so the 
existing
+guest ``raise_for_access`` branch authorizes it, exactly as the embedded
+dashboard frontend does.
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+def is_guest_read() -> bool:
+    """True when the current MCP read is an embedded guest's, so the chart 
tools
+    skip the dataset RBAC pre-check: a guest reads via the dashboard context, 
not
+    dataset RBAC, and ``raise_for_access`` remains the real gate."""
+    from superset import security_manager
+
+    return security_manager.is_guest_user()
+
+
+def guest_dashboard_id(chart: Any) -> int | None:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Replace Any type annotation in 
guest_dashboard_id</b></div>
   <div id="fix">
   
   Replace `Any` type in `chart` parameter with a concrete type to satisfy 
ANN401. Similar typing issues exist on line 57 for `query_context` and `chart`.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #0a1301</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
superset/utils/filters.py:
##########
@@ -41,3 +41,43 @@ def get_dataset_access_filters(
         base_model.schema_perm.in_(schema_perms),
         *args,
     )
+
+
+def guest_embedded_dashboard_filter() -> Optional[Any]:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Imprecise return type annotation</b></div>
   <div id="fix">
   
   Return type `Optional[Any]` is imprecise. SQLAlchemy's `or_()` always 
returns `BooleanClauseList` (including empty when called with no args), so the 
correct type is `Optional[BooleanClauseList]`. This aligns with the existing 
`get_dataset_access_filters` return type and provides proper type checking.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #0a1301</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
superset/mcp_service/guest_scope.py:
##########
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Embedded-guest data-query authorization for MCP chart tools.
+
+Chart *resolution* is scoped for guests by the core ``ChartFilter`` (mirroring
+``DashboardAccessFilter``). This module handles the remaining MCP-layer 
concern:
+attaching the embedded dashboard context to a chart's data query so the 
existing
+guest ``raise_for_access`` branch authorizes it, exactly as the embedded
+dashboard frontend does.
+"""
+
+from __future__ import annotations
+
+import logging
+from typing import Any
+
+logger = logging.getLogger(__name__)
+
+
+def is_guest_read() -> bool:
+    """True when the current MCP read is an embedded guest's, so the chart 
tools
+    skip the dataset RBAC pre-check: a guest reads via the dashboard context, 
not
+    dataset RBAC, and ``raise_for_access`` remains the real gate."""
+    from superset import security_manager
+
+    return security_manager.is_guest_user()
+
+
+def guest_dashboard_id(chart: Any) -> int | None:
+    """Id of a guest-accessible dashboard containing ``chart``, else None (also
+    the "is embedded-guest read" signal: None for non-guests)."""
+    from superset import security_manager
+
+    if not security_manager.is_guest_user():
+        return None
+    for dashboard in getattr(chart, "dashboards", None) or []:
+        if security_manager.has_guest_access(dashboard):
+            return dashboard.id
+    return None
+
+
+def authorize_query(query_context: Any, dashboard_id: int, chart: Any) -> None:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Replace Any type annotations in authorize_query</b></div>
   <div id="fix">
   
   Replace `Any` type annotations for `query_context` and `chart` parameters 
with concrete types to satisfy ANN401.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #0a1301</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to