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,
|
email=settings.admin_email,
|
||||||
hashed_password=hashed_password,
|
hashed_password=hashed_password,
|
||||||
role="admin",
|
role="admin",
|
||||||
|
is_super_admin=True,
|
||||||
first_name=settings.admin_first_name,
|
first_name=settings.admin_first_name,
|
||||||
last_name=settings.admin_last_name,
|
last_name=settings.admin_last_name,
|
||||||
is_active=True,
|
is_active=True,
|
||||||
@@ -130,31 +131,77 @@ def create_admin_user(db: Session, auth_manager: AuthManager) -> User:
|
|||||||
return admin
|
return admin
|
||||||
|
|
||||||
|
|
||||||
def create_default_platform(db: Session) -> Platform:
|
def create_default_platforms(db: Session) -> list[Platform]:
|
||||||
"""Create the default OMS platform."""
|
"""Create all default platforms (OMS, Main, Loyalty+)."""
|
||||||
|
|
||||||
|
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"},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
platforms = []
|
||||||
|
for pdef in platform_defs:
|
||||||
existing = db.execute(
|
existing = db.execute(
|
||||||
select(Platform).where(Platform.code == "oms")
|
select(Platform).where(Platform.code == pdef["code"])
|
||||||
).scalar_one_or_none()
|
).scalar_one_or_none()
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
print_warning(f"Platform already exists: {existing.name}")
|
print_warning(f"Platform already exists: {existing.name} ({existing.code})")
|
||||||
return existing
|
platforms.append(existing)
|
||||||
|
continue
|
||||||
|
|
||||||
platform = Platform(
|
platform = Platform(
|
||||||
code="oms",
|
code=pdef["code"],
|
||||||
name="Wizamart OMS",
|
name=pdef["name"],
|
||||||
description="Order Management System for multi-store e-commerce",
|
description=pdef["description"],
|
||||||
domain=settings.platform_domain,
|
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_active=True,
|
||||||
|
is_public=True,
|
||||||
created_at=datetime.now(UTC),
|
created_at=datetime.now(UTC),
|
||||||
updated_at=datetime.now(UTC),
|
updated_at=datetime.now(UTC),
|
||||||
)
|
)
|
||||||
db.add(platform)
|
db.add(platform)
|
||||||
db.flush()
|
db.flush()
|
||||||
|
platforms.append(platform)
|
||||||
print_success(f"Created platform: {platform.name} ({platform.code})")
|
print_success(f"Created platform: {platform.name} ({platform.code})")
|
||||||
return platform
|
|
||||||
|
return platforms
|
||||||
|
|
||||||
|
|
||||||
def create_default_role_templates(db: Session) -> dict:
|
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...")
|
print_step(2, "Creating platform admin...")
|
||||||
admin = create_admin_user(db, auth_manager)
|
admin = create_admin_user(db, auth_manager)
|
||||||
|
|
||||||
# Step 3: Create default platform
|
# Step 3: Create default platforms
|
||||||
print_step(3, "Creating default platform...")
|
print_step(3, "Creating default platforms...")
|
||||||
platform = create_default_platform(db)
|
platforms = create_default_platforms(db)
|
||||||
|
|
||||||
# Step 4: Set up default role templates
|
# Step 4: Set up default role templates
|
||||||
print_step(4, "Setting up role templates...")
|
print_step(4, "Setting up role templates...")
|
||||||
@@ -422,9 +469,11 @@ def print_summary(db: Session):
|
|||||||
# Count records
|
# Count records
|
||||||
user_count = db.query(User).filter(User.role == "admin").count()
|
user_count = db.query(User).filter(User.role == "admin").count()
|
||||||
setting_count = db.query(AdminSetting).count()
|
setting_count = db.query(AdminSetting).count()
|
||||||
|
platform_count = db.query(Platform).count()
|
||||||
|
|
||||||
print("\n📊 Database Status:")
|
print("\n📊 Database Status:")
|
||||||
print(f" Admin users: {user_count}")
|
print(f" Admin users: {user_count}")
|
||||||
|
print(f" Platforms: {platform_count}")
|
||||||
print(f" Admin settings: {setting_count}")
|
print(f" Admin settings: {setting_count}")
|
||||||
|
|
||||||
print("\n" + "─" * 70)
|
print("\n" + "─" * 70)
|
||||||
|
|||||||
Reference in New Issue
Block a user