feat(project): 업무를 옮기면 설명 링크 속 드라이브 파일도 새 폴더로

업무의 섹션·프로젝트가 바뀌거나 세부 업무를 다른 상위 업무로 옮기면
드라이브 폴더 경로(프로젝트/섹션/업무/세부 업무)가 달라지는데 파일은
예전 폴더에 남았다. 이동 API(업무 수정·move-parent·move-project) 뒤
백그라운드로 업무와 모든 하위 업무의 설명 링크 파일을 새 폴더로 옮긴다.
그 업무가 올린 파일(appProperties dbxTaskId)만 옮기고, 예전 폴더는 둔다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 12:32:06 +09:00
parent cad347a936
commit bca1082c26
6 changed files with 161 additions and 0 deletions
+44
View File
@@ -1716,9 +1716,17 @@ def api_update_task(
emails=store.extract_mentions_from_html(payload["description"]),
actor=user["email"], project_name=project_name,
)
if _drive_path_changed(existing, task): # 섹션·프로젝트·상위 업무가 바뀜 → 드라이브 파일도 새 폴더로
bg.add_task(_relocate_drive_files, st, task_id)
return JSONResponse({"task": task, "mention_skipped": skipped})
def _drive_path_changed(before: dict[str, Any], after: dict[str, Any]) -> bool:
"""드라이브 폴더 경로(프로젝트/섹션/상위 업무)가 바뀌었나."""
return any(str(before.get(k) or "") != str(after.get(k) or "")
for k in ("project_id", "stage_id", "parent_task_id") if k in after)
@router.delete("/api/tasks/{task_id}")
def api_delete_task(request: Request, task_id: int) -> JSONResponse:
user = _require_user(request)
@@ -1797,6 +1805,7 @@ def api_reorder_subtasks(
def api_move_subtask(
request: Request,
task_id: int,
bg: BackgroundTasks,
payload: dict[str, Any] = Body(...),
) -> JSONResponse:
"""세부 업무를 다른 상위 업무로 옮긴다 — 보드에서 세부 업무 줄을 다른 카드로 드래그.
@@ -1817,6 +1826,8 @@ def api_move_subtask(
raise HTTPException(status_code=400, detail=str(exc))
except KeyError as exc:
raise HTTPException(status_code=404, detail=str(exc))
if _drive_path_changed(existing, task): # 드라이브 파일도 새 상위 업무 폴더로(백그라운드)
bg.add_task(_relocate_drive_files, st, task_id)
return JSONResponse({"task": task})
@@ -1854,6 +1865,8 @@ def api_move_task_project(
except KeyError as exc:
raise HTTPException(status_code=404, detail=str(exc))
task.pop("_moved_ids", None)
if _drive_path_changed(existing, task): # 세부 업무까지 드라이브 파일도 새 프로젝트/섹션 폴더로(백그라운드)
bg.add_task(_relocate_drive_files, st, task_id)
newly_assigned = task.pop("_newly_assigned", None)
if newly_assigned: # 대상 섹션 기본 담당자가 자동 배정됨 — 일반 배정과 같은 알림(담당자는 협업자가 아님)
_inbox(
@@ -2600,6 +2613,37 @@ def _sync_drive_links(st: Any, task_id: int, removed: set[str], added: set[str])
logger.warning("드라이브 파일 복구 실패: task=%s file=%s", task_id, fid)
def _relocate_drive_files(st: Any, task_id: int) -> None:
"""업무가 다른 섹션·프로젝트·상위 업무로 옮겨지면 설명란 링크 속 드라이브 파일도 새 `프로젝트/섹션/업무/세부 업무`
폴더로 옮긴다(2026-10-20, 백그라운드). 하위 세부 업무도 경로가 바뀌므로 함께. 그 업무가 올린 파일만
(appProperties dbxTaskId — 다른 업무 링크를 붙여 넣은 것·남의 파일은 그대로). 예전 폴더는 지우지 않는다."""
from app.integrations import google_drive # noqa: WPS433
client = google_drive.get_client()
if not client.enabled:
return
try:
ids = st.task_subtree_ids(task_id=task_id)
except Exception: # noqa: BLE001
logger.warning("드라이브 파일 이동 — 하위 업무 조회 실패: task=%s", task_id)
return
for tid in ids:
task = st.get_task(task_id=tid)
files = google_drive.file_ids_in((task or {}).get("description") or "")
if not files:
continue
try:
folder = client.ensure_folder_path(_drive_folder_names(st, task))
except Exception: # noqa: BLE001 — 이동은 이미 끝났다(파일만 예전 폴더에 남음)
logger.warning("드라이브 폴더 준비 실패: task=%s", tid)
continue
for fid in files:
try:
client.move_to(fid, folder, task_id=tid)
except Exception: # noqa: BLE001
logger.warning("드라이브 파일 이동 실패: task=%s file=%s", tid, fid)
# ────────────────────────────────────────────────────────────
# JSON API — 단계 이름/순서 편집
# ────────────────────────────────────────────────────────────