This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new cc471f96c14 Move `airflow/api_fastapi/auth/managers/utils/fab` to FAB 
provider (#47571)
cc471f96c14 is described below

commit cc471f96c147a11488744873cf92d2829007767e
Author: Vincent <[email protected]>
AuthorDate: Mon Mar 10 13:20:45 2025 -0400

    Move `airflow/api_fastapi/auth/managers/utils/fab` to FAB provider (#47571)
---
 .../api_fastapi/auth/managers/utils/__init__.py    | 17 -------
 airflow/api_fastapi/auth/managers/utils/fab.py     | 52 ----------------------
 .../providers/fab/auth_manager/fab_auth_manager.py |  5 +--
 .../airflow/providers/fab/www/security_manager.py  |  5 +--
 .../fab/src/airflow/providers/fab/www/utils.py     | 29 ++++++++++++
 .../fab/www/views/test_views_custom_user_views.py  |  2 +-
 6 files changed, 32 insertions(+), 78 deletions(-)

diff --git a/airflow/api_fastapi/auth/managers/utils/__init__.py 
b/airflow/api_fastapi/auth/managers/utils/__init__.py
deleted file mode 100644
index 217e5db9607..00000000000
--- a/airflow/api_fastapi/auth/managers/utils/__init__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# 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.
diff --git a/airflow/api_fastapi/auth/managers/utils/fab.py 
b/airflow/api_fastapi/auth/managers/utils/fab.py
deleted file mode 100644
index 82a1c9344ba..00000000000
--- a/airflow/api_fastapi/auth/managers/utils/fab.py
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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.
-from __future__ import annotations
-
-from typing import TYPE_CHECKING
-
-from airflow.security.permissions import (
-    ACTION_CAN_ACCESS_MENU,
-    ACTION_CAN_CREATE,
-    ACTION_CAN_DELETE,
-    ACTION_CAN_EDIT,
-    ACTION_CAN_READ,
-)
-
-if TYPE_CHECKING:
-    from airflow.api_fastapi.auth.managers.base_auth_manager import 
ResourceMethod
-
-# Convert methods to FAB action name
-_MAP_METHOD_NAME_TO_FAB_ACTION_NAME: dict[ResourceMethod, str] = {
-    "POST": ACTION_CAN_CREATE,
-    "GET": ACTION_CAN_READ,
-    "PUT": ACTION_CAN_EDIT,
-    "DELETE": ACTION_CAN_DELETE,
-    "MENU": ACTION_CAN_ACCESS_MENU,
-}
-
-
-def get_fab_action_from_method_map():
-    """Return the map associating a method to a FAB action."""
-    return _MAP_METHOD_NAME_TO_FAB_ACTION_NAME
-
-
-def get_method_from_fab_action_map():
-    """Return the map associating a FAB action to a method."""
-    return {
-        **{v: k for k, v in _MAP_METHOD_NAME_TO_FAB_ACTION_NAME.items()},
-    }
diff --git 
a/providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py 
b/providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py
index e3dd384df21..fef3609b39a 100644
--- a/providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py
+++ b/providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py
@@ -41,10 +41,6 @@ from 
airflow.api_fastapi.auth.managers.models.resource_details import (
     PoolDetails,
     VariableDetails,
 )
-from airflow.api_fastapi.auth.managers.utils.fab import (
-    get_fab_action_from_method_map,
-    get_method_from_fab_action_map,
-)
 from airflow.cli.cli_config import (
     DefaultHelpParser,
     GroupCommand,
@@ -89,6 +85,7 @@ from airflow.providers.fab.www.security.permissions import (
     RESOURCE_WEBSITE,
     RESOURCE_XCOM,
 )
+from airflow.providers.fab.www.utils import get_fab_action_from_method_map, 
get_method_from_fab_action_map
 from airflow.utils.session import NEW_SESSION, create_session, provide_session
 from airflow.utils.yaml import safe_load
 
diff --git a/providers/fab/src/airflow/providers/fab/www/security_manager.py 
b/providers/fab/src/airflow/providers/fab/www/security_manager.py
index a20c1308eda..b41bcd8bec5 100644
--- a/providers/fab/src/airflow/providers/fab/www/security_manager.py
+++ b/providers/fab/src/airflow/providers/fab/www/security_manager.py
@@ -23,10 +23,7 @@ from flask_limiter import Limiter
 from flask_limiter.util import get_remote_address
 
 from airflow.api_fastapi.app import get_auth_manager
-from airflow.api_fastapi.auth.managers.utils.fab import (
-    get_method_from_fab_action_map,
-)
-from airflow.providers.fab.www.utils import CustomSQLAInterface
+from airflow.providers.fab.www.utils import CustomSQLAInterface, 
get_method_from_fab_action_map
 from airflow.utils.log.logging_mixin import LoggingMixin
 
 EXISTING_ROLES = {
diff --git a/providers/fab/src/airflow/providers/fab/www/utils.py 
b/providers/fab/src/airflow/providers/fab/www/utils.py
index b14da644864..1b9e6d0309d 100644
--- a/providers/fab/src/airflow/providers/fab/www/utils.py
+++ b/providers/fab/src/airflow/providers/fab/www/utils.py
@@ -28,13 +28,30 @@ from sqlalchemy import types
 from sqlalchemy.ext.associationproxy import AssociationProxy
 
 from airflow.api_fastapi.app import get_auth_manager
+from airflow.providers.fab.www.security.permissions import (
+    ACTION_CAN_ACCESS_MENU,
+    ACTION_CAN_CREATE,
+    ACTION_CAN_DELETE,
+    ACTION_CAN_EDIT,
+    ACTION_CAN_READ,
+)
 from airflow.utils import timezone
 
 if TYPE_CHECKING:
     from sqlalchemy.orm.session import Session
 
+    from airflow.api_fastapi.auth.managers.base_auth_manager import 
ResourceMethod
     from airflow.providers.fab.auth_manager.fab_auth_manager import 
FabAuthManager
 
+# Convert methods to FAB action name
+_MAP_METHOD_NAME_TO_FAB_ACTION_NAME: dict[ResourceMethod, str] = {
+    "POST": ACTION_CAN_CREATE,
+    "GET": ACTION_CAN_READ,
+    "PUT": ACTION_CAN_EDIT,
+    "DELETE": ACTION_CAN_DELETE,
+    "MENU": ACTION_CAN_ACCESS_MENU,
+}
+
 
 def get_fab_auth_manager() -> FabAuthManager:
     from airflow.providers.fab.auth_manager.fab_auth_manager import 
FabAuthManager
@@ -47,6 +64,18 @@ def get_fab_auth_manager() -> FabAuthManager:
     return auth_manager
 
 
+def get_fab_action_from_method_map():
+    """Return the map associating a method to a FAB action."""
+    return _MAP_METHOD_NAME_TO_FAB_ACTION_NAME
+
+
+def get_method_from_fab_action_map():
+    """Return the map associating a FAB action to a method."""
+    return {
+        **{v: k for k, v in _MAP_METHOD_NAME_TO_FAB_ACTION_NAME.items()},
+    }
+
+
 class UtcAwareFilterMixin:
     """Mixin for filter for UTC time."""
 
diff --git 
a/providers/fab/tests/unit/fab/www/views/test_views_custom_user_views.py 
b/providers/fab/tests/unit/fab/www/views/test_views_custom_user_views.py
index 6851db3700c..315f64afd42 100644
--- a/providers/fab/tests/unit/fab/www/views/test_views_custom_user_views.py
+++ b/providers/fab/tests/unit/fab/www/views/test_views_custom_user_views.py
@@ -26,7 +26,7 @@ from flask_appbuilder import SQLA
 
 from airflow import settings
 from airflow.providers.fab.www import app as application
-from airflow.security import permissions
+from airflow.providers.fab.www.security import permissions
 from unit.fab.auth_manager.api_endpoints.api_connexion_utils import (
     create_user,
     delete_role,

Reply via email to