fix(project): review fixes — access leaks, open paths, save safety, concurrency
- Subproject tasks via parent /tasks are re-filtered by current access (FULL/READ kept)
- PUT /api/projects/order: every id must be manageable; bad/duplicate ids -> 400, all-or-nothing
- Inbox, web alert popup, PC notifier open tasks via /project/t/{id}; embed=1 survives redirect;
old /p/{home}?task= redirects READ users to the linked project
- Project page / snapshot / workload include the opened archived or sub project only
- Alerts: DB-side filters + oldest-first paging (no 50-row cut); badges counted without caps;
my tasks keep every open task (completed capped)
- Meeting results: next-week meeting open, or own meeting open when no next meeting;
header edits + result checks under row locks (FOR UPDATE / FOR SHARE)
- Inbox panel waits for the task window save (same retry/discard flow) before switching/closing;
read failures stay unread
- Attachment upload removes only its own file on DB failure
- New project modal: create once, retry only failed member assignments
- update_task / update_project: locked-row validation in one transaction; completion hints from real transition
- Creator added as explicit member when another owner is chosen
- _once lock lifetime managed by refcount (no leak on failure)
- Section default assignee must still be a registered project user; follower add uses can_assign
- Docs (PROJECT_MODULE 6-15, help), tests (DB-less, real PostgreSQL, jsdom, Chrome)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -346,7 +346,7 @@ def test_file_comment_atomic_and_idempotent():
|
||||
# [04] 날짜 범위
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def test_date_range_validation():
|
||||
p = _project("P-date", ADMIN, (BOB,))
|
||||
p = _project("P-date", ADMIN, (BOB, PRO))
|
||||
s = _stage(p["id"], by=ADMIN)
|
||||
base = f"/project/api/projects/{p['id']}/tasks"
|
||||
assert req("POST", base, BOB, json={"title": "bad", "stage_id": s["id"], "start_date": "2026-10-05", "due_date": "2026-10-01"}).status_code == 400
|
||||
@@ -359,11 +359,11 @@ def test_date_range_validation():
|
||||
assert req("PUT", u, BOB, json={"start_date": "2026-09-30", "start_time": "18:00", "due_time": "09:00"}).status_code == 400
|
||||
assert req("PUT", u, BOB, json={"start_date": "2026-09-30", "start_time": "00:00", "due_time": "23:59"}).status_code == 200
|
||||
assert req("PUT", u, BOB, json={"start_date": "2026-09-30", "start_time": "09:00", "due_time": "09:00"}).status_code == 200
|
||||
# 프로젝트도 같은 규칙(부분 수정 포함)
|
||||
# 프로젝트도 같은 규칙(부분 수정 포함) — 프로젝트 수정은 Pro user 이상 멤버(2026-10-12)
|
||||
pu = f"/project/api/projects/{p['id']}"
|
||||
assert req("PUT", pu, BOB, json={"start_date": "2026-11-01", "due_date": "2026-10-01"}).status_code == 400
|
||||
assert req("PUT", pu, BOB, json={"due_date": "2026-10-01"}).status_code == 200
|
||||
assert req("PUT", pu, BOB, json={"start_date": "2026-11-01"}).status_code == 400
|
||||
assert req("PUT", pu, PRO, json={"start_date": "2026-11-01", "due_date": "2026-10-01"}).status_code == 400
|
||||
assert req("PUT", pu, PRO, json={"due_date": "2026-10-01"}).status_code == 200
|
||||
assert req("PUT", pu, PRO, json={"start_date": "2026-11-01"}).status_code == 400
|
||||
assert req("POST", "/project/api/projects", PRO, json={"name": "d", "start_date": "2026-11-02", "due_date": "2026-11-01"}).status_code == 400
|
||||
|
||||
|
||||
@@ -1031,6 +1031,141 @@ def test_meeting_perf_unknown_vs_zero():
|
||||
_drop_meetings([w, w - timedelta(days=7)])
|
||||
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# [검토 2026-10-12] 실제 DB — 동시성·조회 범위·알림 페이지·배지·회의록 결과 잠금
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def _race(fns):
|
||||
"""함수들을 최대한 같은 순간에 돌리고 (결과 또는 예외) 목록."""
|
||||
gate = threading.Barrier(len(fns))
|
||||
out: list = [None] * len(fns)
|
||||
|
||||
def run(i, fn):
|
||||
gate.wait()
|
||||
try:
|
||||
out[i] = fn()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
out[i] = exc
|
||||
ths = [threading.Thread(target=run, args=(i, f)) for i, f in enumerate(fns)]
|
||||
[t.start() for t in ths]
|
||||
[t.join() for t in ths]
|
||||
return out
|
||||
|
||||
|
||||
def test_review_task_dates_never_invert_under_race():
|
||||
p = _project("P-race", ADMIN, (BOB,))
|
||||
s = _stage(p["id"], by=ADMIN)
|
||||
for _ in range(10):
|
||||
t = ST.create_task(project_id=p["id"], title="race", stage_id=s["id"],
|
||||
start_date="2026-10-10", due_date="2026-10-20", created_by=BOB)
|
||||
_race([lambda: ST.update_task(task_id=t["id"], fields={"start_date": "2026-10-18"}),
|
||||
lambda: ST.update_task(task_id=t["id"], fields={"due_date": "2026-10-12"})])
|
||||
got = ST.get_task(task_id=t["id"])
|
||||
assert got["start_date"] <= got["due_date"], got # 한쪽은 지금 값으로 검사돼 거절된다
|
||||
# 프로젝트도 같은 규칙
|
||||
for _ in range(5):
|
||||
q = ST.create_project(name=f"race-{uuid.uuid4().hex[:4]}", owner_email=ADMIN, created_by=ADMIN,
|
||||
start_date="2026-10-10", due_date="2026-10-20")
|
||||
_race([lambda: ST.update_project(project_id=q["id"], fields={"start_date": "2026-10-18"}),
|
||||
lambda: ST.update_project(project_id=q["id"], fields={"due_date": "2026-10-12"})])
|
||||
got = ST.get_project(project_id=q["id"])
|
||||
assert got["start_date"] <= got["due_date"], got
|
||||
|
||||
|
||||
def test_review_concurrent_completion_logs_once():
|
||||
p = _project("P-done-race", ADMIN, (BOB,))
|
||||
s = _stage(p["id"], by=ADMIN)
|
||||
t = ST.create_task(project_id=p["id"], title="once", stage_id=s["id"], created_by=BOB)
|
||||
outs = _race([lambda: ST.update_task(task_id=t["id"], fields={"completed": True}, actor=BOB) for _ in range(4)])
|
||||
assert sum(1 for o in outs if isinstance(o, dict) and o["_newly_completed"]) == 1, outs
|
||||
assert _count("SELECT COUNT(*) AS n FROM project_activity WHERE task_id = %s AND action = 'completed'", t["id"]) == 1
|
||||
|
||||
|
||||
def test_review_subproject_tasks_and_archived_scope():
|
||||
parent = _project("P-parent", ADMIN, (BOB, CAROL))
|
||||
child = ST.create_project(name=f"child-{uuid.uuid4().hex[:4]}", parent_id=parent["id"], owner_email=ADMIN, created_by=ADMIN)
|
||||
ST.add_member(project_id=child["id"], user_email=CAROL)
|
||||
tp = ST.create_task(project_id=parent["id"], title="부모", created_by=ADMIN)
|
||||
tc = ST.create_task(project_id=child["id"], title="자식", created_by=ADMIN)
|
||||
ids = lambda who: sorted(t["id"] for t in req("GET", f"/project/api/projects/{parent['id']}/tasks", who).json()["tasks"])
|
||||
assert ids(BOB) == [tp["id"]] # 부모 멤버·자식 비멤버 — 자식 작업 안 보임
|
||||
assert ids(CAROL) == sorted([tp["id"], tc["id"]])
|
||||
assert req("GET", f"/project/api/projects/{parent['id']}/tasks", ADMIN).status_code == 200 # ADMIN = owner
|
||||
# 보관된 프로젝트를 열어도 자기 작업은 받는다(스냅샷)
|
||||
arch = _project("P-arch", BOB)
|
||||
ta = ST.create_task(project_id=arch["id"], title="보관 작업", created_by=BOB)
|
||||
ST.update_project(project_id=arch["id"], fields={"status": "archived"})
|
||||
snap = req("GET", f"/project/api/projects/{arch['id']}/snapshot?scope=all", BOB).json()
|
||||
assert ta["id"] in [t["id"] for t in snap["tasks"]]
|
||||
assert [x["id"] for x in snap["projects"] if x.get("view_only")] == [arch["id"]]
|
||||
|
||||
|
||||
def test_review_alert_paging_and_badges():
|
||||
me = USERS.add(f"alert-{uuid.uuid4().hex[:6]}@test.local")
|
||||
p = _project("P-alert", ADMIN, (me,))
|
||||
t = ST.create_task(project_id=p["id"], title="x", created_by=ADMIN)
|
||||
ST.add_notification(recipient_email=me, actor_email=ADMIN, project_id=p["id"], task_id=t["id"], type="assigned", title="배정")
|
||||
for _ in range(55):
|
||||
ST.add_notification(recipient_email=me, actor_email=ADMIN, project_id=p["id"], task_id=t["id"], type="comment", title="댓글")
|
||||
out = req("GET", "/project/api/notifications/alerts?after=0", me).json()
|
||||
assert [a["type"] for a in out["alerts"]] == ["assigned"] and out["alerts"][0]["href"] == f"/project/t/{t['id']}"
|
||||
assert req("GET", "/project/api/notifications/unread-count", me).json()["unread"] == 56
|
||||
# 권한을 잃은 프로젝트의 알림은 배지에서 빠진다(기록은 그대로)
|
||||
ST.remove_member(project_id=p["id"], user_email=me)
|
||||
assert req("GET", "/project/api/notifications/unread-count", me).json()["unread"] == 0
|
||||
# 내 작업 배지·목록 — 미완료는 전부, 완료는 최근 것만
|
||||
q = _project("P-my", ADMIN, (me,))
|
||||
open_ids = [ST.create_task(project_id=q["id"], title=f"o{i}", assignee_email=me, created_by=ADMIN)["id"] for i in range(3)]
|
||||
done_ids = []
|
||||
for i in range(3):
|
||||
d = ST.create_task(project_id=q["id"], title=f"d{i}", assignee_email=me, created_by=ADMIN)
|
||||
ST.update_task(task_id=d["id"], fields={"completed": True})
|
||||
done_ids.append(d["id"])
|
||||
rows = ST.list_my_tasks(assignee_email=me, completed_limit=1)
|
||||
assert sorted(r["id"] for r in rows if not r["completed_at"]) == sorted(open_ids)
|
||||
assert [r["id"] for r in rows if r["completed_at"]] == [done_ids[-1]]
|
||||
assert req("GET", "/project/api/my-tasks/open-count", me).json()["open"] == 3
|
||||
ST.add_mentions(task_id=open_ids[0], emails=[me], actor_email=ADMIN)
|
||||
assert req("GET", "/project/api/mentions/unread-count", me).json()["unread"] == 1
|
||||
|
||||
|
||||
def test_review_reorder_and_creator_membership():
|
||||
mine = _project("P-ord", PRO)
|
||||
other = _project("P-ord-other", ADMIN)
|
||||
assert req("PUT", "/project/api/projects/order", PRO, json={"ordered_ids": [mine["id"], other["id"]]}).status_code == 403
|
||||
assert req("PUT", "/project/api/projects/order", PRO, json={"ordered_ids": [mine["id"], mine["id"]]}).status_code == 400
|
||||
assert req("PUT", "/project/api/projects/order", PRO, json={"ordered_ids": [mine["id"]]}).status_code == 200
|
||||
r = req("POST", "/project/api/projects", PRO, json={"name": f"own-{RUN}", "owner_email": ALICE})
|
||||
assert r.status_code == 201, r.text
|
||||
pid = r.json()["project"]["id"]
|
||||
assert ST.get_project(project_id=pid)["owner_email"] == ALICE
|
||||
assert req("GET", f"/project/p/{pid}", PRO).status_code == 200 # 만든 직후 자기 프로젝트를 연다(멤버 행)
|
||||
ST.remove_member(project_id=pid, user_email=PRO)
|
||||
assert req("GET", f"/project/p/{pid}", PRO).status_code == 403 # created_by 로는 권한이 남지 않는다
|
||||
|
||||
|
||||
def test_review_meeting_result_lock_rules():
|
||||
from app.modules.project import store
|
||||
|
||||
w2 = date(2031, 10, 1) # 수요일 시작 1주차(달 경계)
|
||||
w1 = store.prev_week_period(w2)[0] # 9월 마지막 주차
|
||||
_drop_meetings([w1, w2])
|
||||
try:
|
||||
_create_meeting(w1)
|
||||
item = ST.get_meeting(week_start=w1)["items"][0]["id"]
|
||||
put = lambda body: req("PUT", f"/project/api/goals/meeting-items/{item}", BOB, json=body).status_code
|
||||
ST.set_meeting_completed(week_start=w1, done=True, by=ADMIN)
|
||||
assert put({"result_note": "다음 회의 전"}) == 409 # 다음 주차 회의록이 없으면 그 주가 완료되면 잠김
|
||||
_create_meeting(w2)
|
||||
assert put({"result_note": "다음 회의에서"}) == 200 # 다음 주차 회의록이 열려 있으면 결과는 적을 수 있다
|
||||
assert put({"content": "내용"}) == 409 # 주요 업무는 그 주 완료로 잠김(잠금 차이 보존)
|
||||
ST.set_meeting_completed(week_start=w2, done=True, by=ADMIN)
|
||||
assert put({"result_note": "늦게"}) == 409
|
||||
r = req("PUT", f"/project/api/goals/meetings/{w2}", BOB, json={"notes": "잠김"})
|
||||
assert r.status_code == 409, r.text # 완료된 회의록 머리도
|
||||
finally:
|
||||
_drop_meetings([w1, w2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if not ENABLED:
|
||||
print("SKIP: PROJECT_TEST_DB_URL(localhost) not set")
|
||||
|
||||
Reference in New Issue
Block a user