mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
refactor: add efficient get_aces_for_path method for resource pool checks
Add a new repository method get_aces_for_path() that: - Queries ACEs for a specific path at database level (more efficient) - Preloads related user, group, and role objects to prevent 500 errors - Keeps original get_aces() method unchanged to avoid performance impact This improves both performance and code clarity for resource pool deletion safety checks.
This commit is contained in:
2 files changed
+20
-2
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user