alexandrusoare commented on code in PR #45451:
URL: https://github.com/apache/superset/pull/45451#discussion_r4324059154


##########
superset/utils/filters.py:
##########
@@ -176,3 +177,33 @@ def guest_embedded_dashboard_filter() -> 
Optional[ColumnElement[bool]]:
         # dashboards, never a plain internal id.
         conditions.append(and_(Dashboard.id.in_(int_ids), 
Dashboard.embedded.any()))
     return or_(*conditions) if conditions else false()
+
+
+def apply_extra_access_exclusions(
+    query: "Query",
+    asset_kind: str,
+    id_column: "ColumnElement[Any]",
+) -> "Query":
+    """Withhold the asset IDs an ``EXTRA_ACCESS_QUERY_EXCLUSIONS`` hook names.
+
+    ``EXTRA_ACCESS_QUERY_FILTERS`` can only widen a result set -- its 
conditions
+    are OR'd with the role paths -- so a deployment with its own notion of a
+    withheld asset cannot express that through it. This is the matching AND 
NOT.
+
+    Returns ``query`` unchanged when no hook is configured or there is no
+    authenticated user, so the default build is unaffected.
+    """
+    from flask import current_app
+
+    from superset.utils.core import get_user_id
+
+    exclusions = current_app.config.get("EXTRA_ACCESS_QUERY_EXCLUSIONS") or {}
+    hook = exclusions.get(asset_kind)
+    if not hook:
+        return query
+
+    user_id = get_user_id()
+    if not user_id:
+        return query
+
+    return query.filter(id_column.notin_(hook(user_id)))

Review Comment:
   Right. I'd written this down as a known hazard and shipped it anyway, so 
thanks for catching it. Switched to NOT EXISTS, which doesn't match a NULL, so 
a malformed hook withholds nothing instead of everything. Test puts a literal 
NULL through a hook and asserts the list survives.



-- 
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