Add cleanup logic to remove inactive/revoked client records from database

- Clients list page now removes ClientActivity records associated with inactive or revoked API tokens
- Only clients with active tokens are displayed in the web interface
- Added logging for cleanup operations
- Maintains existing filtering for active tokens in display
parent aa0108ff
......@@ -1424,6 +1424,23 @@ def clients():
from app.models import ClientActivity, SystemSettings, APIToken
from datetime import datetime, timedelta
# Clean up clients with inactive or revoked tokens
# Delete ClientActivity records where the associated token is inactive or doesn't exist
inactive_clients = ClientActivity.query.filter(
db.or_(
~ClientActivity.api_token_id.in_(
db.session.query(APIToken.id).filter(APIToken.is_active == True)
),
ClientActivity.api_token_id.is_(None)
)
).all()
if inactive_clients:
for client in inactive_clients:
db.session.delete(client)
db.session.commit()
logger.info(f"Cleaned up {len(inactive_clients)} client records with inactive/revoked tokens")
# Get filter and search parameters
status_filter = request.args.get('status') # 'online', 'offline', or None for all
search_query = request.args.get('search', '').strip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment