This commit is contained in:
beabigegg
2025-09-01 09:16:14 +08:00
parent 45a42f8e64
commit 8185b609f7
4 changed files with 545 additions and 39 deletions

View File

@@ -117,18 +117,18 @@ def upload_excel():
# 狀態
status_mapping = {
'新建': 'NEW', '進行中': 'IN_PROGRESS', '完成': 'DONE',
'NEW': 'NEW', 'IN_PROGRESS': 'IN_PROGRESS', 'DONE': 'DONE',
'': 'NEW', '進行': 'IN_PROGRESS', '': 'DONE'
'新建': 'NEW', '進行中': 'DOING', '完成': 'DONE', '阻塞': 'BLOCKED',
'NEW': 'NEW', 'DOING': 'DOING', 'DONE': 'DONE', 'BLOCKED': 'BLOCKED',
'': 'NEW', '進行': 'DOING', '': 'DONE', '': 'BLOCKED'
}
status_str = str(row.get('狀態', row.get('status', 'NEW'))).strip()
status = status_mapping.get(status_str, 'NEW')
# 優先級
priority_mapping = {
'': 'HIGH', '': 'MEDIUM', '': 'LOW',
'HIGH': 'HIGH', 'MEDIUM': 'MEDIUM', 'LOW': 'LOW',
'高優先級': 'HIGH', '中優先級': 'MEDIUM', '低優先級': 'LOW'
'緊急': 'URGENT', '': 'HIGH', '': 'MEDIUM', '': 'LOW',
'URGENT': 'URGENT', 'HIGH': 'HIGH', 'MEDIUM': 'MEDIUM', 'LOW': 'LOW',
'緊急優先級': 'URGENT', '高優先級': 'HIGH', '中優先級': 'MEDIUM', '低優先級': 'LOW'
}
priority_str = str(row.get('優先級', row.get('priority', 'MEDIUM'))).strip()
priority = priority_mapping.get(priority_str, 'MEDIUM')
@@ -356,8 +356,8 @@ def export_todos():
followers = [f.ad_account for f in todo.followers]
# 狀態和優先級的中文對應
status_mapping = {'NEW': '新建', 'IN_PROGRESS': '進行中', 'DONE': '完成'}
priority_mapping = {'HIGH': '', 'MEDIUM': '', 'LOW': ''}
status_mapping = {'NEW': '新建', 'DOING': '進行中', 'DONE': '完成', 'BLOCKED': '阻塞'}
priority_mapping = {'URGENT': '緊急', 'HIGH': '', 'MEDIUM': '', 'LOW': ''}
data.append({
'編號': todo.id,
@@ -445,7 +445,7 @@ def download_template():
'描述': ['這是第一個範例的詳細描述', '這是第二個範例的詳細描述'],
'狀態': ['新建', '進行中'],
'優先級': ['', ''],
'到期日': ['2024-12-31', '2025-01-15'],
'到期日': ['2025-12-31', '2026-01-15'],
'負責人': ['user1@panjit.com.tw', 'user2@panjit.com.tw'],
'追蹤人': ['user3@panjit.com.tw;user4@panjit.com.tw', 'user5@panjit.com.tw']
}
@@ -455,8 +455,8 @@ def download_template():
'欄位說明': [
'標題 (必填)',
'描述 (選填)',
'狀態: 新建/進行中/完成',
'優先級: 高/中/低',
'狀態: 新建/進行中/完成/阻塞',
'優先級: 緊急/高/中/低',
'到期日: YYYY-MM-DD 格式',
'負責人: AD帳號多人用分號分隔',
'追蹤人: AD帳號多人用分號分隔'
@@ -464,8 +464,8 @@ def download_template():
'說明': [
'請填入待辦事項的標題',
'可選填詳細描述',
'可選填 NEW/IN_PROGRESS/DONE',
'可選填 HIGH/MEDIUM/LOW',
'可選填 NEW/DOING/DONE/BLOCKED',
'可選填 URGENT/HIGH/MEDIUM/LOW',
'例如: 2024-12-31',
'例如: john@panjit.com.tw',
'例如: mary@panjit.com.tw;tom@panjit.com.tw'

View File

@@ -154,7 +154,23 @@ def get_user_info(ad_account):
return None
config = current_app.config
search_filter = f"(&(objectClass=person)(sAMAccountName={ad_account}))"
# 支援 sAMAccountName 和 userPrincipalName 格式
if '@' in ad_account:
# Email 格式,使用 userPrincipalName 或 mail 搜尋
search_filter = f"""(&
(objectClass=person)
(|
(userPrincipalName={ad_account})
(mail={ad_account})
)
)"""
else:
# 純帳號名稱,使用 sAMAccountName 搜尋
search_filter = f"(&(objectClass=person)(sAMAccountName={ad_account}))"
# 移除多餘的空白
search_filter = ' '.join(search_filter.split())
conn.search(
config['LDAP_SEARCH_BASE'],
@@ -170,7 +186,8 @@ def get_user_info(ad_account):
return {
'ad_account': str(entry.sAMAccountName) if entry.sAMAccountName else ad_account,
'display_name': str(entry.displayName) if entry.displayName else ad_account,
'email': str(entry.mail) if entry.mail else ''
'email': str(entry.mail) if entry.mail else '',
'user_principal_name': str(entry.userPrincipalName) if entry.userPrincipalName else ''
}
except Exception as e:
@@ -191,13 +208,28 @@ def validate_ad_accounts(ad_accounts):
valid_accounts = {}
for account in ad_accounts:
search_filter = f"(&(objectClass=person)(sAMAccountName={account}))"
# 支援 sAMAccountName 和 userPrincipalName 格式
if '@' in account:
# Email 格式,使用 userPrincipalName 或 mail 搜尋
search_filter = f"""(&
(objectClass=person)
(|
(userPrincipalName={account})
(mail={account})
)
)"""
else:
# 純帳號名稱,使用 sAMAccountName 搜尋
search_filter = f"(&(objectClass=person)(sAMAccountName={account}))"
# 移除多餘的空白
search_filter = ' '.join(search_filter.split())
conn.search(
config['LDAP_SEARCH_BASE'],
search_filter,
SUBTREE,
attributes=['sAMAccountName', 'displayName', 'mail']
attributes=['sAMAccountName', 'displayName', 'mail', 'userPrincipalName']
)
if conn.entries:
@@ -205,8 +237,12 @@ def validate_ad_accounts(ad_accounts):
valid_accounts[account] = {
'ad_account': str(entry.sAMAccountName) if entry.sAMAccountName else account,
'display_name': str(entry.displayName) if entry.displayName else account,
'email': str(entry.mail) if entry.mail else ''
'email': str(entry.mail) if entry.mail else '',
'user_principal_name': str(entry.userPrincipalName) if entry.userPrincipalName else ''
}
logger.info(f"Validated AD account: {account} -> {entry.sAMAccountName}")
else:
logger.warning(f"AD account not found: {account}")
return valid_accounts