feat(init): create all 3 platforms and make admin super_admin
Admin user is now created with is_super_admin=True for full platform access. Replaced single OMS platform creation with all 3 platforms: oms, main (Wizamart marketing site), and loyalty (Loyalty+). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -115,6 +115,7 @@ def create_admin_user(db: Session, auth_manager: AuthManager) -> User:
|
||||
email=settings.admin_email,
|
||||
hashed_password=hashed_password,
|
||||
role="admin",
|
||||
is_super_admin=True,
|
||||
first_name=settings.admin_first_name,
|
||||
last_name=settings.admin_last_name,
|
||||
is_active=True,
|
||||
@@ -130,31 +131,77 @@ def create_admin_user(db: Session, auth_manager: AuthManager) -> User:
|
||||
return admin
|
||||
|
||||
|
||||
def create_default_platform(db: Session) -> Platform:
|
||||
"""Create the default OMS platform."""
|
||||
def create_default_platforms(db: Session) -> list[Platform]:
|
||||
"""Create all default platforms (OMS, Main, Loyalty+)."""
|
||||
|
||||
existing = db.execute(
|
||||
select(Platform).where(Platform.code == "oms")
|
||||
).scalar_one_or_none()
|
||||
platform_defs = [
|
||||
{
|
||||
"code": "oms",
|
||||
"name": "Wizamart OMS",
|
||||
"description": "Order Management System for multi-store e-commerce",
|
||||
"domain": settings.platform_domain,
|
||||
"path_prefix": "oms",
|
||||
"default_language": "fr",
|
||||
"supported_languages": ["fr", "de", "en"],
|
||||
"settings": {},
|
||||
"theme_config": {},
|
||||
},
|
||||
{
|
||||
"code": "main",
|
||||
"name": "Wizamart",
|
||||
"description": "Main marketing site showcasing all Wizamart platforms",
|
||||
"domain": "wizamart.lu",
|
||||
"path_prefix": None,
|
||||
"default_language": "fr",
|
||||
"supported_languages": ["fr", "de", "en"],
|
||||
"settings": {"is_marketing_site": True},
|
||||
"theme_config": {"primary_color": "#2563EB", "secondary_color": "#3B82F6"},
|
||||
},
|
||||
{
|
||||
"code": "loyalty",
|
||||
"name": "Loyalty+",
|
||||
"description": "Customer loyalty program platform for Luxembourg businesses",
|
||||
"domain": "loyalty.lu",
|
||||
"path_prefix": "loyalty",
|
||||
"default_language": "fr",
|
||||
"supported_languages": ["fr", "de", "en"],
|
||||
"settings": {"features": ["points", "rewards", "tiers", "analytics"]},
|
||||
"theme_config": {"primary_color": "#8B5CF6", "secondary_color": "#A78BFA"},
|
||||
},
|
||||
]
|
||||
|
||||
if existing:
|
||||
print_warning(f"Platform already exists: {existing.name}")
|
||||
return existing
|
||||
platforms = []
|
||||
for pdef in platform_defs:
|
||||
existing = db.execute(
|
||||
select(Platform).where(Platform.code == pdef["code"])
|
||||
).scalar_one_or_none()
|
||||
|
||||
platform = Platform(
|
||||
code="oms",
|
||||
name="Wizamart OMS",
|
||||
description="Order Management System for multi-store e-commerce",
|
||||
domain=settings.platform_domain,
|
||||
is_active=True,
|
||||
created_at=datetime.now(UTC),
|
||||
updated_at=datetime.now(UTC),
|
||||
)
|
||||
db.add(platform)
|
||||
db.flush()
|
||||
if existing:
|
||||
print_warning(f"Platform already exists: {existing.name} ({existing.code})")
|
||||
platforms.append(existing)
|
||||
continue
|
||||
|
||||
print_success(f"Created platform: {platform.name} ({platform.code})")
|
||||
return platform
|
||||
platform = Platform(
|
||||
code=pdef["code"],
|
||||
name=pdef["name"],
|
||||
description=pdef["description"],
|
||||
domain=pdef["domain"],
|
||||
path_prefix=pdef["path_prefix"],
|
||||
default_language=pdef["default_language"],
|
||||
supported_languages=pdef["supported_languages"],
|
||||
settings=pdef["settings"],
|
||||
theme_config=pdef["theme_config"],
|
||||
is_active=True,
|
||||
is_public=True,
|
||||
created_at=datetime.now(UTC),
|
||||
updated_at=datetime.now(UTC),
|
||||
)
|
||||
db.add(platform)
|
||||
db.flush()
|
||||
platforms.append(platform)
|
||||
print_success(f"Created platform: {platform.name} ({platform.code})")
|
||||
|
||||
return platforms
|
||||
|
||||
|
||||
def create_default_role_templates(db: Session) -> dict:
|
||||
@@ -397,9 +444,9 @@ def initialize_production(db: Session, auth_manager: AuthManager):
|
||||
print_step(2, "Creating platform admin...")
|
||||
admin = create_admin_user(db, auth_manager)
|
||||
|
||||
# Step 3: Create default platform
|
||||
print_step(3, "Creating default platform...")
|
||||
platform = create_default_platform(db)
|
||||
# Step 3: Create default platforms
|
||||
print_step(3, "Creating default platforms...")
|
||||
platforms = create_default_platforms(db)
|
||||
|
||||
# Step 4: Set up default role templates
|
||||
print_step(4, "Setting up role templates...")
|
||||
@@ -422,9 +469,11 @@ def print_summary(db: Session):
|
||||
# Count records
|
||||
user_count = db.query(User).filter(User.role == "admin").count()
|
||||
setting_count = db.query(AdminSetting).count()
|
||||
platform_count = db.query(Platform).count()
|
||||
|
||||
print("\n📊 Database Status:")
|
||||
print(f" Admin users: {user_count}")
|
||||
print(f" Platforms: {platform_count}")
|
||||
print(f" Admin settings: {setting_count}")
|
||||
|
||||
print("\n" + "─" * 70)
|
||||
|
||||
Reference in New Issue
Block a user