Improve demo seed
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Seed Demo Users
|
||||
Creates demo user accounts for production demo environment
|
||||
@@ -18,6 +19,7 @@ from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sess
|
||||
from sqlalchemy import select
|
||||
import structlog
|
||||
import uuid
|
||||
import json
|
||||
|
||||
logger = structlog.get_logger()
|
||||
|
||||
@@ -52,6 +54,22 @@ DEMO_USERS = [
|
||||
]
|
||||
|
||||
|
||||
def load_staff_users():
|
||||
"""Load staff users from JSON file"""
|
||||
json_file = Path(__file__).parent / "usuarios_staff_es.json"
|
||||
if not json_file.exists():
|
||||
logger.warning(f"Staff users JSON not found: {json_file}, skipping staff users")
|
||||
return []
|
||||
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Combine both individual and central bakery staff
|
||||
all_staff = data.get("staff_individual_bakery", []) + data.get("staff_central_bakery", [])
|
||||
logger.info(f"Loaded {len(all_staff)} staff users from JSON")
|
||||
return all_staff
|
||||
|
||||
|
||||
async def seed_demo_users():
|
||||
"""Seed demo users into auth database"""
|
||||
|
||||
@@ -74,7 +92,17 @@ async def seed_demo_users():
|
||||
from services.auth.app.models.users import User
|
||||
from datetime import datetime, timezone
|
||||
|
||||
for user_data in DEMO_USERS:
|
||||
# Load staff users from JSON
|
||||
staff_users = load_staff_users()
|
||||
|
||||
# Combine owner users with staff users
|
||||
all_users = DEMO_USERS + staff_users
|
||||
logger.info(f"Seeding {len(all_users)} total users ({len(DEMO_USERS)} owners + {len(staff_users)} staff)")
|
||||
|
||||
created_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
for user_data in all_users:
|
||||
# Check if user already exists
|
||||
result = await session.execute(
|
||||
select(User).where(User.email == user_data["email"])
|
||||
@@ -82,7 +110,8 @@ async def seed_demo_users():
|
||||
existing_user = result.scalar_one_or_none()
|
||||
|
||||
if existing_user:
|
||||
logger.info(f"Demo user already exists: {user_data['email']}")
|
||||
logger.debug(f"Demo user already exists: {user_data['email']}")
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
# Create new demo user
|
||||
@@ -102,10 +131,11 @@ async def seed_demo_users():
|
||||
)
|
||||
|
||||
session.add(user)
|
||||
logger.info(f"Created demo user: {user_data['email']}")
|
||||
created_count += 1
|
||||
logger.debug(f"Created demo user: {user_data['email']} ({user_data.get('role', 'owner')})")
|
||||
|
||||
await session.commit()
|
||||
logger.info("Demo users seeded successfully")
|
||||
logger.info(f"Demo users seeded successfully: {created_count} created, {skipped_count} skipped")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
|
||||
204
services/auth/scripts/demo/usuarios_staff_es.json
Normal file
204
services/auth/scripts/demo/usuarios_staff_es.json
Normal file
@@ -0,0 +1,204 @@
|
||||
{
|
||||
"staff_individual_bakery": [
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000001",
|
||||
"email": "juan.panadero@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Juan Pérez Moreno",
|
||||
"phone": "+34 912 111 001",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "baker",
|
||||
"department": "production",
|
||||
"position": "Panadero Senior",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000002",
|
||||
"email": "ana.ventas@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Ana Rodríguez Sánchez",
|
||||
"phone": "+34 912 111 002",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "sales",
|
||||
"department": "sales",
|
||||
"position": "Responsable de Ventas",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000003",
|
||||
"email": "luis.calidad@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Luis Fernández García",
|
||||
"phone": "+34 912 111 003",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "quality_control",
|
||||
"department": "quality",
|
||||
"position": "Inspector de Calidad",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000004",
|
||||
"email": "carmen.admin@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Carmen López Martínez",
|
||||
"phone": "+34 912 111 004",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "admin",
|
||||
"department": "administration",
|
||||
"position": "Administradora",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000005",
|
||||
"email": "pedro.almacen@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Pedro González Torres",
|
||||
"phone": "+34 912 111 005",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "warehouse",
|
||||
"department": "inventory",
|
||||
"position": "Encargado de Almacén",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000006",
|
||||
"email": "isabel.produccion@panaderiasanpablo.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Isabel Romero Díaz",
|
||||
"phone": "+34 912 111 006",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "production_manager",
|
||||
"department": "production",
|
||||
"position": "Jefa de Producción",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
}
|
||||
],
|
||||
"staff_central_bakery": [
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000011",
|
||||
"email": "roberto.produccion@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Roberto Sánchez Vargas",
|
||||
"phone": "+34 913 222 001",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "production_manager",
|
||||
"department": "production",
|
||||
"position": "Director de Producción",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000012",
|
||||
"email": "sofia.calidad@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Sofía Jiménez Ortega",
|
||||
"phone": "+34 913 222 002",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "quality_control",
|
||||
"department": "quality",
|
||||
"position": "Responsable de Control de Calidad",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000013",
|
||||
"email": "miguel.logistica@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Miguel Herrera Castro",
|
||||
"phone": "+34 913 222 003",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "logistics",
|
||||
"department": "logistics",
|
||||
"position": "Coordinador de Logística",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000014",
|
||||
"email": "elena.ventas@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Elena Morales Ruiz",
|
||||
"phone": "+34 913 222 004",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "sales",
|
||||
"department": "sales",
|
||||
"position": "Directora Comercial",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000015",
|
||||
"email": "javier.compras@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Javier Navarro Prieto",
|
||||
"phone": "+34 913 222 005",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "procurement",
|
||||
"department": "procurement",
|
||||
"position": "Responsable de Compras",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
},
|
||||
{
|
||||
"id": "50000000-0000-0000-0000-000000000016",
|
||||
"email": "laura.mantenimiento@panaderialaespiga.com",
|
||||
"password_hash": "$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYVPWzO8hGi",
|
||||
"full_name": "Laura Delgado Santos",
|
||||
"phone": "+34 913 222 006",
|
||||
"language": "es",
|
||||
"timezone": "Europe/Madrid",
|
||||
"role": "maintenance",
|
||||
"department": "maintenance",
|
||||
"position": "Técnica de Mantenimiento",
|
||||
"is_active": true,
|
||||
"is_verified": true,
|
||||
"is_demo": true
|
||||
}
|
||||
],
|
||||
"notas": {
|
||||
"password_comun": "DemoStaff2024!",
|
||||
"total_staff": 12,
|
||||
"roles": {
|
||||
"individual_bakery": ["baker", "sales", "quality_control", "admin", "warehouse", "production_manager"],
|
||||
"central_bakery": ["production_manager", "quality_control", "logistics", "sales", "procurement", "maintenance"]
|
||||
},
|
||||
"departamentos": [
|
||||
"production",
|
||||
"sales",
|
||||
"quality",
|
||||
"administration",
|
||||
"inventory",
|
||||
"logistics",
|
||||
"procurement",
|
||||
"maintenance"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user