villebro commented on code in PR #44215:
URL: https://github.com/apache/superset/pull/44215#discussion_r4001176901
##########
superset/dashboards/api.py:
##########
@@ -742,29 +742,44 @@ def get_datasets(self, id_or_slug: str) -> Response:
$ref: '#/components/responses/404'
"""
try:
- datasets = DashboardDAO.get_datasets_for_dashboard(id_or_slug)
+ dashboard, datasets =
DashboardDAO.get_datasets_for_dashboard(id_or_slug)
result = [
- self._serialize_dashboard_dataset(datasource, payload)
+ self._serialize_dashboard_dataset(datasource, payload,
dashboard)
for datasource, payload in datasets
]
return self.response(200, result=result)
except (TypeError, ValueError) as err:
raise DatasetValidationError(err) from err
def _serialize_dashboard_dataset(
- self, datasource: Any, payload: dict[str, Any]
+ self, datasource: Any, payload: dict[str, Any], dashboard: Dashboard
) -> dict[str, Any]:
"""Dump a member dataset, narrowed when the caller cannot access it."""
serialized = self.dashboard_dataset_schema.dump(payload)
- if not security_manager.can_access_datasource(datasource):
+ if not (
+ security_manager.can_access_datasource(datasource)
+ or security_manager.can_drill_dataset_via_dashboard_access(
+ datasource, dashboard
+ )
+ ):
for key in DASHBOARD_DATASET_INACCESSIBLE_FIELDS:
serialized.pop(key, None)
return serialized
- def _serialize_dashboard_chart(self, chart: Any) -> dict[str, Any]:
+ def _serialize_dashboard_chart(
+ self, chart: Any, dashboard: Dashboard
+ ) -> dict[str, Any]:
"""Dump a member chart, narrowed when the caller cannot access it."""
serialized = self.chart_entity_response_schema.dump(chart)
- if not security_manager.can_access_chart(chart):
+ if not (
+ security_manager.can_access_chart(chart)
+ or (
+ chart.datasource is not None
+ and security_manager.can_drill_dataset_via_dashboard_access(
+ chart.datasource, dashboard
+ )
Review Comment:
Addressed structurally in 3f094b1284a. Rather than guard `chart.datasource`
in the serializer, the access inheritance now lives in the access primitive
(`raise_for_access`): `can_access_chart` / `can_access_datasource` themselves
recognize a promiscuous viewer of a published dashboard the chart/dataset
belongs to. Because that check is dashboard-level rather than per-datasource,
it's datasource-type agnostic — semantic-view charts (whose table-only
`chart.datasource` is `None`) render correctly with no special-casing. The
dashboard serializers revert to pristine as a result. The tangled datasource
branch of `raise_for_access` was also refactored into named helpers, preserving
the embedded-guest strict per-request binding (validated against the existing
guest/drill/multi-layer suite).
--
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]