fix: skip NC/Mail steps for manager tenant in account scheduler
Manager tenant accounts don't have an NC container, so NC user creation and Mail setup should be skipped (marked as success). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -77,6 +77,13 @@ def run_account_check(schedule_log_id: int, db: Session):
|
||||
result.mailbox_done_at = now_tw()
|
||||
fail_reasons.append(f"mailbox: {e}")
|
||||
|
||||
# [3] NC user + Mail(manager 租戶無 NC container,跳過)
|
||||
if tenant.is_manager:
|
||||
result.nc_result = True
|
||||
result.nc_done_at = now_tw()
|
||||
result.nc_mail_result = True
|
||||
result.nc_mail_done_at = now_tw()
|
||||
else:
|
||||
# [3] NC user check
|
||||
try:
|
||||
from app.core.config import settings as _cfg
|
||||
@@ -97,7 +104,6 @@ def run_account_check(schedule_log_id: int, db: Session):
|
||||
fail_reasons.append(f"nc: {e}")
|
||||
|
||||
# [3.5] NC 台灣國定假日行事曆訂閱
|
||||
# 前置條件:NC 帳號已存在;MKCALENDAR 為 idempotent(已存在回傳 405 視為成功)
|
||||
TW_HOLIDAYS_ICS_URL = "https://www.officeholidays.com/ics-clean/taiwan"
|
||||
if result.nc_result:
|
||||
try:
|
||||
@@ -116,7 +122,6 @@ def run_account_check(schedule_log_id: int, db: Session):
|
||||
logger.warning(f"NC calendar subscribe error [{account.sso_account}]: {e}")
|
||||
|
||||
# [4] NC Mail 帳號設定
|
||||
# 前置條件:NC 帳號已建立 + mailbox 已建立
|
||||
try:
|
||||
if result.nc_result and result.mailbox_result:
|
||||
import paramiko
|
||||
@@ -130,7 +135,6 @@ def run_account_check(schedule_log_id: int, db: Session):
|
||||
ssh.connect(_cfg.DOCKER_SSH_HOST, username=_cfg.DOCKER_SSH_USER, timeout=15)
|
||||
|
||||
def _ssh_run(cmd, timeout=60):
|
||||
"""執行 SSH 指令並回傳輸出,超時返回空字串"""
|
||||
_, stdout, _ = ssh.exec_command(cmd)
|
||||
stdout.channel.settimeout(timeout)
|
||||
try:
|
||||
@@ -139,7 +143,6 @@ def run_account_check(schedule_log_id: int, db: Session):
|
||||
out = ""
|
||||
return out
|
||||
|
||||
# 確認是否已設定(occ mail:account:export 回傳帳號列表)
|
||||
export_out = _ssh_run(
|
||||
f"docker exec -u www-data {nc_container} "
|
||||
f"php /var/www/html/occ mail:account:export {account.sso_account} 2>/dev/null"
|
||||
|
||||
Reference in New Issue
Block a user