feat(project): dashboard workload by assignee with subtasks and completion
Replace the scheduled-tasks bar chart with a table of all tasks assigned
per person in scope (no due date needed, filters ignored): main tasks,
subtasks (new GET /api/projects/{id}/subtasks-summary), done counts and
completion rate, plus a total row. Admin only, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -484,6 +484,19 @@ class ProjectStore:
|
||||
project_ids=[project_id], assignee_email=assignee_email, limit=limit,
|
||||
)
|
||||
|
||||
def list_subtasks_of(self, *, parent_ids: list[int]) -> list[dict[str, Any]]:
|
||||
"""하위 업무 요약(대시보드 담당자별 집계용) — 부모 id·담당자·완료 여부만."""
|
||||
ids = sorted({int(i) for i in parent_ids})
|
||||
if not ids:
|
||||
return []
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT parent_task_id, assignee_email, assignee_name, completed_at IS NOT NULL AS done "
|
||||
"FROM tasks WHERE parent_task_id = ANY(%s)", (ids,),
|
||||
).fetchall()
|
||||
return [{"parent_task_id": int(r["parent_task_id"]), "assignee_email": r["assignee_email"] or "",
|
||||
"assignee_name": r["assignee_name"] or "", "done": bool(r["done"])} for r in rows]
|
||||
|
||||
def list_tasks_for_projects(
|
||||
self, *, project_ids: list[int], assignee_email: str | None = None,
|
||||
limit: int = 20000,
|
||||
|
||||
@@ -1335,6 +1335,24 @@ def api_project_snapshot(request: Request, project_id: int, scope: str = "projec
|
||||
})
|
||||
|
||||
|
||||
@router.get("/api/projects/{project_id}/subtasks-summary")
|
||||
def api_subtasks_summary(request: Request, project_id: int, scope: str = "project") -> JSONResponse:
|
||||
"""대시보드 "담당자별 작업 합계" — 화면 업무 목록엔 하위 업무가 없어서(보드에 카드로 안 뜨게) 하위 업무만 따로.
|
||||
scope=project → 이 프로젝트(+여기 연결된) 최상위 업무의 하위 업무, scope=all → 볼 수 있는 모든 최상위 프로젝트(스냅샷과 같은 범위)."""
|
||||
user = _require_user(request)
|
||||
st = _db_or_503(request)
|
||||
_require_manage(request, st, user, project_id)
|
||||
if scope == "all":
|
||||
allowed = _accessible_project_ids(st, user)
|
||||
ids = [p["id"] for p in st.list_projects(include_archived=False,
|
||||
member_email=None if allowed is None else user["email"])
|
||||
if not p.get("parent_id")]
|
||||
else:
|
||||
ids = [project_id]
|
||||
parents = [t["id"] for t in st.list_tasks_for_projects(project_ids=ids)]
|
||||
return JSONResponse({"subtasks": st.list_subtasks_of(parent_ids=parents)})
|
||||
|
||||
|
||||
def _project_meta(p: dict[str, Any]) -> dict[str, Any]:
|
||||
"""프로젝트 화면·스냅샷 공용 프로젝트 요약(사이드바·타임라인 그룹·보드 배지용)."""
|
||||
return {
|
||||
|
||||
@@ -267,5 +267,5 @@
|
||||
|
||||
<script src="/static/project-goal-text.js?v=20261003d" defer></script>
|
||||
<script src="/static/project-meeting-cells.js?v=20261007a" defer></script>
|
||||
<script src="/static/project.js?v=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% 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=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -407,7 +407,7 @@
|
||||
<li>위쪽 숫자 카드 4개: <b>완료된 작업 합계 · 미완료 작업 합계 · 마감일이 지난 작업 합계 · 작업 합계</b></li>
|
||||
<li><b>미완료 작업 합계(섹션별)</b> — 섹션마다 남은 일이 몇 개인지 막대로 보여줍니다. 막대에 마우스를 올리면 숫자가 나옵니다.</li>
|
||||
<li><b>작업 합계(완료 상태별)</b> — 완료와 미완료 비율을 도넛 차트로 보여줍니다.</li>
|
||||
<li><b>예정된 작업 합계(담당자별)</b> — 사람별로 일정이 잡힌 미완료 작업 수(상위 10명). <b>관리자에게만</b> 보입니다.</li>
|
||||
<li><b>담당자별 작업 합계(메인·하위 작업, 완료)</b> — 이 범위에서 사람별로 배정된 작업 <b>전부</b>(마감일이 없어도, 필터와 관계없이)를 메인 작업·하위 작업으로 나눠 세고, 각각과 전체의 완료 수·완료율을 보여 줍니다. 하위 작업은 하위 작업에 지정된 담당자 기준입니다. 맨 아래 줄은 합계입니다. <b>관리자에게만</b> 보입니다.</li>
|
||||
<li>범위(이 프로젝트/전체 프로젝트)와 필터 바 설정을 그대로 따라 계산합니다.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -104,5 +104,5 @@
|
||||
{% include "project/_side_modals.html" %}
|
||||
{% include "project/_member_tasks_modal.html" %}
|
||||
|
||||
<script src="/static/project.js?v=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -100,5 +100,5 @@
|
||||
"today": {{ today | tojson }}
|
||||
}
|
||||
</script>
|
||||
<script src="/static/project.js?v=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261004a" />
|
||||
<link rel="stylesheet" href="/static/project.css?v=20261007a" />
|
||||
<!-- 구글 머티리얼 심볼(담당자 아이콘 등) — self-host -->
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
<!-- 타임라인 vis-timeline — self-host -->
|
||||
@@ -492,5 +492,5 @@
|
||||
</script>
|
||||
|
||||
<script src="/static/vendor/vis-timeline/vis-timeline-graph2d.min.js"></script>
|
||||
<script src="/static/project.js?v=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -70,5 +70,5 @@
|
||||
{% include "project/_side_modals.html" %}
|
||||
{% include "project/_member_tasks_modal.html" %}
|
||||
|
||||
<script src="/static/project.js?v=20261007e" defer></script>
|
||||
<script src="/static/project.js?v=20261007f" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1544,6 +1544,23 @@ img.pj-person-ic { width: 22px; height: 22px; }
|
||||
box-shadow: var(--pj-card-shadow); padding: 18px 20px 20px; min-width: 0;
|
||||
}
|
||||
.pj-dash-card-wide { grid-column: 1 / -1; }
|
||||
/* 담당자별 작업 합계(메인·하위, 완료) 표 */
|
||||
.pj-dash-workload { overflow-x: auto; }
|
||||
.pj-wl-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
|
||||
.pj-wl-table th, .pj-wl-table td { padding: 8px 10px; border-bottom: 1px solid var(--pj-border); text-align: left; white-space: nowrap; }
|
||||
.pj-wl-table thead th { font-size: 12px; font-weight: 600; color: var(--pj-ink-soft); }
|
||||
.pj-wl-table thead th:nth-child(2), .pj-wl-table thead th:nth-child(3), .pj-wl-table thead th:nth-child(4) { text-align: right; }
|
||||
.pj-wl-table tbody th { font-weight: 600; }
|
||||
.pj-wl-cnt { text-align: right !important; width: 72px; }
|
||||
.pj-wl-num { min-width: 150px; }
|
||||
.pj-wl-num > span { margin-left: 8px; color: var(--pj-ink-soft); }
|
||||
.pj-wl-num b { color: var(--pj-ink); }
|
||||
.pj-wl-num em { font-style: normal; font-weight: 700; color: var(--pj-accent-dark); margin-left: 4px; }
|
||||
.pj-wl-num em.is-good { color: #1f8a4c; }
|
||||
.pj-wl-bar { display: inline-block; vertical-align: middle; width: 90px; height: 8px; border-radius: 999px; background: #eceef2; overflow: hidden; }
|
||||
.pj-wl-bar i { display: block; height: 100%; border-radius: inherit; background: var(--color-success-green, #2e9e5b); transition: width .6s cubic-bezier(.22,.9,.3,1); }
|
||||
.pj-wl-all .pj-wl-bar { width: 120px; }
|
||||
.pj-wl-total th, .pj-wl-total td { border-bottom: none; border-top: 2px solid var(--pj-border); font-weight: 700; }
|
||||
.pj-dash-card-title { font-size: 13.5px; font-weight: 700; color: var(--pj-ink); margin-bottom: 18px; }
|
||||
|
||||
/* 세로 막대(섹션별/담당자별 공용) */
|
||||
|
||||
+91
-15
@@ -5785,31 +5785,107 @@
|
||||
]));
|
||||
charts.appendChild(statusCard);
|
||||
|
||||
// 담당자별 예정된 작업 — 미완료 + 일정(시작/마감일) 있는 작업만, 상위 10명.
|
||||
// 담당자별 작업 합계(2026-10-07) — 이 범위에서 그 사람에게 배정된 작업 전부(마감일·필터와 무관),
|
||||
// 메인 작업과 하위 작업을 나눠 세고 완료 수·완료율. 하위 업무는 화면 목록에 없어 서버에서 따로 받는다.
|
||||
// 사람별 업무량이 드러나는 표라 관리자에게만 보여준다.
|
||||
if (isAdmin) {
|
||||
const byAssignee = {};
|
||||
incomplete.forEach(function (t) {
|
||||
if (!t.start_date && !t.due_date) return;
|
||||
const k = t.assignee_email ? capName(t.assignee_name || idOf(t.assignee_email)) : "담당자 없음";
|
||||
byAssignee[k] = (byAssignee[k] || 0) + 1;
|
||||
});
|
||||
let assigneeEntries = Object.keys(byAssignee).map(function (k) { return { label: k, value: byAssignee[k] }; })
|
||||
.sort(function (a, b) { return b.value - a.value; });
|
||||
if (assigneeEntries.length > 10) {
|
||||
const rest = assigneeEntries.slice(10).reduce(function (s, x) { return s + x.value; }, 0);
|
||||
assigneeEntries = assigneeEntries.slice(0, 10).concat([{ label: "기타", value: rest }]);
|
||||
}
|
||||
const assigneeCard = document.createElement("div");
|
||||
assigneeCard.className = "pj-dash-card pj-dash-card-wide";
|
||||
assigneeCard.innerHTML = '<div class="pj-dash-card-title">예정된 작업 합계(담당자별)</div>';
|
||||
assigneeCard.appendChild(dashBarChart(assigneeEntries));
|
||||
assigneeCard.innerHTML = '<div class="pj-dash-card-title">담당자별 작업 합계(메인·하위 작업, 완료)</div>' +
|
||||
'<div class="pj-dash-workload"></div>';
|
||||
charts.appendChild(assigneeCard);
|
||||
paintWorkload(assigneeCard.querySelector(".pj-dash-workload"));
|
||||
}
|
||||
|
||||
root.appendChild(charts);
|
||||
}
|
||||
|
||||
// ── 담당자별 작업 합계 — 메인(이 범위 최상위 작업, 중복 없이) + 하위(서버 subtasks-summary), 완료 수 ──
|
||||
let workloadCache = { scope: "", at: 0, subtasks: null, pending: null };
|
||||
function loadWorkloadSubtasks(force) {
|
||||
const fresh = workloadCache.scope === viewScope && Date.now() - workloadCache.at < 15000;
|
||||
if (!force && fresh && workloadCache.subtasks) return Promise.resolve(workloadCache.subtasks);
|
||||
if (workloadCache.pending && workloadCache.scope === viewScope) return workloadCache.pending;
|
||||
const scope = viewScope;
|
||||
workloadCache.scope = scope;
|
||||
workloadCache.pending = api("GET", "/project/api/projects/" + projectId + "/subtasks-summary?scope=" + scope)
|
||||
.then(function (res) {
|
||||
if (workloadCache.scope === scope) Object.assign(workloadCache, { at: Date.now(), subtasks: res.subtasks || [] });
|
||||
return res.subtasks || [];
|
||||
})
|
||||
.finally(function () { workloadCache.pending = null; });
|
||||
return workloadCache.pending;
|
||||
}
|
||||
function paintWorkload(box) {
|
||||
const seen = {}, rows = {};
|
||||
function row(email, name) {
|
||||
const k = email ? email.toLowerCase() : "";
|
||||
if (!rows[k]) rows[k] = { label: email ? capName(name || idOf(email)) : "담당자 없음", none: !email,
|
||||
main: 0, mainDone: 0, sub: 0, subDone: 0 };
|
||||
return rows[k];
|
||||
}
|
||||
const mains = scopeTasks().filter(function (t) {
|
||||
if (t.parent_task_id || seen[t.id]) return false;
|
||||
seen[t.id] = true; return true;
|
||||
});
|
||||
mains.forEach(function (t) {
|
||||
const r = row(t.assignee_email, t.assignee_name);
|
||||
r.main++; if (t.completed_at) r.mainDone++;
|
||||
});
|
||||
function draw(subs) {
|
||||
Object.keys(rows).forEach(function (k) { rows[k].sub = 0; rows[k].subDone = 0; });
|
||||
(subs || []).forEach(function (s) {
|
||||
if (!seen[s.parent_task_id]) return; // 이 범위의 메인 작업에 딸린 하위 작업만
|
||||
const r = row(s.assignee_email, s.assignee_name);
|
||||
r.sub++; if (s.done) r.subDone++;
|
||||
});
|
||||
const list = Object.keys(rows).map(function (k) { return rows[k]; })
|
||||
.filter(function (r) { return r.main + r.sub > 0; })
|
||||
.sort(function (a, b) { return (a.none - b.none) || ((b.main + b.sub) - (a.main + a.sub)) || a.label.localeCompare(b.label); });
|
||||
if (!list.length) { box.innerHTML = "<div class='pj-empty-sm'>배정된 작업이 없습니다.</div>"; return; }
|
||||
const total = list.reduce(function (t, r) {
|
||||
return { main: t.main + r.main, mainDone: t.mainDone + r.mainDone, sub: t.sub + r.sub, subDone: t.subDone + r.subDone };
|
||||
}, { main: 0, mainDone: 0, sub: 0, subDone: 0 });
|
||||
function bar(done, all) {
|
||||
const pct = all ? Math.round(done / all * 100) : 0;
|
||||
return '<div class="pj-wl-bar" title="완료 ' + done + ' / ' + all + '"><i style="width:' + pct + '%"></i></div>';
|
||||
}
|
||||
function cell(done, all) {
|
||||
return '<td class="pj-wl-num">' + (all ? bar(done, all) + '<span><b>' + done + "</b> / " + all + "</span>" : '<span class="pj-muted">—</span>') + "</td>";
|
||||
}
|
||||
function tr(r, cls) {
|
||||
const all = r.main + r.sub, done = r.mainDone + r.subDone, pct = all ? Math.round(done / all * 100) : 0;
|
||||
return '<tr class="' + (cls || "") + '"><th>' + escapeHtml(r.label) + "</th>" +
|
||||
'<td class="pj-wl-cnt">' + r.main + "</td>" + '<td class="pj-wl-cnt">' + r.sub + "</td>" +
|
||||
'<td class="pj-wl-cnt"><b>' + all + "</b></td>" +
|
||||
cell(r.mainDone, r.main) + cell(r.subDone, r.sub) +
|
||||
'<td class="pj-wl-num pj-wl-all">' + bar(done, all) + "<span><b>" + done + "</b> / " + all +
|
||||
' <em class="' + (pct >= 100 ? "is-good" : "") + '">' + pct + "%</em></span></td></tr>";
|
||||
}
|
||||
box.innerHTML = '<table class="pj-wl-table"><thead><tr><th>담당자</th><th>메인 작업</th><th>하위 작업</th><th>전체</th>' +
|
||||
"<th>메인 완료</th><th>하위 완료</th><th>전체 완료(완료율)</th></tr></thead><tbody>" +
|
||||
list.map(function (r) { return tr(r); }).join("") + "</tbody><tfoot>" +
|
||||
tr(Object.assign({ label: "합계" }, total), "pj-wl-total") + "</tfoot></table>";
|
||||
requestAnimationFrame(function () { // 막대는 0 에서 늘어나게
|
||||
box.querySelectorAll(".pj-wl-bar i").forEach(function (i) {
|
||||
const w = i.style.width; i.style.width = "0"; requestAnimationFrame(function () { i.style.width = w; });
|
||||
});
|
||||
});
|
||||
}
|
||||
if (workloadCache.subtasks && workloadCache.scope === viewScope) draw(workloadCache.subtasks);
|
||||
else box.innerHTML = "<div class='pj-empty-sm'>하위 작업을 불러오는 중…</div>";
|
||||
loadWorkloadSubtasks(false).then(function (subs) {
|
||||
if (box.isConnected) draw(subs);
|
||||
}).catch(function (err) {
|
||||
if (!box.isConnected) return;
|
||||
draw([]);
|
||||
const note = document.createElement("div");
|
||||
note.className = "pj-empty-sm";
|
||||
note.textContent = "하위 작업을 불러오지 못해 메인 작업만 표시합니다: " + err.message;
|
||||
box.appendChild(note);
|
||||
});
|
||||
}
|
||||
|
||||
// 서버가 돌려준 업무를 로컬 목록에 반영. 멀티호밍된 업무는 목록에 여러 행
|
||||
// (원래 소속 맥락 + 연결된 프로젝트 맥락)으로 들어 있으므로 같은 id 의 행을
|
||||
// 전부 고친다. 단 "어느 맥락의 세션인지"에 해당하는 필드는 행마다 다르다 —
|
||||
|
||||
@@ -280,9 +280,13 @@
|
||||
CSS 의 크기는 전부 `calc(Npx * var(--tz))`(배율 모드 `--tz: .75`), vis 옵션 높이·간격도
|
||||
`uiZoom()` 을 곱한다. 배율을 토글하면(resize) 다시 그린다. **타임라인 CSS 에 px 크기를 새로 넣을
|
||||
때도 `var(--tz)` 를 곱한다.**
|
||||
- **대시보드** — 합계 타일 4개 + 미완료 작업(섹션별)·작업 합계(완료 상태별) 차트. **"예정된 작업 합계
|
||||
(담당자별)" 차트는 관리자(`is_admin`)에게만** 보인다(사람별 업무량이 드러나서). 화면 표시만 막는 것 —
|
||||
작업 데이터 자체는 멤버가 원래 볼 수 있는 범위 그대로다.
|
||||
- **대시보드** — 합계 타일 4개 + 미완료 작업(섹션별)·작업 합계(완료 상태별) 차트. **"담당자별 작업 합계(메인·하위
|
||||
작업, 완료)" 표는 관리자(`is_admin`)에게만** 보인다(사람별 업무량이 드러나서). 화면 표시만 막는 것 —
|
||||
작업 데이터 자체는 멤버가 원래 볼 수 있는 범위 그대로다. (2026-10-07, 예전 "예정된 작업 합계(담당자별)" 막대 대신)
|
||||
그 범위(이 프로젝트 = 여기 연결된 작업 포함 / 전체 프로젝트)에서 사람별로 배정된 작업 **전부**(마감일·필터와 무관) —
|
||||
메인 작업(`scopeTasks()` 최상위, 중복 없이)과 하위 작업(화면 목록엔 없어 `GET /api/projects/{id}/subtasks-summary?scope=`
|
||||
— `db.list_subtasks_of`, 그 범위 메인 작업의 하위만, 하위 작업 자신의 담당자 기준)을 나눠 세고, 메인·하위·전체 완료 수와
|
||||
전체 완료율, 맨 아래 합계 줄. 하위 요약은 15초 캐시(`paintWorkload`).
|
||||
- **보드** — 섹션별 칸반. `renderBoard` 는 캔버스를 통째로 다시 그리므로 **섹션 세로 스크롤(`.pj-col-body`,
|
||||
섹션 id/이름 기준)·보드 가로 스크롤을 저장했다가 되돌린다**(작업 창 닫기·완료 체크·8초 갱신 후에도 보던 자리).
|
||||
작업 창을 닫으면 펼친 카드의 하위 작업을 먼저 다 받은 뒤 한 번에 다시 그린다(짧아진 채 그리면 스크롤이 밀림). 섹션은 아사나처럼 **가로로 계속 늘어난다** — 화면을 넘치면
|
||||
|
||||
@@ -684,6 +684,36 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
|
||||
const d = env.d;
|
||||
check("[프로젝트 줄] 읽기 전용은 연결 목록만 표시", d.getElementById("pj-link-form").hidden && d.getElementById("pj-links-block").classList.contains("is-readonly") && !!d.querySelector(".pj-link-chip") && !d.querySelector(".pj-link-del"));
|
||||
}
|
||||
// ── 대시보드 담당자별 작업 합계 — 메인·하위 분리, 완료 수, 마감일 없어도 포함, 다른 범위 하위 작업 제외 ──
|
||||
{
|
||||
const env = makeEnv(); baseRoutes(env);
|
||||
env.d.querySelector(".pj-project-view").dataset.isAdmin = "true";
|
||||
let asked = null;
|
||||
env.route("GET", /\/project\/api\/projects\/1\/subtasks-summary\?scope=project$/, function (u) {
|
||||
asked = u;
|
||||
return { body: { subtasks: [
|
||||
{ parent_task_id: 101, assignee_email: "me@test.local", assignee_name: "Me", done: true },
|
||||
{ parent_task_id: 101, assignee_email: "bob@test.local", assignee_name: "Bob", done: false },
|
||||
{ parent_task_id: 103, assignee_email: "bob@test.local", assignee_name: "Bob", done: true }, // 다른 프로젝트 작업의 하위
|
||||
] } };
|
||||
});
|
||||
const P = await boot(env);
|
||||
P.state().tasks.forEach(function (t) {
|
||||
if (t.id === 101) Object.assign(t, { assignee_email: "me@test.local", assignee_name: "Me", completed_at: "2026-09-29T10:00:00+09:00" });
|
||||
if (t.id === 102) Object.assign(t, { assignee_email: "me@test.local", assignee_name: "Me" });
|
||||
if (t.id === 301) Object.assign(t, { assignee_email: "bob@test.local", assignee_name: "Bob" });
|
||||
});
|
||||
env.d.querySelector('.pj-tab[data-view="dashboard"]').click(); await settle();
|
||||
const rows = Array.from(env.d.querySelectorAll(".pj-wl-table tbody tr")).map(function (tr) {
|
||||
return Array.from(tr.children).slice(0, 4).map(function (c) { return c.textContent.trim(); }).join("|");
|
||||
});
|
||||
const totalRow = env.d.querySelector(".pj-wl-total");
|
||||
const total = totalRow ? totalRow.textContent.replace(/\s+/g, " ") : "";
|
||||
check("[대시보드 담당자별] 하위 작업 요청(이 프로젝트 범위)", !!asked);
|
||||
check("[대시보드 담당자별] 사람별 메인·하위·전체(마감일 없는 작업 포함, 다른 프로젝트 하위 제외)",
|
||||
JSON.stringify(rows) === JSON.stringify(["Me|2|1|3", "Bob|1|1|2"]), rows);
|
||||
check("[대시보드 담당자별] 합계 줄 완료 2/5 (40%) — 메인 완료 1 + 하위 완료 1", /2 \/ 5 40%/.test(total), total);
|
||||
}
|
||||
clearTimeout(WATCHDOG);
|
||||
console.log(fails.length ? "\nFAILED: " + fails.join(", ") : "\nALL PASS");
|
||||
process.exit(fails.length ? 1 : 0);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""대시보드 담당자별 작업 합계 — 하위 작업 요약 API(subtasks-summary) 범위·권한. DB 없이 가짜 저장소로."""
|
||||
import importlib
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
api = importlib.import_module("app.modules.project.router")
|
||||
|
||||
|
||||
class FakeStore:
|
||||
def __init__(self):
|
||||
self.asked_projects, self.asked_parents = None, None
|
||||
|
||||
def list_projects(self, include_archived, member_email):
|
||||
return [{"id": 1, "parent_id": None}, {"id": 2, "parent_id": None}, {"id": 5, "parent_id": 1}]
|
||||
|
||||
def list_tasks_for_projects(self, project_ids):
|
||||
self.asked_projects = project_ids
|
||||
return [{"id": 10 * pid} for pid in project_ids]
|
||||
|
||||
def list_subtasks_of(self, parent_ids):
|
||||
self.asked_parents = parent_ids
|
||||
return [{"parent_task_id": parent_ids[0], "assignee_email": "a@test", "assignee_name": "A", "done": True}]
|
||||
|
||||
|
||||
class SubtaskSummaryTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
app = FastAPI()
|
||||
app.include_router(api.router)
|
||||
self.client = TestClient(app)
|
||||
self.st = FakeStore()
|
||||
|
||||
def call(self, scope):
|
||||
with patch.object(api, "_require_user", return_value={"email": "me@test"}), \
|
||||
patch.object(api, "_db_or_503", return_value=self.st), \
|
||||
patch.object(api, "_require_manage", return_value=None), \
|
||||
patch.object(api, "_accessible_project_ids", return_value=None):
|
||||
return self.client.get(f"/project/api/projects/1/subtasks-summary?scope={scope}")
|
||||
|
||||
def test_project_scope_uses_only_this_project(self):
|
||||
r = self.call("project")
|
||||
self.assertEqual(r.status_code, 200, r.text)
|
||||
self.assertEqual(self.st.asked_projects, [1])
|
||||
self.assertEqual(self.st.asked_parents, [10])
|
||||
self.assertEqual(r.json()["subtasks"][0]["done"], True)
|
||||
|
||||
def test_all_scope_uses_top_level_projects(self):
|
||||
self.call("all")
|
||||
self.assertEqual(self.st.asked_projects, [1, 2]) # 서브프로젝트(5) 제외 — 스냅샷과 같은 범위
|
||||
|
||||
def test_no_access_is_rejected(self):
|
||||
with patch.object(api, "_require_user", return_value={"email": "me@test"}), \
|
||||
patch.object(api, "_db_or_503", return_value=self.st), \
|
||||
patch.object(api, "_require_manage", side_effect=HTTPException(403)):
|
||||
self.assertEqual(self.client.get("/project/api/projects/1/subtasks-summary").status_code, 403)
|
||||
self.assertIsNone(self.st.asked_parents)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user