feat: add multi-tenant system with properties, organizations, and public booking
Implement complete multi-property architecture: - Properties (groups of spaces) with public/private visibility - Property managers (many-to-many) with role-based permissions - Organizations with member management - Anonymous/guest booking support via public API (/api/public/*) - Property-scoped spaces, bookings, and settings - Frontend: property selector, organization management, public booking views - Migration script and updated seed data Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
"""Seed database with initial data."""
|
||||
"""Seed database with initial data for multi-property system."""
|
||||
from app.core.security import get_password_hash
|
||||
from app.db.session import Base, SessionLocal, engine
|
||||
from app.models.organization import Organization
|
||||
from app.models.organization_member import OrganizationMember
|
||||
from app.models.property import Property
|
||||
from app.models.property_access import PropertyAccess
|
||||
from app.models.property_manager import PropertyManager
|
||||
from app.models.settings import Settings
|
||||
from app.models.space import Space
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
def seed_database() -> None:
|
||||
"""Create initial users for testing."""
|
||||
"""Create initial data for testing multi-property system."""
|
||||
# Create tables
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
@@ -18,16 +24,27 @@ def seed_database() -> None:
|
||||
print("Database already seeded. Skipping...")
|
||||
return
|
||||
|
||||
# Create admin user
|
||||
admin = User(
|
||||
# Create superadmin user
|
||||
superadmin = User(
|
||||
email="admin@example.com",
|
||||
full_name="Admin User",
|
||||
full_name="Super Admin",
|
||||
hashed_password=get_password_hash("adminpassword"),
|
||||
role="admin",
|
||||
role="superadmin",
|
||||
organization="Management",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(admin)
|
||||
db.add(superadmin)
|
||||
|
||||
# Create manager user
|
||||
manager = User(
|
||||
email="manager@example.com",
|
||||
full_name="Property Manager",
|
||||
hashed_password=get_password_hash("managerpassword"),
|
||||
role="manager",
|
||||
organization="Management",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(manager)
|
||||
|
||||
# Create regular user
|
||||
user = User(
|
||||
@@ -40,6 +57,93 @@ def seed_database() -> None:
|
||||
)
|
||||
db.add(user)
|
||||
|
||||
db.flush() # Get IDs
|
||||
|
||||
# Create properties
|
||||
prop1 = Property(
|
||||
name="Clădirea Centrală",
|
||||
description="Clădirea principală din centru",
|
||||
address="Str. Principală nr. 1",
|
||||
is_public=True,
|
||||
is_active=True,
|
||||
)
|
||||
db.add(prop1)
|
||||
|
||||
prop2 = Property(
|
||||
name="Biroul Privat",
|
||||
description="Spațiu privat pentru echipă",
|
||||
address="Str. Secundară nr. 5",
|
||||
is_public=False,
|
||||
is_active=True,
|
||||
)
|
||||
db.add(prop2)
|
||||
|
||||
db.flush() # Get property IDs
|
||||
|
||||
# Assign manager to both properties
|
||||
db.add(PropertyManager(property_id=prop1.id, user_id=manager.id))
|
||||
db.add(PropertyManager(property_id=prop2.id, user_id=manager.id))
|
||||
|
||||
# Create spaces (2 in first property, 1 in second)
|
||||
space1 = Space(
|
||||
name="Sala Mare",
|
||||
type="sala",
|
||||
capacity=20,
|
||||
description="Sală de conferințe mare",
|
||||
is_active=True,
|
||||
property_id=prop1.id,
|
||||
)
|
||||
db.add(space1)
|
||||
|
||||
space2 = Space(
|
||||
name="Birou A1",
|
||||
type="birou",
|
||||
capacity=4,
|
||||
description="Birou deschis",
|
||||
is_active=True,
|
||||
property_id=prop1.id,
|
||||
)
|
||||
db.add(space2)
|
||||
|
||||
space3 = Space(
|
||||
name="Sala Privată",
|
||||
type="sala",
|
||||
capacity=10,
|
||||
description="Sală privată pentru echipă",
|
||||
is_active=True,
|
||||
property_id=prop2.id,
|
||||
)
|
||||
db.add(space3)
|
||||
|
||||
# Create organizations
|
||||
org1 = Organization(
|
||||
name="Engineering",
|
||||
description="Echipa de dezvoltare",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(org1)
|
||||
|
||||
org2 = Organization(
|
||||
name="Management",
|
||||
description="Echipa de management",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(org2)
|
||||
|
||||
db.flush() # Get org IDs
|
||||
|
||||
# Create organization members
|
||||
db.add(OrganizationMember(organization_id=org1.id, user_id=user.id, role="member"))
|
||||
db.add(OrganizationMember(organization_id=org2.id, user_id=manager.id, role="admin"))
|
||||
db.add(OrganizationMember(organization_id=org2.id, user_id=superadmin.id, role="admin"))
|
||||
|
||||
# Grant user access to private property
|
||||
db.add(PropertyAccess(
|
||||
property_id=prop2.id,
|
||||
user_id=user.id,
|
||||
granted_by=manager.id,
|
||||
))
|
||||
|
||||
# Create default settings if not exist
|
||||
existing_settings = db.query(Settings).filter(Settings.id == 1).first()
|
||||
if not existing_settings:
|
||||
@@ -55,9 +159,12 @@ def seed_database() -> None:
|
||||
db.add(default_settings)
|
||||
|
||||
db.commit()
|
||||
print("✓ Database seeded successfully!")
|
||||
print("Admin: admin@example.com / adminpassword")
|
||||
print("Database seeded successfully!")
|
||||
print("Superadmin: admin@example.com / adminpassword")
|
||||
print("Manager: manager@example.com / managerpassword")
|
||||
print("User: user@example.com / userpassword")
|
||||
print(f"Properties: '{prop1.name}' (public), '{prop2.name}' (private)")
|
||||
print(f"Organizations: '{org1.name}', '{org2.name}'")
|
||||
except Exception as e:
|
||||
print(f"Error seeding database: {e}")
|
||||
db.rollback()
|
||||
|
||||
Reference in New Issue
Block a user