diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index cdd1c8d..018054c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -17,6 +17,7 @@ - Fix potential issue in LUA script for policy creation on entity creation - Added counter header in responses to policy GETs - Fixed issues with /me endpoint not retrieving policies correctly +- Ordering for polciies and tenants to avoid pagination issues ### Documentation diff --git a/anubis-management-api/anubis/policies/operations.py b/anubis-management-api/anubis/policies/operations.py index 582caaa..1e20e6b 100644 --- a/anubis-management-api/anubis/policies/operations.py +++ b/anubis-management-api/anubis/policies/operations.py @@ -44,7 +44,8 @@ def get_policies_by_service_path( db_policies = filter_policies_by_user_profile( db_policies, tenant, user_info) counter = db_policies.count() - return db_policies.offset(skip).limit(limit).all(), counter + return db_policies.order_by(models.Policy.id.asc()).offset( + skip).limit(limit).all(), counter elif mode is None and agent is not None: return get_policies_by_agent( db=db, @@ -114,7 +115,8 @@ def get_policies_by_mode( db_policies = filter_policies_by_user_profile( db_policies, tenant, user_info) counter = db_policies.count() - return db_policies.offset(skip).limit(limit).all(), counter + return db_policies.order_by(models.Policy.id.asc()).offset( + skip).limit(limit).all(), counter def get_policies_by_agent( @@ -142,7 +144,8 @@ def get_policies_by_agent( db_policies = filter_policies_by_user_profile( db_policies, tenant, user_info) counter = db_policies.count() - return db_policies.offset(skip).limit(limit).all(), counter + return db_policies.order_by(models.Policy.id.asc()).offset( + skip).limit(limit).all(), counter def _get_policies_by_service_path( @@ -177,7 +180,8 @@ def _get_policies_by_service_path( db_policies = filter_policies_by_user_profile( db_policies, tenant, user_info) counter = db_policies.count() - return db_policies.offset(skip).limit(limit).all(), counter + return db_policies.order_by(models.Policy.id.asc()).offset( + skip).limit(limit).all(), counter def get_policy_by_access_to(db: Session, access_to: str): @@ -185,7 +189,9 @@ def get_policy_by_access_to(db: Session, access_to: str): def get_policies(db: Session, skip: int = 0, limit: int = defaultLimit): - return db.query(models.Policy).offset(skip).limit(limit).all() + return db.query( + models.Policy).order_by( + models.Policy.id.asc()).offset(skip).limit(limit).all() def filter_policies_by_user_profile(db_policies, tenant, user_info): diff --git a/anubis-management-api/anubis/tenants/operations.py b/anubis-management-api/anubis/tenants/operations.py index 3c5c011..887f3f9 100644 --- a/anubis-management-api/anubis/tenants/operations.py +++ b/anubis-management-api/anubis/tenants/operations.py @@ -24,7 +24,9 @@ def get_tenant_by_name(db: Session, name: str): def get_tenants(db: Session, skip: int = 0, limit: int = 100): - return db.query(models.Tenant).offset(skip).limit(limit).all() + return db.query( + models.Tenant).order_by( + models.Tenant.name.asc()).offset(skip).limit(limit).all() def create_tenant( @@ -69,7 +71,8 @@ def delete_tenant(db: Session, tenant: models.Tenant): def get_service_paths(db: Session, skip: int = 0, limit: int = 100): - return db.query(models.ServicePath).offset(skip).limit(limit).all() + return db.query(models.ServicePath).order_by( + models.ServicePath.path.asc()).offset(skip).limit(limit).all() def get_tenant_service_paths( @@ -83,7 +86,8 @@ def get_tenant_service_paths( if name: db_service_paths = db_service_paths.filter( models.ServicePath.path.startswith(name)) - return db_service_paths.offset(skip).limit(limit).all() + return db_service_paths.order_by( + models.ServicePath.path.asc()).offset(skip).limit(limit).all() def get_db_service_path(db: Session, tenant: str, service_path: str): @@ -105,12 +109,14 @@ def get_tenant_service_path_by_path(db: Session, tenant_id: str, path: str): return db.query( models.ServicePath).filter( models.ServicePath.tenant_id == tenant_id).filter( - models.ServicePath.path.like(queryPath)).all() + models.ServicePath.path.like(queryPath)).order_by( + models.ServicePath.path.asc()).all() else: return db.query( models.ServicePath).filter( models.ServicePath.tenant_id == tenant_id).filter( - models.ServicePath.path == path).all() + models.ServicePath.path == path).order_by( + models.ServicePath.path.asc()).all() def get_tenant_service_path(db: Session, service_path_id: str, tenant_id: str):