vincbeck commented on code in PR #54528: URL: https://github.com/apache/airflow/pull/54528#discussion_r2316227892
########## providers/fab/src/airflow/providers/fab/auth_manager/dag_permissions.py: ########## @@ -0,0 +1,110 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""DAG permissions management for FAB Auth Manager.""" + +from __future__ import annotations + +import logging +from typing import TYPE_CHECKING + +from airflow.security.permissions import RESOURCE_DAG_PREFIX + +if TYPE_CHECKING: + from sqlalchemy.orm import Session + +log = logging.getLogger(__name__) + + +def cleanup_dag_permissions(dag_id: str, session: Session | None = None) -> None: + """ + Clean up DAG-specific permissions from Flask-AppBuilder tables. + + When a DAG is deleted, we need to clean up the corresponding permissions + to prevent orphaned entries in the ab_view_menu table. + + This addresses issue #50905: Deleted DAGs not removed from ab_view_menu table + and show up in permissions. + + :param dag_id: Specific DAG ID to clean up. + :param session: Database session. If None, creates a new session. + """ + from airflow.utils.session import create_session + + if session is None: + with create_session() as session: + _cleanup_dag_permissions_impl(dag_id, session) + else: + _cleanup_dag_permissions_impl(dag_id, session) Review Comment: The decorator `@provide_session` does pretty much what you are doing here ########## providers/fab/src/airflow/providers/fab/auth_manager/dag_permissions.py: ########## @@ -0,0 +1,110 @@ +# Review Comment: I would move this code either in `providers/fab/src/airflow/providers/fab/auth_manager/cli_commands/permissions_command.py` or in a new file in `providers/fab/src/airflow/providers/fab/auth_manager/cli_commands/` -- 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]
