henry3260 commented on code in PR #76965:
URL: https://github.com/apache/airflow/pull/76965#discussion_r4568556238


##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -1236,6 +1236,15 @@ def __init__(
         self.asset_ids = asset_ids
         self.can_read_an_owner = can_read_an_owner
 
+    def allows(self, *, dag_id: str | None, owner_ref: dict | None, 
watched_asset_ids: set[int]) -> bool:
+        """Check trigger ownership permissions without expanding SQL IN 
lists."""
+        owner_ref = owner_ref or {}
+        if owner_ref.get("ti_id") is not None:
+            return dag_id in self.task_dag_ids
+        if owner_ref.get("callback_id") is not None:
+            return dag_id in self.callback_dag_ids
+        return bool(watched_asset_ids & self.asset_ids)
+
     def to_orm(self, select: Select) -> Select:

Review Comment:
   Could we remove `PermittedTriggerFilter.to_orm()` and 
`_select_triggers_watching()`? This PR replaces `to_orm()` with `allows()`, so 
neither has a caller left, and keeping both means the same permission rule 
lives in two places.



##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_triggers.py:
##########
@@ -365,6 +365,29 @@ def test_filters(self, test_client, triggers, params, 
expected):
         assert response.status_code == 200
         assert sorted(_name(t) for t in response.json()["triggers"]) == 
expected
 
+    def test_pagination_counts_multi_watcher_trigger_once(self, test_client, 
session, triggers):

Review Comment:
   Could you add a test that mocks `get_authorized_dag_ids` so some triggers 
are hidden, then walks the pages with `limit`/`offset` and asserts 
`total_entries` and the order?



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

Reply via email to