Spaces:
Running
Running
axeronis commited on
Commit ·
dba382f
1
Parent(s): 53290ba
fix: clear all localStorage on logout to prevent data mixing
Browse files
backend/app/services/ai_core/lead_analyzer.py
CHANGED
|
@@ -14,11 +14,19 @@ from typing import List, Dict, Any, TYPE_CHECKING
|
|
| 14 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 15 |
|
| 16 |
from app.models.lead import Lead, Message, Psychotype, LeadHeat
|
| 17 |
-
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 18 |
from app.core.logging import get_logger
|
| 19 |
|
| 20 |
logger = get_logger(__name__)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if TYPE_CHECKING:
|
| 23 |
from .base import AICore
|
| 24 |
|
|
|
|
| 14 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 15 |
|
| 16 |
from app.models.lead import Lead, Message, Psychotype, LeadHeat
|
|
|
|
| 17 |
from app.core.logging import get_logger
|
| 18 |
|
| 19 |
logger = get_logger(__name__)
|
| 20 |
|
| 21 |
+
# Try to import CRM integration models (may not exist)
|
| 22 |
+
try:
|
| 23 |
+
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 24 |
+
CRM_AVAILABLE = True
|
| 25 |
+
except ImportError:
|
| 26 |
+
CRM_AVAILABLE = False
|
| 27 |
+
CRMIntegration = None
|
| 28 |
+
SyncStatus = None
|
| 29 |
+
|
| 30 |
if TYPE_CHECKING:
|
| 31 |
from .base import AICore
|
| 32 |
|
backend/app/services/ai_core_legacy.py
CHANGED
|
@@ -10,10 +10,18 @@ from app.models.tenant import Tenant
|
|
| 10 |
from app.models.knowledge import SalesScript
|
| 11 |
from app.models.sales_stage import SalesStage # NEW
|
| 12 |
from app.models.ai_training import AITrainingExample, AILearningRule
|
| 13 |
-
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 14 |
from app.models.booking import Service
|
| 15 |
from sqlmodel import select
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
class AICore:
|
| 19 |
"""
|
|
|
|
| 10 |
from app.models.knowledge import SalesScript
|
| 11 |
from app.models.sales_stage import SalesStage # NEW
|
| 12 |
from app.models.ai_training import AITrainingExample, AILearningRule
|
|
|
|
| 13 |
from app.models.booking import Service
|
| 14 |
from sqlmodel import select
|
| 15 |
|
| 16 |
+
# Try to import CRM integration models (may not exist)
|
| 17 |
+
try:
|
| 18 |
+
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 19 |
+
CRM_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
CRM_AVAILABLE = False
|
| 22 |
+
CRMIntegration = None
|
| 23 |
+
SyncStatus = None
|
| 24 |
+
|
| 25 |
|
| 26 |
class AICore:
|
| 27 |
"""
|
backend/app/services/auto_sync_service.py
CHANGED
|
@@ -15,18 +15,27 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|
| 15 |
from sqlmodel import select
|
| 16 |
|
| 17 |
from app.models.lead import Lead, LeadHeat
|
| 18 |
-
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 19 |
-
from app.services.crm_sync import get_crm_sync_service
|
| 20 |
from app.core.logging import get_logger
|
| 21 |
|
| 22 |
logger = get_logger(__name__)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
class AutoSyncService:
|
| 26 |
"""Service for automatically syncing qualified leads to CRM."""
|
| 27 |
|
| 28 |
def __init__(self):
|
| 29 |
-
self.crm_sync_service = get_crm_sync_service()
|
| 30 |
self.min_sync_interval_minutes = 5 # Don't sync same lead more than once per 5 min
|
| 31 |
|
| 32 |
async def check_and_sync_lead(
|
|
|
|
| 15 |
from sqlmodel import select
|
| 16 |
|
| 17 |
from app.models.lead import Lead, LeadHeat
|
|
|
|
|
|
|
| 18 |
from app.core.logging import get_logger
|
| 19 |
|
| 20 |
logger = get_logger(__name__)
|
| 21 |
|
| 22 |
+
# Try to import CRM integration models (may not exist)
|
| 23 |
+
try:
|
| 24 |
+
from app.models.crm_integration import CRMIntegration, SyncStatus
|
| 25 |
+
from app.services.crm_sync import get_crm_sync_service
|
| 26 |
+
CRM_AVAILABLE = True
|
| 27 |
+
except ImportError:
|
| 28 |
+
CRM_AVAILABLE = False
|
| 29 |
+
CRMIntegration = None
|
| 30 |
+
SyncStatus = None
|
| 31 |
+
logger.warning("CRM integration module not available - auto sync disabled")
|
| 32 |
+
|
| 33 |
|
| 34 |
class AutoSyncService:
|
| 35 |
"""Service for automatically syncing qualified leads to CRM."""
|
| 36 |
|
| 37 |
def __init__(self):
|
| 38 |
+
self.crm_sync_service = get_crm_sync_service() if CRM_AVAILABLE else None
|
| 39 |
self.min_sync_interval_minutes = 5 # Don't sync same lead more than once per 5 min
|
| 40 |
|
| 41 |
async def check_and_sync_lead(
|
backend/app/services/subscription_manager.py
CHANGED
|
@@ -42,6 +42,9 @@ class SubscriptionManager:
|
|
| 42 |
# Admin email that bypasses all limits
|
| 43 |
ADMIN_EMAIL = "axeroni.s2@gmail.com"
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
@classmethod
|
| 46 |
async def check_can_create_conversation(
|
| 47 |
cls,
|
|
@@ -65,6 +68,10 @@ class SubscriptionManager:
|
|
| 65 |
if user_email and user_email.lower() == cls.ADMIN_EMAIL.lower():
|
| 66 |
return True, None
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# 1. Проверка истечения подписки
|
| 69 |
if tenant.subscription_end:
|
| 70 |
if datetime.utcnow() > tenant.subscription_end:
|
|
|
|
| 42 |
# Admin email that bypasses all limits
|
| 43 |
ADMIN_EMAIL = "axeroni.s2@gmail.com"
|
| 44 |
|
| 45 |
+
# Admin tenant ID that bypasses all limits (for webhooks without user context)
|
| 46 |
+
ADMIN_TENANT_ID = "058500ec-bd8f-4af1-a088-47a511d96a0c"
|
| 47 |
+
|
| 48 |
@classmethod
|
| 49 |
async def check_can_create_conversation(
|
| 50 |
cls,
|
|
|
|
| 68 |
if user_email and user_email.lower() == cls.ADMIN_EMAIL.lower():
|
| 69 |
return True, None
|
| 70 |
|
| 71 |
+
# ADMIN BYPASS - admin tenant gets unlimited access (for webhooks)
|
| 72 |
+
if str(tenant.id) == cls.ADMIN_TENANT_ID:
|
| 73 |
+
return True, None
|
| 74 |
+
|
| 75 |
# 1. Проверка истечения подписки
|
| 76 |
if tenant.subscription_end:
|
| 77 |
if datetime.utcnow() > tenant.subscription_end:
|
frontend/contexts/AuthContext.tsx
CHANGED
|
@@ -505,7 +505,22 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|
| 505 |
if (typeof window !== 'undefined') {
|
| 506 |
// Clear all auth state including cache
|
| 507 |
clearAuthState()
|
| 508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
}
|
| 510 |
|
| 511 |
|
|
|
|
| 505 |
if (typeof window !== 'undefined') {
|
| 506 |
// Clear all auth state including cache
|
| 507 |
clearAuthState()
|
| 508 |
+
|
| 509 |
+
// CRITICAL: Clear ALL localStorage to prevent data leakage between accounts
|
| 510 |
+
// This includes any cached leads, settings, or other user-specific data
|
| 511 |
+
const keysToPreserve = ['microfunnel_language'] // Only preserve non-user-specific settings
|
| 512 |
+
const allKeys = Object.keys(localStorage)
|
| 513 |
+
|
| 514 |
+
allKeys.forEach(key => {
|
| 515 |
+
if (!keysToPreserve.includes(key)) {
|
| 516 |
+
localStorage.removeItem(key)
|
| 517 |
+
}
|
| 518 |
+
})
|
| 519 |
+
|
| 520 |
+
// Clear all sessionStorage
|
| 521 |
+
sessionStorage.clear()
|
| 522 |
+
|
| 523 |
+
console.log('🧹 [AuthContext] Cleared all user data from storage')
|
| 524 |
}
|
| 525 |
|
| 526 |
|