vincbeck commented on code in PR #77311:
URL: https://github.com/apache/airflow/pull/77311#discussion_r4644664215


##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -677,33 +677,11 @@ def get_authorized_dag_ids(
         if self._is_authorized(method=method, resource_type=RESOURCE_DAG, 
user=user):
             # If user is authorized to access all DAGs, return all DAGs
             return {dag.dag_id for dag in 
session.execute(select(DagModel.dag_id))}
-        if isinstance(user, AnonymousUser):
-            return set()
-        user_query = (
-            session.scalars(
-                select(User)
-                .options(
-                    joinedload(User.roles)
-                    .subqueryload(Role.permissions)
-                    .options(joinedload(Permission.action), 
joinedload(Permission.resource))
-                )
-                .where(User.id == user.id)
-            )
-            .unique()
-            .one()
-        )
-        roles = user_query.roles
-
         fab_action = get_fab_action_from_method_map().get(method)
         resources = set()
-        for role in roles:
-            for permission in role.permissions:
-                if permission.action.name == fab_action:
-                    resource = permission.resource.name
-                    if resource == permissions.RESOURCE_DAG:
-                        return {dag.dag_id for dag in 
session.execute(select(DagModel.dag_id))}
-                    if resource.startswith(permissions.RESOURCE_DAG_PREFIX):
-                        
resources.add(resource[len(permissions.RESOURCE_DAG_PREFIX) :])
+        for action, resource in self._get_user_permissions(user):
+            if action == fab_action and 
resource.startswith(permissions.RESOURCE_DAG_PREFIX):
+                resources.add(resource[len(permissions.RESOURCE_DAG_PREFIX) :])

Review Comment:
   nit: `RESOURCE_DAG_PREFIX` is already imported, so no need for `permissions.`
   
   ```suggestion
               if action == fab_action and 
resource.startswith(RESOURCE_DAG_PREFIX):
                   resources.add(resource[len(RESOURCE_DAG_PREFIX) :])
   ```



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