feat(project): 파일 끌어 놓기 → 구글 드라이브 링크, 필터 켠 보드 카드 순서 버그 수정
- 설명란·세부 업무 목록·보드 카드에 파일을 놓으면 드라이브 프로젝트/섹션/업무/세부 업무 폴더에 올리고 설명에 "파일 이름.확장자" 링크(PROJECT_DRIVE_FOLDER_ID) - 설명에서 링크를 지우면 우리가 올린 파일만 드라이브 휴지통, 되살리면 복구 - 브라우저별 필터(localStorage)가 켜져 있으면 섹션 안 카드가 제자리로 돌아가던 버그 — 필터 중에도 순서 변경 허용, 숨은 업무는 제자리. 카드 속 이미지 끌기 오인 방지 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1705,6 +1705,12 @@ def api_update_task(
|
||||
_notify_completed(bg, request, st, project=project, task=task, actor=user["email"])
|
||||
skipped: list[str] = []
|
||||
if "description" in payload:
|
||||
# 드라이브 파일 링크를 지우면 그 파일을 휴지통으로 / 되살리면 꺼낸다(2026-10-19, 백그라운드)
|
||||
from app.integrations.google_drive import file_ids_in # noqa: WPS433
|
||||
|
||||
before, after = file_ids_in(existing.get("description") or ""), file_ids_in(payload["description"])
|
||||
if before != after:
|
||||
bg.add_task(_sync_drive_links, st, task_id, before - after, after - before)
|
||||
skipped = _record_mentions(
|
||||
st, task=task,
|
||||
emails=store.extract_mentions_from_html(payload["description"]),
|
||||
@@ -2492,6 +2498,108 @@ def api_delete_attachment(request: Request, attachment_id: int) -> JSONResponse:
|
||||
return JSONResponse({"ok": True})
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# 업무 파일 → 구글 드라이브(2026-10-19) — 설명란·보드 카드·세부 업무 줄에 파일을 끌어 놓으면
|
||||
# 드라이브 `프로젝트/섹션/업무/세부 업무` 폴더에 올리고 설명란에 "파일 이름.확장자" 링크.
|
||||
# 설명에서 링크를 지우면 그 파일을 드라이브 휴지통으로(api_update_task → _sync_drive_links).
|
||||
# ────────────────────────────────────────────────────────────
|
||||
_MAX_DRIVE_BYTES = 200 * 1024 * 1024 # 200MB
|
||||
|
||||
|
||||
def _drive_folder_names(st: Any, task: dict[str, Any]) -> list[str]:
|
||||
"""[프로젝트, 섹션, 업무, (세부 업무…)] — 섹션은 맨 위 업무의 섹션(세부 업무는 섹션이 없을 수 있다)."""
|
||||
chain = [task]
|
||||
seen = {int(task["id"])}
|
||||
while chain[-1].get("parent_task_id") and len(chain) < 10:
|
||||
parent = st.get_task(task_id=chain[-1]["parent_task_id"])
|
||||
if parent is None or int(parent["id"]) in seen:
|
||||
break
|
||||
seen.add(int(parent["id"]))
|
||||
chain.append(parent)
|
||||
chain.reverse()
|
||||
top = chain[0]
|
||||
return [top.get("project_name") or "", top.get("stage_name") or "섹션 없음"] + [t.get("title") or "" for t in chain]
|
||||
|
||||
|
||||
def drive_link_html(url: str, name: str) -> str:
|
||||
"""설명란 링크 — 제목 = 파일 이름.확장자, 새 탭에서 열기."""
|
||||
import html as _html # noqa: WPS433
|
||||
|
||||
return (f'<a href="{_html.escape(url, quote=True)}" target="_blank" rel="noopener noreferrer">'
|
||||
f"{_html.escape(name)}</a>")
|
||||
|
||||
|
||||
@router.post("/api/tasks/{task_id}/drive-files")
|
||||
def api_upload_drive_file(
|
||||
request: Request, task_id: int, file: UploadFile = File(...), append: bool = Form(False),
|
||||
) -> JSONResponse:
|
||||
"""파일 하나를 구글 드라이브 업무 폴더에 올린다 → {file: {id, name, url}, link_html}.
|
||||
append=true 면 서버가 그 업무 설명 끝에 링크 줄을 붙이고 바뀐 업무를 같이 돌려준다(보드 카드·세부 업무 줄에 놓을 때 —
|
||||
설명란을 열어 둔 업무는 화면이 커서 자리에 직접 넣고 평소처럼 저장)."""
|
||||
from app.integrations import google_drive # noqa: WPS433
|
||||
|
||||
user = _require_user(request)
|
||||
st = _db_or_503(request)
|
||||
task = _task_or_404(st, task_id)
|
||||
_require_task(st, user, task, write=True)
|
||||
client = google_drive.get_client()
|
||||
if not client.enabled:
|
||||
raise HTTPException(status_code=503, detail=f"구글 드라이브 연동이 꺼져 있습니다({client.reason}).")
|
||||
stream = file.file
|
||||
stream.seek(0, 2)
|
||||
size = stream.tell()
|
||||
stream.seek(0)
|
||||
if size > _MAX_DRIVE_BYTES:
|
||||
raise HTTPException(status_code=413, detail="파일이 너무 큽니다(최대 200MB).")
|
||||
if size <= 0:
|
||||
raise HTTPException(status_code=400, detail="빈 파일입니다.")
|
||||
name = (file.filename or "file").replace("\\", "_").replace("/", "_").strip() or "file"
|
||||
try:
|
||||
folder = client.ensure_folder_path(_drive_folder_names(st, task))
|
||||
up = client.upload(folder_id=folder, name=name, stream=stream,
|
||||
mimetype=file.content_type or "application/octet-stream", task_id=task_id)
|
||||
except google_drive.GoogleDriveError as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc))
|
||||
link = drive_link_html(up["url"], up["name"])
|
||||
out: dict[str, Any] = {"file": up, "link_html": link}
|
||||
if append:
|
||||
cur = st.get_task(task_id=task_id) or task
|
||||
desc = store.sanitize_description_html((cur.get("description") or "") + f"<p>{link}</p>")
|
||||
try:
|
||||
out["task"] = st.update_task(task_id=task_id, fields={"description": desc}, actor=user["email"],
|
||||
assignee_allowed=_registered_project_user)
|
||||
except (ValueError, KeyError):
|
||||
# 파일은 올라갔다 — 링크만 못 붙임(화면이 링크를 알려 준다)
|
||||
out["append_failed"] = True
|
||||
return JSONResponse(out, status_code=201)
|
||||
|
||||
|
||||
def _sync_drive_links(st: Any, task_id: int, removed: set[str], added: set[str]) -> None:
|
||||
"""설명란 드라이브 링크가 빠지면 그 파일을 휴지통으로, 다시 생기면 휴지통에서 꺼낸다(백그라운드).
|
||||
우리가 올린 파일(appProperties dbxTaskId)만, 그리고 다른 업무 설명에 같은 링크가 남아 있으면 휴지통에 넣지 않는다."""
|
||||
from app.integrations import google_drive # noqa: WPS433
|
||||
|
||||
client = google_drive.get_client()
|
||||
if not client.enabled:
|
||||
return
|
||||
for fid in removed:
|
||||
try:
|
||||
if st.description_mentions(text=fid, exclude_task_id=task_id):
|
||||
continue
|
||||
info = client.ours(fid)
|
||||
if info and not info["trashed"]:
|
||||
client.set_trashed(fid, True)
|
||||
except Exception: # noqa: BLE001 — 저장은 이미 끝났다(파일만 남음)
|
||||
logger.warning("드라이브 파일 휴지통 이동 실패: task=%s file=%s", task_id, fid)
|
||||
for fid in added:
|
||||
try:
|
||||
info = client.ours(fid)
|
||||
if info and info["trashed"]:
|
||||
client.set_trashed(fid, False)
|
||||
except Exception: # noqa: BLE001
|
||||
logger.warning("드라이브 파일 복구 실패: task=%s file=%s", task_id, fid)
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# JSON API — 단계 이름/순서 편집
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user