codeant-ai-for-open-source[bot] commented on code in PR #45451:
URL: https://github.com/apache/superset/pull/45451#discussion_r4324787664


##########
superset/utils/filters.py:
##########
@@ -176,3 +177,105 @@ 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.
+    """
+
+    clause = extra_access_exclusion_clause(asset_kind, id_column)
+    return query if clause is None else query.filter(clause)
+
+
+def extra_access_exclusion_clause(
+    asset_kind: str,
+    id_column: "ColumnElement[Any]",
+) -> Optional["ColumnElement[bool]"]:
+    """The ``NOT EXISTS`` clause for an exclusion hook, or None when inactive.
+
+    Deliberately ``NOT EXISTS`` rather than ``NOT IN``: a hook subquery that
+    yields a single NULL id makes ``NOT IN`` evaluate to NULL for every row,
+    which would silently empty the entire list -- for admins too. ``NOT 
EXISTS``
+    simply does not match a NULL, so a malformed hook withholds nothing instead
+    of everything.
+    """
+    hook, _reason = _extra_access_exclusion_entry(asset_kind)
+    if not hook:
+        return None
+
+    from superset.utils.core import get_user_id
+
+    user_id = get_user_id()
+    if not user_id:
+        return None
+
+    excluded = hook(user_id)
+    excluded_id = list(excluded.c)[0]

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `6790957`.
   
   The hook result now passes through `_exclusion_id_column`, which converts 
values exposing `.subquery()` (including ORM `Query` objects) before reading 
the resulting column.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



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