diff --git a/gns3server/api/routes/controller/pools.py b/gns3server/api/routes/controller/pools.py index 4c4f53c21..0d79e39bc 100644 --- a/gns3server/api/routes/controller/pools.py +++ b/gns3server/api/routes/controller/pools.py @@ -149,8 +149,7 @@ async def delete_resource_pool( # Check if there are any ACE configurations using this resource pool path pool_path = f"/pools/{resource_pool_id}" - aces = await rbac_repo.get_aces() - using_aces = [ace for ace in aces if ace.path == pool_path or ace.path.startswith(pool_path + "/")] + using_aces = await rbac_repo.get_aces_for_path(pool_path) if using_aces: # Build detailed error message with ACE information diff --git a/gns3server/db/repositories/rbac.py b/gns3server/db/repositories/rbac.py index 6d7514654..ce62c5caa 100644 --- a/gns3server/db/repositories/rbac.py +++ b/gns3server/db/repositories/rbac.py @@ -230,6 +230,25 @@ class RbacRepository(BaseRepository): result = await self._db_session.execute(query) return result.scalars().all() + async def get_aces_for_path(self, path: str) -> List[models.ACE]: + """ + Get all ACEs for a specific path (exact match or starting with path). + + This method includes related user, group, and role information. + """ + + query = select(models.ACE).\ + where( + (models.ACE.path == path) | (models.ACE.path.startswith(path + "/")) + ).\ + options( + selectinload(models.ACE.user), + selectinload(models.ACE.group), + selectinload(models.ACE.role) + ) + result = await self._db_session.execute(query) + return result.scalars().all() + async def check_ace_exists(self, path: str) -> bool: """ Check if an ACE exists.