sha174n commented on code in PR #45622:
URL: https://github.com/apache/superset/pull/45622#discussion_r4364700008
##########
superset/daos/dashboard.py:
##########
@@ -609,6 +622,53 @@ def validate_update_slug_uniqueness(dashboard_id: int,
slug: str | None) -> bool
return not db.session.query(dashboard_query.exists()).scalar()
return True
+ @staticmethod
+ def raise_for_added_member_datasource_access(
+ json_metadata: str | None,
+ slice_ids: list[int] | None = None,
+ existing_dashboard_id: int | None = None,
+ ) -> None:
+ """Require the acting user's access to each chart newly added to a
dashboard.
+
+ A chart's datasource can be served through a dashboard it belongs to
+ (see ``can_drill_dataset_via_dashboard_access`` /
``has_drill_access``),
+ so adding one must not grant data the user could not otherwise read.
+ Called from the command ``validate()`` layer, before any side effects.
+
+ The candidate charts are those in the ``json_metadata`` layout plus
+ ``slice_ids``; charts already linked to ``existing_dashboard_id`` are
+ not re-checked. The admin, no-request-user and unresolvable-datasource
+ exemptions live in ``security_manager.raise_for_datasources_access``.
+ Raises ``DashboardForbiddenError`` when refused.
+ """
+ candidate_ids: set[int] = set(slice_ids or [])
+ if json_metadata and (positions :=
json.loads(json_metadata).get("positions")):
+ candidate_ids.update(_slice_ids_from_positions(positions))
+ if not candidate_ids:
+ return
+ # Read prior membership from ``dashboard_slices`` rather than
+ # ``Dashboard.slices``: a dashboard loaded through a query carries the
+ # soft-delete loader criteria into that relationship, which would hide
+ # an archived member and make it look like a new addition.
+ if existing_dashboard_id is not None:
+ candidate_ids -= set(
+
db.session.scalars(_member_slice_ids_select(existing_dashboard_id))
+ )
+ if not candidate_ids:
+ return
+ # Resolve the incoming charts with the visibility filter lifted, the
same
+ # as ``set_dash_metadata``'s rebuild, since it links archived charts
too.
+ with skip_visibility_filter(db.session, Slice):
Review Comment:
Added `test_added_member_datasource_access_checks_soft_deleted_non_member`
in 3ff5627d0c; it fails if the `with` is removed.
--
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]