Sistema limpio
This commit is contained in:
28
backend/fix_users.py
Normal file
28
backend/fix_users.py
Normal file
@@ -0,0 +1,28 @@
|
||||
with open("/app/app/api/v1/endpoints/users.py", "r") as f:
|
||||
content = f.read()
|
||||
|
||||
old1 = " User.tenant_id == current_user.tenant_id # " + "\u2705" + " Seguridad multi-tenant"
|
||||
new1 = """ from app.models.user import UserRole as _UserRole
|
||||
if current_user.role == _UserRole.ADMIN:
|
||||
query = select(User).where(User.id == user_id)
|
||||
else:
|
||||
query = select(User).where(
|
||||
User.id == user_id,
|
||||
User.tenant_id == current_user.tenant_id
|
||||
)"""
|
||||
|
||||
if old1 in content:
|
||||
content = content.replace(old1, new1)
|
||||
print("OK bloque 1")
|
||||
else:
|
||||
print("SKIP bloque 1 - buscando alternativa")
|
||||
old1b = " User.tenant_id == current_user.tenant_id\n )\n result = await db.execute(query)\n if not user:"
|
||||
new1b = " User.tenant_id == current_user.tenant_id\n )\n result = await db.execute(query)\n if not user:"
|
||||
print("Lineas con tenant_id encontradas:")
|
||||
for i, line in enumerate(content.split("\n")):
|
||||
if "tenant_id == current_user.tenant_id" in line:
|
||||
print(f" Linea {i}: {line}")
|
||||
|
||||
with open("/app/app/api/v1/endpoints/users.py", "w") as f:
|
||||
f.write(content)
|
||||
print("Listo")
|
||||
Reference in New Issue
Block a user