Refactor to manager-centric model, add team calendar for all users

Key changes:
- Removed office-centric model (deleted offices.py, office-rules)
- Renamed to team-rules, managers are part of their own team
- Team calendar visible to all (read-only for employees)
- Admins can have a manager assigned
This commit is contained in:
Stefano Manfredi
2025-12-02 13:30:04 +00:00
parent 2ad8ba3424
commit 7168fa4b72
30 changed files with 1016 additions and 910 deletions

View File

@@ -3,19 +3,14 @@ Create test database with sample data
Run: .venv/bin/python create_test_db.py
Manager-centric model:
- Users have a manager_id pointing to their manager
- Managers own parking spots (manager_parking_quota)
- Each manager has a spot prefix (A, B, C...) for display names
- Offices are containers for employees (like LDAP groups)
LDAP Group Simulation:
- parking_admin: admin role
- parking_manager: manager role
- office groups (presales, design, operations): employee office assignment
"""
import uuid
from datetime import datetime, timezone
from database.connection import engine, SessionLocal
from database.models import Base, User, Office, OfficeMembership
from database.models import Base, User
from services.auth import hash_password
# Drop and recreate all tables for clean slate
@@ -27,29 +22,8 @@ db = SessionLocal()
now = datetime.now(timezone.utc).isoformat()
password_hash = hash_password("password123")
# Create offices (representing LDAP groups)
offices = [
Office(id="presales", name="Presales", location="Building A", created_at=now),
Office(id="design", name="Design", location="Building B", created_at=now),
Office(id="operations", name="Operations", location="Building C", created_at=now),
]
for office in offices:
db.add(office)
print(f"Created office: {office.name}")
db.commit()
# Create users
# LDAP groups simulation:
# admin: parking_admin, presales
# manager1: parking_manager, presales, design
# manager2: parking_manager, operations
# user1: presales
# user2: design
# user3: design
# user4: operations
# user5: operations
# Create users with manager-centric model
# manager_id points to the user's manager
users_data = [
{
@@ -57,15 +31,15 @@ users_data = [
"email": "admin@example.com",
"name": "Admin User",
"role": "admin",
"office_id": "presales", # Primary office from LDAP groups
"manager_id": None, # Admins don't have managers
},
{
"id": "manager1",
"email": "manager1@example.com",
"name": "Alice Manager",
"role": "manager",
"office_id": "presales",
"manager_parking_quota": 3, # For 5 users: admin, alice, user1, user2, user3
"manager_id": None, # Managers don't have managers
"manager_parking_quota": 3,
"manager_spot_prefix": "A",
},
{
@@ -73,8 +47,8 @@ users_data = [
"email": "manager2@example.com",
"name": "Bob Manager",
"role": "manager",
"office_id": "operations",
"manager_parking_quota": 2, # For 3 users: bob, user4, user5
"manager_id": None,
"manager_parking_quota": 2,
"manager_spot_prefix": "B",
},
{
@@ -82,35 +56,35 @@ users_data = [
"email": "user1@example.com",
"name": "User One",
"role": "employee",
"office_id": "presales",
"manager_id": "manager1", # Managed by Alice
},
{
"id": "user2",
"email": "user2@example.com",
"name": "User Two",
"role": "employee",
"office_id": "design",
"manager_id": "manager1", # Managed by Alice
},
{
"id": "user3",
"email": "user3@example.com",
"name": "User Three",
"role": "employee",
"office_id": "design",
"manager_id": "manager1", # Managed by Alice
},
{
"id": "user4",
"email": "user4@example.com",
"name": "User Four",
"role": "employee",
"office_id": "operations",
"manager_id": "manager2", # Managed by Bob
},
{
"id": "user5",
"email": "user5@example.com",
"name": "User Five",
"role": "employee",
"office_id": "operations",
"manager_id": "manager2", # Managed by Bob
},
]
@@ -121,7 +95,7 @@ for data in users_data:
password_hash=password_hash,
name=data["name"],
role=data["role"],
office_id=data.get("office_id"),
manager_id=data.get("manager_id"),
manager_parking_quota=data.get("manager_parking_quota", 0),
manager_spot_prefix=data.get("manager_spot_prefix"),
created_at=now
@@ -129,30 +103,6 @@ for data in users_data:
db.add(user)
print(f"Created user: {user.email} ({user.role})")
db.commit()
# Create office memberships for managers
# Manager 1 (Alice) manages Presales and Design
for office_id in ["presales", "design"]:
membership = OfficeMembership(
id=str(uuid.uuid4()),
user_id="manager1",
office_id=office_id,
created_at=now
)
db.add(membership)
print(f"Created membership: Alice -> {office_id}")
# Manager 2 (Bob) manages Operations
membership = OfficeMembership(
id=str(uuid.uuid4()),
user_id="manager2",
office_id="operations",
created_at=now
)
db.add(membership)
print(f"Created membership: Bob -> operations")
db.commit()
db.close()
@@ -161,23 +111,22 @@ print("Test database created successfully!")
print("="*60)
print("\nTest accounts (all use password: password123):")
print("-"*60)
print(f"{'Email':<25} {'Role':<10} {'Office':<12} {'Spots'}")
print(f"{'Email':<25} {'Role':<10} {'Manager':<15}")
print("-"*60)
print(f"{'admin@example.com':<25} {'admin':<10} {'presales':<12}")
print(f"{'manager1@example.com':<25} {'manager':<10} {'presales':<12}")
print(f"{'manager2@example.com':<25} {'manager':<10} {'operations':<12}")
print(f"{'user1@example.com':<25} {'employee':<10} {'presales':<12}")
print(f"{'user2@example.com':<25} {'employee':<10} {'design':<12}")
print(f"{'user3@example.com':<25} {'employee':<10} {'design':<12}")
print(f"{'user4@example.com':<25} {'employee':<10} {'operations':<12}")
print(f"{'user5@example.com':<25} {'employee':<10} {'operations':<12}")
print(f"{'admin@example.com':<25} {'admin':<10} {'-':<15}")
print(f"{'manager1@example.com':<25} {'manager':<10} {'-':<15}")
print(f"{'manager2@example.com':<25} {'manager':<10} {'-':<15}")
print(f"{'user1@example.com':<25} {'employee':<10} {'Alice':<15}")
print(f"{'user2@example.com':<25} {'employee':<10} {'Alice':<15}")
print(f"{'user3@example.com':<25} {'employee':<10} {'Alice':<15}")
print(f"{'user4@example.com':<25} {'employee':<10} {'Bob':<15}")
print(f"{'user5@example.com':<25} {'employee':<10} {'Bob':<15}")
print("-"*60)
print("\nParking pools:")
print(" Alice (manager1): 3 spots (A1,A2,A3)")
print(" -> presales: admin, alice, user1")
print(" -> design: user2, user3")
print(" -> 5 users, 3 spots = 60% ratio target")
print(" -> manages: user1, user2, user3")
print(" -> 3 users, 3 spots = 100% ratio target")
print()
print(" Bob (manager2): 2 spots (B1,B2)")
print(" -> operations: bob, user4, user5")
print(" -> 3 users, 2 spots = 67% ratio target")
print(" -> manages: user4, user5")
print(" -> 2 users, 2 spots = 100% ratio target")