style: apply black and isort formatting across entire codebase
- Standardize quote style (single to double quotes) - Reorder and group imports alphabetically - Fix line breaks and indentation for consistency - Apply PEP 8 formatting standards Also updated Makefile to exclude both venv and .venv from code quality checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,15 +10,15 @@ This module provides functions for:
|
||||
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional, Dict, Any
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import and_, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.exceptions import AdminOperationException
|
||||
from models.database.admin import AdminAuditLog
|
||||
from models.database.user import User
|
||||
from models.schema.admin import AdminAuditLogFilters, AdminAuditLogResponse
|
||||
from app.exceptions import AdminOperationException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -36,7 +36,7 @@ class AdminAuditService:
|
||||
details: Optional[Dict[str, Any]] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
user_agent: Optional[str] = None,
|
||||
request_id: Optional[str] = None
|
||||
request_id: Optional[str] = None,
|
||||
) -> AdminAuditLog:
|
||||
"""
|
||||
Log an admin action to the audit trail.
|
||||
@@ -63,7 +63,7 @@ class AdminAuditService:
|
||||
details=details or {},
|
||||
ip_address=ip_address,
|
||||
user_agent=user_agent,
|
||||
request_id=request_id
|
||||
request_id=request_id,
|
||||
)
|
||||
|
||||
db.add(audit_log)
|
||||
@@ -84,9 +84,7 @@ class AdminAuditService:
|
||||
return None
|
||||
|
||||
def get_audit_logs(
|
||||
self,
|
||||
db: Session,
|
||||
filters: AdminAuditLogFilters
|
||||
self, db: Session, filters: AdminAuditLogFilters
|
||||
) -> List[AdminAuditLogResponse]:
|
||||
"""
|
||||
Get filtered admin audit logs with pagination.
|
||||
@@ -98,7 +96,9 @@ class AdminAuditService:
|
||||
List of audit log responses
|
||||
"""
|
||||
try:
|
||||
query = db.query(AdminAuditLog).join(User, AdminAuditLog.admin_user_id == User.id)
|
||||
query = db.query(AdminAuditLog).join(
|
||||
User, AdminAuditLog.admin_user_id == User.id
|
||||
)
|
||||
|
||||
# Apply filters
|
||||
conditions = []
|
||||
@@ -123,8 +123,7 @@ class AdminAuditService:
|
||||
|
||||
# Execute query with pagination
|
||||
logs = (
|
||||
query
|
||||
.order_by(AdminAuditLog.created_at.desc())
|
||||
query.order_by(AdminAuditLog.created_at.desc())
|
||||
.offset(filters.skip)
|
||||
.limit(filters.limit)
|
||||
.all()
|
||||
@@ -143,7 +142,7 @@ class AdminAuditService:
|
||||
ip_address=log.ip_address,
|
||||
user_agent=log.user_agent,
|
||||
request_id=log.request_id,
|
||||
created_at=log.created_at
|
||||
created_at=log.created_at,
|
||||
)
|
||||
for log in logs
|
||||
]
|
||||
@@ -151,15 +150,10 @@ class AdminAuditService:
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to retrieve audit logs: {str(e)}")
|
||||
raise AdminOperationException(
|
||||
operation="get_audit_logs",
|
||||
reason="Database query failed"
|
||||
operation="get_audit_logs", reason="Database query failed"
|
||||
)
|
||||
|
||||
def get_audit_logs_count(
|
||||
self,
|
||||
db: Session,
|
||||
filters: AdminAuditLogFilters
|
||||
) -> int:
|
||||
def get_audit_logs_count(self, db: Session, filters: AdminAuditLogFilters) -> int:
|
||||
"""Get total count of audit logs matching filters."""
|
||||
try:
|
||||
query = db.query(AdminAuditLog)
|
||||
@@ -192,24 +186,14 @@ class AdminAuditService:
|
||||
return 0
|
||||
|
||||
def get_recent_actions_by_admin(
|
||||
self,
|
||||
db: Session,
|
||||
admin_user_id: int,
|
||||
limit: int = 10
|
||||
self, db: Session, admin_user_id: int, limit: int = 10
|
||||
) -> List[AdminAuditLogResponse]:
|
||||
"""Get recent actions by a specific admin."""
|
||||
filters = AdminAuditLogFilters(
|
||||
admin_user_id=admin_user_id,
|
||||
limit=limit
|
||||
)
|
||||
filters = AdminAuditLogFilters(admin_user_id=admin_user_id, limit=limit)
|
||||
return self.get_audit_logs(db, filters)
|
||||
|
||||
def get_actions_by_target(
|
||||
self,
|
||||
db: Session,
|
||||
target_type: str,
|
||||
target_id: str,
|
||||
limit: int = 50
|
||||
self, db: Session, target_type: str, target_id: str, limit: int = 50
|
||||
) -> List[AdminAuditLogResponse]:
|
||||
"""Get all actions performed on a specific target."""
|
||||
try:
|
||||
@@ -218,7 +202,7 @@ class AdminAuditService:
|
||||
.filter(
|
||||
and_(
|
||||
AdminAuditLog.target_type == target_type,
|
||||
AdminAuditLog.target_id == str(target_id)
|
||||
AdminAuditLog.target_id == str(target_id),
|
||||
)
|
||||
)
|
||||
.order_by(AdminAuditLog.created_at.desc())
|
||||
@@ -236,7 +220,7 @@ class AdminAuditService:
|
||||
target_id=log.target_id,
|
||||
details=log.details,
|
||||
ip_address=log.ip_address,
|
||||
created_at=log.created_at
|
||||
created_at=log.created_at,
|
||||
)
|
||||
for log in logs
|
||||
]
|
||||
@@ -247,4 +231,4 @@ class AdminAuditService:
|
||||
|
||||
|
||||
# Create service instance
|
||||
admin_audit_service = AdminAuditService()
|
||||
admin_audit_service = AdminAuditService()
|
||||
|
||||
Reference in New Issue
Block a user