fix demo load
This commit is contained in:
@@ -49,6 +49,7 @@ DEMO_ALLOWED_OPERATIONS = {
|
|||||||
"/api/v1/production/batches",
|
"/api/v1/production/batches",
|
||||||
"/api/v1/tenants/batch/sales-summary",
|
"/api/v1/tenants/batch/sales-summary",
|
||||||
"/api/v1/tenants/batch/production-summary",
|
"/api/v1/tenants/batch/production-summary",
|
||||||
|
"/api/v1/auth/me/onboarding/complete", # Allow completing onboarding (no-op for demos)
|
||||||
# Note: Forecast generation is explicitly blocked (see DEMO_BLOCKED_PATHS)
|
# Note: Forecast generation is explicitly blocked (see DEMO_BLOCKED_PATHS)
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ DEMO_ALLOWED_OPERATIONS = {
|
|||||||
"/api/v1/pos/sales/*",
|
"/api/v1/pos/sales/*",
|
||||||
"/api/v1/orders/*",
|
"/api/v1/orders/*",
|
||||||
"/api/v1/inventory/stock/*",
|
"/api/v1/inventory/stock/*",
|
||||||
|
"/api/v1/auth/me/onboarding/step", # Allow onboarding step updates (no-op for demos)
|
||||||
],
|
],
|
||||||
|
|
||||||
# Blocked operations
|
# Blocked operations
|
||||||
|
|||||||
@@ -519,8 +519,37 @@ async def get_user_progress(
|
|||||||
"""Get current user's onboarding progress"""
|
"""Get current user's onboarding progress"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
user_id = current_user["user_id"]
|
||||||
|
is_demo = current_user.get("is_demo", False)
|
||||||
|
|
||||||
|
# DEMO FIX: Demo users don't need onboarding - return fully completed progress
|
||||||
|
# Demo tenants are pre-configured through cloning, so onboarding is not required
|
||||||
|
if is_demo or user_id.startswith("demo-user-"):
|
||||||
|
logger.info(f"Demo user {user_id} accessing onboarding progress - returning completed state")
|
||||||
|
|
||||||
|
# Create all steps as completed for demo users
|
||||||
|
demo_steps = []
|
||||||
|
for step_name in ONBOARDING_STEPS:
|
||||||
|
demo_steps.append(OnboardingStepStatus(
|
||||||
|
step_name=step_name,
|
||||||
|
completed=True,
|
||||||
|
completed_at=datetime.now(timezone.utc),
|
||||||
|
data={"auto_completed": True, "demo_mode": True}
|
||||||
|
))
|
||||||
|
|
||||||
|
return UserProgress(
|
||||||
|
user_id=user_id,
|
||||||
|
steps=demo_steps,
|
||||||
|
current_step="completion",
|
||||||
|
next_step=None,
|
||||||
|
completion_percentage=100.0,
|
||||||
|
fully_completed=True,
|
||||||
|
last_updated=datetime.now(timezone.utc)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Regular user flow
|
||||||
onboarding_service = OnboardingService(db)
|
onboarding_service = OnboardingService(db)
|
||||||
progress = await onboarding_service.get_user_progress(current_user["user_id"])
|
progress = await onboarding_service.get_user_progress(user_id)
|
||||||
return progress
|
return progress
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -552,6 +581,31 @@ async def get_user_progress_by_id(
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# DEMO FIX: Handle demo users - return fully completed progress
|
||||||
|
if user_id.startswith("demo-user-"):
|
||||||
|
logger.info(f"Service requesting demo user {user_id} onboarding progress - returning completed state")
|
||||||
|
|
||||||
|
# Create all steps as completed for demo users
|
||||||
|
demo_steps = []
|
||||||
|
for step_name in ONBOARDING_STEPS:
|
||||||
|
demo_steps.append(OnboardingStepStatus(
|
||||||
|
step_name=step_name,
|
||||||
|
completed=True,
|
||||||
|
completed_at=datetime.now(timezone.utc),
|
||||||
|
data={"auto_completed": True, "demo_mode": True}
|
||||||
|
))
|
||||||
|
|
||||||
|
return UserProgress(
|
||||||
|
user_id=user_id,
|
||||||
|
steps=demo_steps,
|
||||||
|
current_step="completion",
|
||||||
|
next_step=None,
|
||||||
|
completion_percentage=100.0,
|
||||||
|
fully_completed=True,
|
||||||
|
last_updated=datetime.now(timezone.utc)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Regular user flow
|
||||||
onboarding_service = OnboardingService(db)
|
onboarding_service = OnboardingService(db)
|
||||||
progress = await onboarding_service.get_user_progress(user_id)
|
progress = await onboarding_service.get_user_progress(user_id)
|
||||||
return progress
|
return progress
|
||||||
@@ -572,9 +626,37 @@ async def update_onboarding_step(
|
|||||||
"""Update a specific onboarding step"""
|
"""Update a specific onboarding step"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
user_id = current_user["user_id"]
|
||||||
|
is_demo = current_user.get("is_demo", False)
|
||||||
|
|
||||||
|
# DEMO FIX: Demo users don't update onboarding - return completed progress
|
||||||
|
if is_demo or user_id.startswith("demo-user-"):
|
||||||
|
logger.info(f"Demo user {user_id} attempting to update onboarding step - returning completed state (no-op)")
|
||||||
|
|
||||||
|
# Create all steps as completed for demo users
|
||||||
|
demo_steps = []
|
||||||
|
for step_name in ONBOARDING_STEPS:
|
||||||
|
demo_steps.append(OnboardingStepStatus(
|
||||||
|
step_name=step_name,
|
||||||
|
completed=True,
|
||||||
|
completed_at=datetime.now(timezone.utc),
|
||||||
|
data={"auto_completed": True, "demo_mode": True}
|
||||||
|
))
|
||||||
|
|
||||||
|
return UserProgress(
|
||||||
|
user_id=user_id,
|
||||||
|
steps=demo_steps,
|
||||||
|
current_step="completion",
|
||||||
|
next_step=None,
|
||||||
|
completion_percentage=100.0,
|
||||||
|
fully_completed=True,
|
||||||
|
last_updated=datetime.now(timezone.utc)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Regular user flow
|
||||||
onboarding_service = OnboardingService(db)
|
onboarding_service = OnboardingService(db)
|
||||||
progress = await onboarding_service.update_step(
|
progress = await onboarding_service.update_step(
|
||||||
current_user["user_id"],
|
user_id,
|
||||||
update_request
|
update_request
|
||||||
)
|
)
|
||||||
return progress
|
return progress
|
||||||
@@ -638,8 +720,22 @@ async def complete_onboarding(
|
|||||||
"""Complete entire onboarding process"""
|
"""Complete entire onboarding process"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
user_id = current_user["user_id"]
|
||||||
|
is_demo = current_user.get("is_demo", False)
|
||||||
|
|
||||||
|
# DEMO FIX: Demo users don't need to complete onboarding - return success
|
||||||
|
if is_demo or user_id.startswith("demo-user-"):
|
||||||
|
logger.info(f"Demo user {user_id} attempting to complete onboarding - returning success (no-op)")
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "Onboarding already completed for demo account",
|
||||||
|
"optional_steps_skipped": [],
|
||||||
|
"demo_mode": True
|
||||||
|
}
|
||||||
|
|
||||||
|
# Regular user flow
|
||||||
onboarding_service = OnboardingService(db)
|
onboarding_service = OnboardingService(db)
|
||||||
result = await onboarding_service.complete_onboarding(current_user["user_id"])
|
result = await onboarding_service.complete_onboarding(user_id)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
|
|||||||
Reference in New Issue
Block a user