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>
127 lines
3.6 KiB
Python
127 lines
3.6 KiB
Python
"""
|
|
郵件帳號 Schemas
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, Field, EmailStr, ConfigDict, field_validator
|
|
|
|
from app.schemas.base import BaseSchema, TimestampSchema
|
|
|
|
|
|
class EmailAccountBase(BaseSchema):
|
|
"""郵件帳號基礎 Schema"""
|
|
|
|
email_address: EmailStr = Field(..., description="郵件地址")
|
|
quota_mb: int = Field(2048, ge=1024, le=102400, description="配額 (MB), 1GB-100GB")
|
|
forward_to: Optional[EmailStr] = Field(None, description="轉寄地址")
|
|
auto_reply: Optional[str] = Field(None, max_length=1000, description="自動回覆內容")
|
|
is_active: bool = Field(True, description="是否啟用")
|
|
|
|
|
|
class EmailAccountCreate(EmailAccountBase):
|
|
"""創建郵件帳號 Schema"""
|
|
|
|
employee_id: int = Field(..., description="員工 ID")
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"employee_id": 1,
|
|
"email_address": "porsche.chen@porscheworld.tw",
|
|
"quota_mb": 2048,
|
|
"forward_to": None,
|
|
"auto_reply": None,
|
|
"is_active": True
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
class EmailAccountUpdate(BaseSchema):
|
|
"""更新郵件帳號 Schema"""
|
|
|
|
quota_mb: Optional[int] = Field(None, ge=1024, le=102400, description="配額 (MB)")
|
|
forward_to: Optional[EmailStr] = Field(None, description="轉寄地址")
|
|
auto_reply: Optional[str] = Field(None, max_length=1000, description="自動回覆內容")
|
|
is_active: Optional[bool] = Field(None, description="是否啟用")
|
|
|
|
@field_validator('forward_to')
|
|
@classmethod
|
|
def validate_forward_to(cls, v):
|
|
"""允許空字串來清除轉寄地址"""
|
|
if v == "":
|
|
return None
|
|
return v
|
|
|
|
@field_validator('auto_reply')
|
|
@classmethod
|
|
def validate_auto_reply(cls, v):
|
|
"""允許空字串來清除自動回覆"""
|
|
if v == "":
|
|
return None
|
|
return v
|
|
|
|
|
|
class EmailAccountInDB(EmailAccountBase, TimestampSchema):
|
|
"""資料庫中的郵件帳號 Schema"""
|
|
|
|
id: int
|
|
tenant_id: int
|
|
employee_id: int
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class EmailAccountResponse(EmailAccountInDB):
|
|
"""郵件帳號響應 Schema (包含關聯資料)"""
|
|
|
|
employee_name: Optional[str] = Field(None, description="員工姓名")
|
|
employee_number: Optional[str] = Field(None, description="員工編號")
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"id": 1,
|
|
"tenant_id": 1,
|
|
"employee_id": 1,
|
|
"email_address": "porsche.chen@porscheworld.tw",
|
|
"quota_mb": 2048,
|
|
"forward_to": None,
|
|
"auto_reply": None,
|
|
"is_active": True,
|
|
"employee_name": "陳保時",
|
|
"employee_number": "EMP001",
|
|
"created_at": "2020-01-01T00:00:00",
|
|
"updated_at": "2020-01-01T00:00:00"
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
class EmailAccountListItem(BaseSchema):
|
|
"""郵件帳號列表項 Schema (簡化版)"""
|
|
|
|
id: int
|
|
email_address: str
|
|
quota_mb: int
|
|
is_active: bool
|
|
employee_id: int
|
|
employee_name: Optional[str] = None
|
|
employee_number: Optional[str] = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class EmailAccountQuotaUpdate(BaseSchema):
|
|
"""郵件配額更新 Schema"""
|
|
|
|
quota_mb: int = Field(..., ge=1024, le=102400, description="配額 (MB), 1GB-100GB")
|
|
|
|
model_config = ConfigDict(
|
|
json_schema_extra={
|
|
"example": {
|
|
"quota_mb": 5120 # 5GB
|
|
}
|
|
}
|
|
)
|