gate4: use separate API session for audit log in confirm_password_reset
This commit is contained in:
@@ -335,19 +335,24 @@ 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
|
||||||
await log_audit(
|
api_engine = get_api_engine()
|
||||||
db,
|
async with AsyncSession(api_engine) as audit_db:
|
||||||
reset_token.tenant_id,
|
await set_tenant_context(audit_db, reset_token.tenant_id)
|
||||||
user.id,
|
await log_audit(
|
||||||
"password_reset",
|
audit_db,
|
||||||
"user",
|
reset_token.tenant_id,
|
||||||
user.id,
|
user.id,
|
||||||
changes={"action": "password_changed"},
|
"password_reset",
|
||||||
)
|
"user",
|
||||||
|
user.id,
|
||||||
|
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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user