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:
2026-02-23 20:12:43 +08:00
commit 360533393f
386 changed files with 70353 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
"""
測試 system_functions CRUD API
"""
import psycopg2
import json
conn = psycopg2.connect(
host="10.1.0.20",
port=5433,
database="hr_portal",
user="admin",
password="DC1qaz2wsx"
)
cur = conn.cursor()
print("=" * 60)
print("Test system_functions API")
print("=" * 60)
# Test 1: 取得所有系統功能
print("\n[Test 1] Get all system functions")
cur.execute("""
SELECT id, code, name, function_type, upper_function_id, "order"
FROM system_functions
ORDER BY "order";
""")
results = cur.fetchall()
print(f"Total: {len(results)} records")
for r in results:
indent = " " if r[4] > 0 else ""
node_type = "NODE" if r[3] == 1 else "FUNC"
print(f"{indent}[{r[0]}] {r[1]} - {r[2]} ({node_type})")
# Test 2: 取得樹狀結構
print("\n[Test 2] Get tree structure")
cur.execute("""
SELECT id, code, name, function_type
FROM system_functions
WHERE upper_function_id = 0
ORDER BY "order";
""")
root_nodes = cur.fetchall()
for node in root_nodes:
node_type = "NODE" if node[3] == 1 else "FUNC"
print(f"[{node[0]}] {node[2]} ({node_type})")
# 取得子功能
cur.execute("""
SELECT id, code, name, function_type
FROM system_functions
WHERE upper_function_id = %s
ORDER BY "order";
""", (node[0],))
children = cur.fetchall()
for child in children:
child_type = "NODE" if child[3] == 1 else "FUNC"
print(f" ├── [{child[0]}] {child[2]} ({child_type})")
# Test 3: 篩選功能類型
print("\n[Test 3] Filter by function_type=1 (nodes)")
cur.execute("""
SELECT id, code, name
FROM system_functions
WHERE function_type = 1
ORDER BY "order";
""")
nodes = cur.fetchall()
print(f"Total nodes: {len(nodes)}")
for n in nodes:
print(f" [{n[0]}] {n[1]} - {n[2]}")
# Test 4: 篩選系統管理功能
print("\n[Test 4] Filter by is_mana=true")
cur.execute("""
SELECT id, code, name
FROM system_functions
WHERE is_mana = true
ORDER BY "order";
""")
mana_funcs = cur.fetchall()
print(f"Total: {len(mana_funcs)} records")
for f in mana_funcs:
print(f" [{f[0]}] {f[1]} - {f[2]}")
print("\n" + "=" * 60)
print("All tests passed!")
print("=" * 60)
cur.close()
conn.close()