feat(project): 업무를 왼쪽 프로젝트로 끌어 다른 프로젝트로 이동(섹션 선택 창)
- 보드 카드를 사이드바 프로젝트 줄에 놓으면 섹션 선택 창 → POST /api/tasks/{id}/move-project
- 세부 업무(모든 단계)까지 한 트랜잭션으로 이동, 섹션 기본 담당자·완료 섹션 규칙, 대상 쪽 연결 정리
- 원 소속 권한 + 대상 프로젝트 멤버만, 대상 프로젝트를 볼 수 없는 담당자·협업자는 화면에 안내
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -933,6 +933,86 @@ class ProjectStore:
|
||||
out["_newly_completed"] = newly_completed if changed else False
|
||||
return out
|
||||
|
||||
def move_task_to_project(
|
||||
self, *, task_id: int, project_id: int, stage_id: Any = None, actor: str = "",
|
||||
assignee_allowed: Any = None,
|
||||
) -> dict[str, Any]:
|
||||
"""메인 업무를 다른 프로젝트(의 섹션)로 옮긴다 — 세부 업무(모든 단계)도 함께. 한 트랜잭션.
|
||||
|
||||
· 메인 업무만(세부 업무는 상위 업무와 함께 움직인다). 같은 프로젝트면 ValueError.
|
||||
· 섹션은 대상 프로젝트 것만(None = 섹션 없음). 목록 끝(sort_order 최대+1)으로.
|
||||
· 섹션을 옮길 때와 같은 규칙 — 담당자가 비었으면 그 섹션 기본 담당자, 완료 섹션이면 완료 처리.
|
||||
· 대상 프로젝트로 걸려 있던 연결(멀티호밍)은 이제 원 소속이라 지운다(다른 연결은 그대로).
|
||||
· 활동 이력·알림·회의록 업무 등록 줄의 프로젝트도 따라 바꾼다(이력이 새 프로젝트 화면에 보이게).
|
||||
반환: 옮긴 업무(get_task) + `_moved_ids`·`_newly_assigned`·`_newly_completed`.
|
||||
"""
|
||||
newly_assigned: str | None = None
|
||||
newly_completed = False
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
row = conn.execute("SELECT * FROM tasks WHERE id = %s FOR UPDATE", (task_id,)).fetchone()
|
||||
if row is None:
|
||||
raise KeyError(f"업무를 찾을 수 없습니다: {task_id}")
|
||||
prev = self._serialize(row)
|
||||
if prev.get("parent_task_id") is not None:
|
||||
raise ValueError("세부 업무는 상위 업무와 함께 옮겨집니다. 상위 업무를 옮기세요.")
|
||||
target = int(project_id)
|
||||
if int(prev["project_id"]) == target:
|
||||
raise ValueError("이미 이 프로젝트의 업무입니다.")
|
||||
if not conn.execute("SELECT 1 FROM projects WHERE id = %s", (target,)).fetchone():
|
||||
raise KeyError(f"프로젝트를 찾을 수 없습니다: {target}")
|
||||
new_stage = self._check_stage_in_project(conn, stage_id, target)
|
||||
ids = [int(r["id"]) for r in conn.execute(
|
||||
"WITH RECURSIVE tree AS (SELECT id FROM tasks WHERE id = %s "
|
||||
"UNION ALL SELECT t.id FROM tasks t JOIN tree ON t.parent_task_id = tree.id) "
|
||||
"SELECT id FROM tree",
|
||||
(task_id,),
|
||||
).fetchall()]
|
||||
nxt = conn.execute(
|
||||
"SELECT COALESCE(MAX(sort_order), -1) + 1 AS n FROM tasks WHERE project_id = %s",
|
||||
(target,),
|
||||
).fetchone()
|
||||
conn.execute("UPDATE tasks SET project_id = %s WHERE id = ANY(%s)", (target, ids))
|
||||
sets = ["stage_id = %s", "sort_order = %s"]
|
||||
params: list[Any] = [new_stage, int(nxt["n"])]
|
||||
if new_stage is not None and not (prev.get("assignee_email") or ""):
|
||||
dae, dan = self._stage_default_assignee(conn, new_stage, target, allowed=assignee_allowed)
|
||||
if dae:
|
||||
sets += ["assignee_email = %s", "assignee_name = %s"]
|
||||
params += [dae, dan]
|
||||
newly_assigned = dae
|
||||
if self._stage_is_done_conn(conn, new_stage) and not prev.get("completed_at"):
|
||||
sets.append("completed_at = %s")
|
||||
params.append(now_kst())
|
||||
newly_completed = True
|
||||
conn.execute(f"UPDATE tasks SET {', '.join(sets)} WHERE id = %s", (*params, task_id))
|
||||
conn.execute(
|
||||
"DELETE FROM task_project_links WHERE task_id = ANY(%s) AND project_id = %s", (ids, target))
|
||||
conn.execute("UPDATE project_activity SET project_id = %s WHERE task_id = ANY(%s)", (target, ids))
|
||||
conn.execute("UPDATE project_notifications SET project_id = %s WHERE task_id = ANY(%s)", (target, ids))
|
||||
if self._table_exists(conn, "goal_meeting_tasks"):
|
||||
conn.execute(
|
||||
"UPDATE goal_meeting_tasks SET project_id = %s, stage_id = %s WHERE task_id = %s",
|
||||
(target, new_stage, task_id))
|
||||
old_name = conn.execute("SELECT name FROM projects WHERE id = %s", (prev["project_id"],)).fetchone()
|
||||
new_name = conn.execute("SELECT name FROM projects WHERE id = %s", (target,)).fetchone()
|
||||
self._log(conn, project_id=target, task_id=task_id, actor=actor,
|
||||
action=store.ACTION_PROJECT_MOVED,
|
||||
detail=f"{prev['title']}: {(old_name or {}).get('name', '')} → {(new_name or {}).get('name', '')}")
|
||||
if newly_assigned:
|
||||
self._log(conn, project_id=target, task_id=task_id, actor=actor,
|
||||
action=store.ACTION_ASSIGNED, detail=f"{prev['title']} → {newly_assigned}")
|
||||
if newly_completed:
|
||||
self._log(conn, project_id=target, task_id=task_id, actor=actor,
|
||||
action=store.ACTION_COMPLETED, detail=prev["title"])
|
||||
out = self.get_task(task_id=task_id)
|
||||
if out is None:
|
||||
raise KeyError(task_id)
|
||||
out["_moved_ids"] = ids
|
||||
out["_newly_assigned"] = newly_assigned
|
||||
out["_newly_completed"] = newly_completed
|
||||
return out
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 휴지통 (마이그레이션 010) — 지우기 직전 스냅샷, 관리자 복구, 3개월 보관
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -1740,6 +1740,60 @@ def api_move_subtask(
|
||||
return JSONResponse({"task": task})
|
||||
|
||||
|
||||
@router.post("/api/tasks/{task_id}/move-project")
|
||||
def api_move_task_project(
|
||||
request: Request,
|
||||
task_id: int,
|
||||
bg: BackgroundTasks,
|
||||
payload: dict[str, Any] = Body(...),
|
||||
) -> JSONResponse:
|
||||
"""메인 업무를 다른 프로젝트로 옮긴다 — 보드 카드·목록 줄을 왼쪽 프로젝트 목록으로 드래그 → 섹션 선택 창.
|
||||
|
||||
body: {"project_id": 대상, "stage_id": 대상 섹션 또는 null}. 원 소속 권한(FULL) + 대상 프로젝트 멤버여야 한다.
|
||||
세부 업무는 함께 옮겨진다. 응답의 `unseen` = 대상 프로젝트를 볼 수 없는 담당자·협업자(화면이 안내).
|
||||
"""
|
||||
user = _require_user(request)
|
||||
st = _db_or_503(request)
|
||||
existing = _task_or_404(st, task_id)
|
||||
_require_task(st, user, existing, write=True)
|
||||
try:
|
||||
target = int(payload.get("project_id"))
|
||||
except (TypeError, ValueError):
|
||||
raise HTTPException(status_code=400, detail="옮길 프로젝트(project_id)가 필요합니다.")
|
||||
_require_manage(request, st, user, target)
|
||||
project = st.get_project(project_id=target)
|
||||
if project is None:
|
||||
raise HTTPException(status_code=404, detail="프로젝트를 찾을 수 없습니다.")
|
||||
try:
|
||||
task = st.move_task_to_project(
|
||||
task_id=task_id, project_id=target, stage_id=payload.get("stage_id"),
|
||||
actor=user["email"], assignee_allowed=_registered_project_user,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
except KeyError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc))
|
||||
task.pop("_moved_ids", None)
|
||||
newly_assigned = task.pop("_newly_assigned", None)
|
||||
if newly_assigned: # 대상 섹션 기본 담당자가 자동 배정됨 — 일반 배정과 같은 알림
|
||||
_follow(st, task["id"], [newly_assigned])
|
||||
_inbox(
|
||||
st, recipients=[newly_assigned], actor=user["email"], project_id=target, task_id=task["id"],
|
||||
ntype="assigned", title=f"업무 배정: {task['title']}",
|
||||
body=f"{project['name']} · 마감 {task.get('due_date') or '-'}",
|
||||
)
|
||||
if task.pop("_newly_completed", False):
|
||||
_notify_completed(bg, request, st, project=project, task=task, actor=user["email"])
|
||||
people = [task.get("assignee_email") or ""]
|
||||
try:
|
||||
people += st.list_followers(task_id=task_id)
|
||||
except Exception: # noqa: BLE001 - 008 미적용
|
||||
pass
|
||||
unseen = sorted({store.norm_str(e, lower=True) for e in people if e} -
|
||||
set(access.filter_recipients(st, task, [e for e in people if e])))
|
||||
return JSONResponse({"task": task, "unseen": unseen})
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
# JSON API — 팔로워 (아사나의 협업자)
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -41,6 +41,7 @@ ACTION_COMPLETED = "completed"
|
||||
ACTION_STAGE_CHANGED = "stage_changed"
|
||||
ACTION_REOPENED = "reopened"
|
||||
ACTION_SUBTASK_MOVED = "subtask_moved" # 세부 업무를 다른 상위 업무로 옮김(보드 드래그)
|
||||
ACTION_PROJECT_MOVED = "project_moved" # 업무를 다른 프로젝트로 옮김(왼쪽 프로젝트 목록으로 드래그)
|
||||
|
||||
# 프로젝트 색상 팔레트 — 32색(8칸 × 4줄). 앞 16색은 아사나 프로젝트 색(아사나 색상표
|
||||
# 순서 그대로), 뒤 16색은 같은 칸(열)에 대응하는 진한 색 — 3줄째 = 1줄째의 진한 색,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "project/_meeting_content_base.html" if meeting_embedded else "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -298,5 +298,5 @@
|
||||
|
||||
<script src="/static/project-goal-text.js?v=20261003d" defer></script>
|
||||
<script src="/static/project-meeting-cells.js?v=20261012a" defer></script>
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -207,5 +207,5 @@
|
||||
{% include "project/_member_tasks_modal.html" %}
|
||||
|
||||
<script src="/static/project-goal-text.js?v=20261003d" defer></script>
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/project-help.css?v=20261003a" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -102,5 +102,5 @@
|
||||
{% include "project/_side_modals.html" %}
|
||||
{% include "project/_member_tasks_modal.html" %}
|
||||
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -100,5 +100,5 @@
|
||||
"today": {{ today | tojson }}
|
||||
}
|
||||
</script>
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -108,5 +108,5 @@
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<!-- 구글 머티리얼 심볼(담당자 아이콘 등) — self-host -->
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
<!-- 타임라인 vis-timeline — self-host -->
|
||||
@@ -469,5 +469,5 @@
|
||||
</script>
|
||||
|
||||
<script src="/static/vendor/vis-timeline/vis-timeline-graph2d.min.js"></script>
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013b" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261013c" />
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
{% endblock %}
|
||||
|
||||
@@ -70,5 +70,5 @@
|
||||
{% include "project/_side_modals.html" %}
|
||||
{% include "project/_member_tasks_modal.html" %}
|
||||
|
||||
<script src="/static/project.js?v=20261013b" defer></script>
|
||||
<script src="/static/project.js?v=20261013c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user