feat(vmis): 租戶自動開通完整流程 + Admin Portal SSO + NC 行事曆訂閱
Backend: - schedule_tenant: NC 新容器自動 pgsql 安裝 (_nc_db_check 全新容器處理) - schedule_tenant: NC 初始化加入 Redis + APCu memcache 設定 (修正 OIDC invalid_state) - schedule_tenant: 新租戶 KC realm 自動設定 accessCodeLifespan=600s (修正 authentication_expired) - schedule_account: NC Mail 帳號自動設定 (nc_mail_result/nc_mail_done_at) - schedule_account: NC 台灣國定假日行事曆自動訂閱 (CalDAV MKCALENDAR) - nextcloud_client: 新增 subscribe_calendar() CalDAV 訂閱方法 - settings: 新增系統設定 API (site_title/version/timezone/SSO/Keycloak) - models/result: 新增 nc_mail_result, nc_mail_done_at 欄位 - alembic: 遷移 002(system_settings) 003(keycloak_admin) 004(nc_mail_result) Frontend (Admin Portal): - 新增完整管理後台 (index/tenants/accounts/servers/schedules/logs/settings/system-status) - api.js: Keycloak JS Adapter SSO 整合 (PKCE/S256, fallback KC JS 來源, 自動 token 更新) - index.html: Promise.allSettled 取代 Promise.all,防止單一 API 失敗影響整頁 - 所有頁面加入 try/catch + toast 錯誤處理 - 新增品牌 LOGO 與 favicon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,11 @@ from app.models.account import Account
|
||||
from app.models.schedule import Schedule, ScheduleLog
|
||||
from app.models.result import TenantScheduleResult, AccountScheduleResult
|
||||
from app.models.server import Server, ServerStatusLog, SystemStatusLog
|
||||
from app.models.settings import SystemSettings
|
||||
|
||||
__all__ = [
|
||||
"Tenant", "Account", "Schedule", "ScheduleLog",
|
||||
"TenantScheduleResult", "AccountScheduleResult",
|
||||
"Server", "ServerStatusLog", "SystemStatusLog",
|
||||
"SystemSettings",
|
||||
]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from app.core.utils import now_tw
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -21,8 +22,8 @@ class Account(Base):
|
||||
default_password = Column(String(200))
|
||||
seq_no = Column(Integer, nullable=False) # 同租戶內流水號
|
||||
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
created_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
updated_at = Column(DateTime, nullable=False, default=now_tw, onupdate=now_tw)
|
||||
|
||||
tenant = relationship("Tenant", back_populates="accounts")
|
||||
schedule_results = relationship("AccountScheduleResult", back_populates="account")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from app.core.utils import now_tw
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Float, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -28,7 +29,7 @@ class TenantScheduleResult(Base):
|
||||
|
||||
fail_reason = Column(Text)
|
||||
quota_usage = Column(Float) # GB
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
schedule_log = relationship("ScheduleLog", back_populates="tenant_results")
|
||||
tenant = relationship("Tenant", back_populates="schedule_results")
|
||||
@@ -52,9 +53,12 @@ class AccountScheduleResult(Base):
|
||||
nc_result = Column(Boolean)
|
||||
nc_done_at = Column(DateTime)
|
||||
|
||||
nc_mail_result = Column(Boolean)
|
||||
nc_mail_done_at = Column(DateTime)
|
||||
|
||||
fail_reason = Column(Text)
|
||||
quota_usage = Column(Float) # GB
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
schedule_log = relationship("ScheduleLog", back_populates="account_results")
|
||||
account = relationship("Account", back_populates="schedule_results")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from app.core.utils import now_tw
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -14,7 +15,7 @@ class Schedule(Base):
|
||||
last_run_at = Column(DateTime)
|
||||
next_run_at = Column(DateTime)
|
||||
last_status = Column(String(10)) # ok / error
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
logs = relationship("ScheduleLog", back_populates="schedule")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from app.core.utils import now_tw
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Float, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -13,7 +14,7 @@ class Server(Base):
|
||||
description = Column(String(200))
|
||||
sort_order = Column(Integer, nullable=False, default=0)
|
||||
is_active = Column(Boolean, nullable=False, default=True)
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
status_logs = relationship("ServerStatusLog", back_populates="server")
|
||||
|
||||
@@ -27,7 +28,7 @@ class ServerStatusLog(Base):
|
||||
result = Column(Boolean, nullable=False)
|
||||
response_time = Column(Float) # ms
|
||||
fail_reason = Column(Text)
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
schedule_log = relationship("ScheduleLog", back_populates="server_status_logs")
|
||||
server = relationship("Server", back_populates="status_logs")
|
||||
@@ -43,6 +44,6 @@ class SystemStatusLog(Base):
|
||||
service_desc = Column(String(100))
|
||||
result = Column(Boolean, nullable=False)
|
||||
fail_reason = Column(Text)
|
||||
recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
recorded_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
|
||||
schedule_log = relationship("ScheduleLog", back_populates="system_status_logs")
|
||||
|
||||
22
backend/app/models/settings.py
Normal file
22
backend/app/models/settings.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime
|
||||
from app.core.database import Base
|
||||
from app.core.utils import now_tw
|
||||
|
||||
|
||||
class SystemSettings(Base):
|
||||
__tablename__ = "system_settings"
|
||||
|
||||
id = Column(Integer, primary_key=True, default=1)
|
||||
site_title = Column(String(200), nullable=False, default="VMIS Admin Portal")
|
||||
version = Column(String(50), nullable=False, default="2.0.0")
|
||||
timezone = Column(String(100), nullable=False, default="Asia/Taipei")
|
||||
sso_enabled = Column(Boolean, nullable=False, default=False)
|
||||
# Keycloak — master realm admin (for tenant realm management)
|
||||
keycloak_url = Column(String(200), nullable=False, default="https://auth.lab.taipei")
|
||||
keycloak_admin_user = Column(String(100), nullable=False, default="admin")
|
||||
keycloak_admin_pass = Column(String(200), nullable=False, default="")
|
||||
# Keycloak — Admin Portal SSO
|
||||
keycloak_realm = Column(String(100), nullable=False, default="vmis-admin")
|
||||
keycloak_client = Column(String(100), nullable=False, default="vmis-portal")
|
||||
updated_at = Column(DateTime, nullable=False, default=now_tw, onupdate=now_tw)
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from app.core.utils import now_tw
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -30,8 +31,8 @@ class Tenant(Base):
|
||||
is_active = Column(Boolean, nullable=False, default=True)
|
||||
status = Column(String(20), nullable=False, default="trial") # trial / active / inactive
|
||||
note = Column(Text)
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
created_at = Column(DateTime, nullable=False, default=now_tw)
|
||||
updated_at = Column(DateTime, nullable=False, default=now_tw, onupdate=now_tw)
|
||||
|
||||
accounts = relationship("Account", back_populates="tenant", cascade="all, delete-orphan")
|
||||
schedule_results = relationship("TenantScheduleResult", back_populates="tenant")
|
||||
|
||||
Reference in New Issue
Block a user