feat: HR Portal - Complete Multi-Tenant System with Redis Session Storage
Major Features: - ✅ Multi-tenant architecture (tenant isolation) - ✅ Employee CRUD with lifecycle management (onboarding/offboarding) - ✅ Department tree structure with email domain management - ✅ Company info management (single-record editing) - ✅ System functions CRUD (permission management) - ✅ Email account management (multi-account per employee) - ✅ Keycloak SSO integration (auth.lab.taipei) - ✅ Redis session storage (10.1.0.254:6379) - Solves Cookie 4KB limitation - Cross-system session sharing - Sliding expiration (8 hours) - Automatic token refresh Technical Stack: Backend: - FastAPI + SQLAlchemy - PostgreSQL 16 (10.1.0.20:5433) - Keycloak Admin API integration - Docker Mailserver integration (SSH) - Alembic migrations Frontend: - Next.js 14 (App Router) - NextAuth 4 with Keycloak Provider - Redis session storage (ioredis) - Tailwind CSS Infrastructure: - Redis 7 (10.1.0.254:6379) - Session + Cache - Keycloak 26.1.0 (auth.lab.taipei) - Docker Mailserver (10.1.0.254) Architecture Highlights: - Session管理由 Keycloak + Redis 統一控制 - 支援多系統 (HR/WebMail/Calendar/Drive/Office) 共享 session - Token 自動刷新,異質服務整合 - 未來可無縫遷移到雲端 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
83
test_backend_startup.py
Normal file
83
test_backend_startup.py
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""測試 HR Portal 後端啟動"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加 backend 路徑
|
||||
backend_path = os.path.join(os.path.dirname(__file__), 'backend')
|
||||
sys.path.insert(0, backend_path)
|
||||
|
||||
print("=" * 60)
|
||||
print("HR Portal 後端啟動測試")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
# 載入環境變數
|
||||
print("\n[1] 載入環境變數...")
|
||||
from dotenv import load_dotenv
|
||||
env_path = os.path.join(backend_path, '.env')
|
||||
load_dotenv(env_path)
|
||||
|
||||
print(f" PROJECT_NAME: {os.getenv('PROJECT_NAME')}")
|
||||
print(f" ENVIRONMENT: {os.getenv('ENVIRONMENT')}")
|
||||
print(f" PORT: {os.getenv('PORT')}")
|
||||
|
||||
# 測試導入核心模組
|
||||
print("\n[2] 導入核心模組...")
|
||||
|
||||
print(" 導入 config...")
|
||||
from app.core.config import settings
|
||||
print(f" [OK] Project: {settings.PROJECT_NAME}")
|
||||
print(f" [OK] Port: {settings.PORT}")
|
||||
|
||||
print(" 導入 database...")
|
||||
from app.db.session import get_engine, get_db
|
||||
engine = get_engine()
|
||||
print(f" [OK] Database engine: {engine.url}")
|
||||
|
||||
print(" 導入 models...")
|
||||
from app.models.employee import Employee
|
||||
from app.models.department import Department
|
||||
from app.models.business_unit import BusinessUnit
|
||||
print(" [OK] Models imported")
|
||||
|
||||
# 測試資料庫連接
|
||||
print("\n[3] 測試資料庫連接...")
|
||||
with engine.connect() as conn:
|
||||
from sqlalchemy import text
|
||||
result = conn.execute(text("SELECT 1"))
|
||||
print(" [OK] Database connection successful")
|
||||
|
||||
# 測試創建 FastAPI 應用
|
||||
print("\n[4] 測試 FastAPI 應用...")
|
||||
from app.main import app
|
||||
print(f" [OK] FastAPI app created")
|
||||
print(f" [OK] Title: {app.title}")
|
||||
print(f" [OK] Version: {app.version}")
|
||||
|
||||
# 列出所有路由
|
||||
print("\n[5] API 路由列表:")
|
||||
routes = []
|
||||
for route in app.routes:
|
||||
if hasattr(route, 'methods') and hasattr(route, 'path'):
|
||||
for method in route.methods:
|
||||
if method != 'HEAD': # 跳過 HEAD
|
||||
routes.append(f" {method:7} {route.path}")
|
||||
|
||||
for route in sorted(set(routes)):
|
||||
print(route)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("後端模組載入成功!")
|
||||
print("=" * 60)
|
||||
print("\n提示: 使用以下命令啟動後端:")
|
||||
print(" cd backend")
|
||||
print(" uvicorn app.main:app --host 0.0.0.0 --port 10181 --reload")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n[FAIL] 測試失敗: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user