You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by vi...@apache.org on 2023/08/10 14:15:22 UTC

[airflow] branch main updated: Move Roles view to FAB (#33043)

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 5707103f44 Move Roles view to FAB (#33043)
5707103f44 is described below

commit 5707103f447be818ad4ba0c34874b822ffeefc09
Author: Raphaƫl Vandon <va...@amazon.com>
AuthorDate: Thu Aug 10 07:15:11 2023 -0700

    Move Roles view to FAB (#33043)
---
 airflow/auth/managers/fab/views/roles_list.py | 42 +++++++++++++++++++++++++++
 airflow/www/fab_security/manager.py           |  4 +--
 airflow/www/fab_security/views.py             | 22 --------------
 airflow/www/security.py                       |  2 +-
 4 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/airflow/auth/managers/fab/views/roles_list.py b/airflow/auth/managers/fab/views/roles_list.py
new file mode 100644
index 0000000000..944ef06cd1
--- /dev/null
+++ b/airflow/auth/managers/fab/views/roles_list.py
@@ -0,0 +1,42 @@
+# 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 flask_appbuilder.security.views import RoleModelView
+
+from airflow.security import permissions
+
+
+class CustomRoleModelView(RoleModelView):
+    """Customize permission names for FAB's builtin RoleModelView."""
+
+    class_permission_name = permissions.RESOURCE_ROLE
+    method_permission_name = {
+        "delete": "delete",
+        "download": "read",
+        "show": "read",
+        "list": "read",
+        "edit": "edit",
+        "add": "create",
+        "copy_role": "create",
+    }
+    base_permissions = [
+        permissions.ACTION_CAN_CREATE,
+        permissions.ACTION_CAN_READ,
+        permissions.ACTION_CAN_EDIT,
+        permissions.ACTION_CAN_DELETE,
+    ]
diff --git a/airflow/www/fab_security/manager.py b/airflow/www/fab_security/manager.py
index fca6a3083c..44d6974625 100644
--- a/airflow/www/fab_security/manager.py
+++ b/airflow/www/fab_security/manager.py
@@ -258,7 +258,7 @@ class BaseSecurityManager:
         """Returns FAB builtin roles."""
         return self.appbuilder.get_app.config.get("FAB_ROLES", {})
 
-    def get_roles_from_keys(self, role_keys: list[str]) -> set[RoleModelView]:
+    def get_roles_from_keys(self, role_keys: list[str]) -> set[Role]:
         """
         Construct a list of FAB role objects, from a list of keys.
 
@@ -267,7 +267,7 @@ class BaseSecurityManager:
         - we use AUTH_ROLES_MAPPING to map from keys, to FAB role names
 
         :param role_keys: the list of FAB role keys
-        :return: a list of RoleModelView
+        :return: a list of Role
         """
         _roles = set()
         _role_keys = set(role_keys)
diff --git a/airflow/www/fab_security/views.py b/airflow/www/fab_security/views.py
index 8619ca69d2..94bfe01d05 100644
--- a/airflow/www/fab_security/views.py
+++ b/airflow/www/fab_security/views.py
@@ -20,7 +20,6 @@ from __future__ import annotations
 from flask_appbuilder.security.views import (
     PermissionModelView,
     PermissionViewModelView,
-    RoleModelView,
     ViewMenuModelView,
 )
 from flask_babel import lazy_gettext
@@ -72,27 +71,6 @@ class PermissionPairModelView(PermissionViewModelView):
     list_columns = ["action", "resource"]
 
 
-class CustomRoleModelView(RoleModelView):
-    """Customize permission names for FAB's builtin RoleModelView."""
-
-    class_permission_name = permissions.RESOURCE_ROLE
-    method_permission_name = {
-        "delete": "delete",
-        "download": "read",
-        "show": "read",
-        "list": "read",
-        "edit": "edit",
-        "add": "create",
-        "copy_role": "create",
-    }
-    base_permissions = [
-        permissions.ACTION_CAN_CREATE,
-        permissions.ACTION_CAN_READ,
-        permissions.ACTION_CAN_EDIT,
-        permissions.ACTION_CAN_DELETE,
-    ]
-
-
 class ResourceModelView(ViewMenuModelView):
     """Customize permission names for FAB's builtin ViewMenuModelView."""
 
diff --git a/airflow/www/security.py b/airflow/www/security.py
index 16a6b822af..fee21dd9d4 100644
--- a/airflow/www/security.py
+++ b/airflow/www/security.py
@@ -25,6 +25,7 @@ from sqlalchemy import or_
 from sqlalchemy.orm import Session, joinedload
 
 from airflow.auth.managers.fab.models import Permission, Resource, Role, User
+from airflow.auth.managers.fab.views.roles_list import CustomRoleModelView
 from airflow.auth.managers.fab.views.user import (
     CustomUserDBModelView,
     CustomUserLDAPModelView,
@@ -47,7 +48,6 @@ from airflow.www.extensions.init_auth_manager import get_auth_manager
 from airflow.www.fab_security.sqla.manager import SecurityManager
 from airflow.www.fab_security.views import (
     ActionModelView,
-    CustomRoleModelView,
     PermissionPairModelView,
     ResourceModelView,
 )