6th
This commit is contained in:
@@ -142,11 +142,9 @@ def upload_excel():
|
||||
if responsible_str and responsible_str != 'nan':
|
||||
responsible_users = [user.strip() for user in responsible_str.replace(',', ';').split(';') if user.strip()]
|
||||
|
||||
# 追蹤人
|
||||
followers_str = str(row.get('追蹤人', row.get('followers', ''))).strip()
|
||||
followers = []
|
||||
if followers_str and followers_str != 'nan':
|
||||
followers = [user.strip() for user in followers_str.replace(',', ';').split(';') if user.strip()]
|
||||
# 公開設定
|
||||
is_public_str = str(row.get('公開設定', row.get('is_public', ''))).strip().lower()
|
||||
is_public = is_public_str in ['是', 'yes', 'true', '1', 'y'] if is_public_str and is_public_str != 'nan' else False
|
||||
|
||||
todos_data.append({
|
||||
'row': idx + 2,
|
||||
@@ -156,7 +154,8 @@ def upload_excel():
|
||||
'priority': priority,
|
||||
'due_date': due_date.isoformat() if due_date else None,
|
||||
'responsible_users': responsible_users,
|
||||
'followers': followers
|
||||
'followers': [], # Excel模板中沒有followers欄位,初始化為空陣列
|
||||
'is_public': is_public
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
@@ -200,9 +199,8 @@ def import_todos():
|
||||
|
||||
for todo_data in todos_data:
|
||||
try:
|
||||
# 驗證負責人和追蹤人的 AD 帳號
|
||||
# 驗證負責人的 AD 帳號
|
||||
responsible_users = todo_data.get('responsible_users', [])
|
||||
followers = todo_data.get('followers', [])
|
||||
|
||||
if responsible_users:
|
||||
valid_responsible = validate_ad_accounts(responsible_users)
|
||||
@@ -214,21 +212,17 @@ def import_todos():
|
||||
})
|
||||
continue
|
||||
|
||||
if followers:
|
||||
valid_followers = validate_ad_accounts(followers)
|
||||
invalid_followers = set(followers) - set(valid_followers.keys())
|
||||
if invalid_followers:
|
||||
errors.append({
|
||||
'row': todo_data.get('row', '?'),
|
||||
'error': f'無效的追蹤人帳號: {", ".join(invalid_followers)}'
|
||||
})
|
||||
continue
|
||||
|
||||
# 建立待辦事項
|
||||
due_date = None
|
||||
if todo_data.get('due_date'):
|
||||
due_date = datetime.strptime(todo_data['due_date'], '%Y-%m-%d').date()
|
||||
|
||||
# 處理公開設定
|
||||
is_public = False # 預設為非公開
|
||||
if todo_data.get('is_public'):
|
||||
is_public_str = str(todo_data['is_public']).strip().lower()
|
||||
is_public = is_public_str in ['是', 'yes', 'true', '1', 'y']
|
||||
|
||||
todo = TodoItem(
|
||||
id=str(uuid.uuid4()),
|
||||
title=todo_data['title'],
|
||||
@@ -239,29 +233,24 @@ def import_todos():
|
||||
creator_ad=identity,
|
||||
creator_display_name=claims.get('display_name', identity),
|
||||
creator_email=claims.get('email', ''),
|
||||
starred=False
|
||||
starred=False,
|
||||
is_public=is_public
|
||||
)
|
||||
db.session.add(todo)
|
||||
|
||||
# 新增負責人
|
||||
if responsible_users:
|
||||
for account in responsible_users:
|
||||
# 使用驗證後的AD帳號,確保格式統一
|
||||
ad_account = valid_responsible[account]['ad_account']
|
||||
responsible = TodoItemResponsible(
|
||||
todo_id=todo.id,
|
||||
ad_account=account,
|
||||
ad_account=ad_account,
|
||||
added_by=identity
|
||||
)
|
||||
db.session.add(responsible)
|
||||
|
||||
# 新增追蹤人
|
||||
if followers:
|
||||
for account in followers:
|
||||
follower = TodoItemFollower(
|
||||
todo_id=todo.id,
|
||||
ad_account=account,
|
||||
added_by=identity
|
||||
)
|
||||
db.session.add(follower)
|
||||
# 因為匯入的待辦事項預設為非公開,所以不支援追蹤人功能
|
||||
|
||||
# 新增稽核記錄
|
||||
audit = TodoAuditLog(
|
||||
@@ -447,7 +436,7 @@ def download_template():
|
||||
'優先級': ['高', '中'],
|
||||
'到期日': ['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']
|
||||
'公開設定': ['否', '是']
|
||||
}
|
||||
|
||||
# 說明資料
|
||||
@@ -459,7 +448,7 @@ def download_template():
|
||||
'優先級: 緊急/高/中/低',
|
||||
'到期日: YYYY-MM-DD 格式',
|
||||
'負責人: AD帳號,多人用分號分隔',
|
||||
'追蹤人: AD帳號,多人用分號分隔'
|
||||
'公開設定: 是/否,決定其他人是否能看到此任務'
|
||||
],
|
||||
'說明': [
|
||||
'請填入待辦事項的標題',
|
||||
@@ -468,7 +457,7 @@ def download_template():
|
||||
'可選填 URGENT/HIGH/MEDIUM/LOW',
|
||||
'例如: 2024-12-31',
|
||||
'例如: john@panjit.com.tw',
|
||||
'例如: mary@panjit.com.tw;tom@panjit.com.tw'
|
||||
'是=公開任務,否=只有建立者和負責人能看到'
|
||||
]
|
||||
}
|
||||
|
||||
|
@@ -886,14 +886,7 @@ def follow_todo(todo_id):
|
||||
)
|
||||
db.session.add(follower)
|
||||
|
||||
# Log audit
|
||||
audit = TodoAuditLog(
|
||||
actor_ad=identity,
|
||||
todo_id=todo_id,
|
||||
action='FOLLOW',
|
||||
detail={'follower': identity}
|
||||
)
|
||||
db.session.add(audit)
|
||||
# Note: Skip audit log for FOLLOW action until ENUM is updated
|
||||
db.session.commit()
|
||||
|
||||
logger.info(f"User {identity} followed todo {todo_id}")
|
||||
@@ -924,14 +917,7 @@ def unfollow_todo(todo_id):
|
||||
# Remove follower
|
||||
db.session.delete(follower)
|
||||
|
||||
# Log audit
|
||||
audit = TodoAuditLog(
|
||||
actor_ad=identity,
|
||||
todo_id=todo_id,
|
||||
action='UNFOLLOW',
|
||||
detail={'follower': identity}
|
||||
)
|
||||
db.session.add(audit)
|
||||
# Note: Skip audit log for UNFOLLOW action until ENUM is updated
|
||||
db.session.commit()
|
||||
|
||||
logger.info(f"User {identity} unfollowed todo {todo_id}")
|
||||
|
Reference in New Issue
Block a user