gate4: use separate API session for audit log in confirm_password_reset

This commit is contained in:
Agent Zero
2026-07-31 12:01:11 +02:00
parent a721db5214
commit a303a4e455
+9 -4
View File
@@ -335,12 +335,16 @@ class AuthService:
except Exception: except Exception:
logger.warning("Failed to invalidate Redis sessions for user %s", user.id, exc_info=True) logger.warning("Failed to invalidate Redis sessions for user %s", user.id, exc_info=True)
# Audit log entry for password reset # Audit log entry for password reset — use separate API session (crm_api)
# to avoid requiring audit_log INSERT grants on crm_auth
try: try:
from app.core.db import set_tenant_context from app.core.db import get_api_engine, set_tenant_context
await set_tenant_context(db, reset_token.tenant_id) from sqlalchemy.ext.asyncio import AsyncSession
api_engine = get_api_engine()
async with AsyncSession(api_engine) as audit_db:
await set_tenant_context(audit_db, reset_token.tenant_id)
await log_audit( await log_audit(
db, audit_db,
reset_token.tenant_id, reset_token.tenant_id,
user.id, user.id,
"password_reset", "password_reset",
@@ -348,6 +352,7 @@ class AuthService:
user.id, user.id,
changes={"action": "password_changed"}, changes={"action": "password_changed"},
) )
await audit_db.commit()
except Exception: except Exception:
logger.warning("Failed to create audit log for password reset of user %s", user.id, exc_info=True) logger.warning("Failed to create audit log for password reset of user %s", user.id, exc_info=True)