vincbeck commented on code in PR #55298: URL: https://github.com/apache/airflow/pull/55298#discussion_r2325767389
########## airflow-core/src/airflow/api_fastapi/core_api/security.py: ########## @@ -233,6 +233,37 @@ def inner( return inner +class PermittedPoolFilter(OrmClause[set[str]]): + """A parameter that filters the permitted pools for the user.""" + + def to_orm(self, select: Select) -> Select: + return select.where(Pool.pool.in_(self.value)) + + +def permitted_pool_filter_factory( + method: ResourceMethod, filter_class=PermittedPoolFilter +) -> Callable[[Request, BaseUser], PermittedPoolFilter]: + """ + Create a callable for Depends in FastAPI that returns a filter of the permitted pools for the user. + + :param method: whether filter readable or writable. + :param filter_class: filter class to apply + """ + + def depends_permitted_pools_filter( + request: Request, + user: GetUserDep, + ) -> PermittedPoolFilter: + auth_manager: BaseAuthManager = request.app.state.auth_manager + authorized_pools: set[str] = auth_manager.get_authorized_pools(user=user, method=method) + return filter_class(authorized_pools) Review Comment: You're entirely correct! Good catch! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org