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:
@@ -18,13 +18,24 @@ ROWS = [ # 최신순(list_notifications 와 같게)
|
||||
|
||||
|
||||
class FakeStore:
|
||||
"""list_notifications(최신순) + list_unread_after(DB 쪽 조건·오래된 것부터) — db.py 와 같은 의미."""
|
||||
desktop = False
|
||||
|
||||
def __init__(self, rows=None):
|
||||
self.rows = list(ROWS if rows is None else rows)
|
||||
self.pages = 0
|
||||
|
||||
def notifier_active(self, email):
|
||||
return self.desktop
|
||||
|
||||
def list_notifications(self, recipient_email, unread_only=False, limit=100):
|
||||
rows = [r for r in ROWS if not unread_only or not r["is_read"]]
|
||||
rows = sorted((r for r in self.rows if not unread_only or not r["is_read"]), key=lambda r: -r["id"])
|
||||
return rows[:limit]
|
||||
|
||||
def list_unread_after(self, recipient_email, after_id, types, limit=200):
|
||||
self.pages += 1
|
||||
rows = sorted((r for r in self.rows if not r["is_read"] and r["id"] > after_id and r["type"] in types),
|
||||
key=lambda r: r["id"])
|
||||
return rows[:limit]
|
||||
|
||||
|
||||
@@ -34,12 +45,13 @@ class AlertsApiTests(unittest.TestCase):
|
||||
app.include_router(api.router)
|
||||
self.client = TestClient(app)
|
||||
|
||||
def get(self, qs="", desktop=False):
|
||||
st = FakeStore()
|
||||
def get(self, qs="", desktop=False, st=None, visible=None):
|
||||
st = st or FakeStore()
|
||||
st.desktop = desktop
|
||||
vis = visible or (lambda st, user, items: items)
|
||||
with patch.object(api, "_require_user", return_value={"email": "Me@Test.local"}), \
|
||||
patch.object(api, "_db_or_503", return_value=st), \
|
||||
patch.object(api, "_visible_notifications", side_effect=lambda st, user, items: items):
|
||||
patch.object(api, "_visible_notifications", side_effect=vis):
|
||||
return self.client.get("/project/api/notifications/alerts" + qs).json()
|
||||
|
||||
def test_without_after_returns_only_baseline(self):
|
||||
@@ -52,6 +64,13 @@ class AlertsApiTests(unittest.TestCase):
|
||||
self.assertEqual(out["alerts"][1]["type"], "mention")
|
||||
self.assertNotIn("desktop", out)
|
||||
|
||||
def test_alert_links_use_task_permalink(self):
|
||||
# 작업 알림은 /project/t/{id} — 연결된 프로젝트에서만 읽을 수 있는 사람도 403 없이 열린다
|
||||
out = self.get("?after=5")
|
||||
self.assertEqual([a["href"] for a in out["alerts"]], ["/project/t/3", "/project/t/1"])
|
||||
st = FakeStore([{"id": 3, "type": "mention", "is_read": False, "task_id": None, "project_id": 4}])
|
||||
self.assertEqual(self.get("?after=0", st=st)["alerts"][0]["href"], "/project/p/4")
|
||||
|
||||
def test_pc_notifier_running_silences_web_popup(self):
|
||||
out = self.get("?after=5", desktop=True)
|
||||
self.assertEqual((out["alerts"], out["latest_id"], out["desktop"]), ([], 9, True))
|
||||
@@ -60,12 +79,39 @@ class AlertsApiTests(unittest.TestCase):
|
||||
class Broken(FakeStore):
|
||||
def notifier_active(self, email):
|
||||
raise RuntimeError("db down")
|
||||
with patch.object(api, "_require_user", return_value={"email": "me@test.local"}), \
|
||||
patch.object(api, "_db_or_503", return_value=Broken()), \
|
||||
patch.object(api, "_visible_notifications", side_effect=lambda st, user, items: items):
|
||||
out = self.client.get("/project/api/notifications/alerts?after=5").json()
|
||||
out = self.get("?after=5", st=Broken())
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [6, 8])
|
||||
|
||||
# ── 예전엔 최신 50건을 자른 뒤 걸러서 빠지던 경우들 ──
|
||||
def test_assignment_behind_fifty_comment_alerts_is_not_lost(self):
|
||||
rows = [{"id": 1, "type": "assigned", "title": "배정", "is_read": False, "task_id": 1, "project_id": 1}]
|
||||
rows += [{"id": 100 + i, "type": "comment", "title": "댓글", "is_read": False, "task_id": 1, "project_id": 1}
|
||||
for i in range(50)]
|
||||
out = self.get("?after=0", st=FakeStore(rows))
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [1])
|
||||
|
||||
def test_more_than_sixty_assignments_page_oldest_first(self):
|
||||
rows = [{"id": i, "type": "assigned", "title": f"배정{i}", "is_read": False, "task_id": i, "project_id": 1}
|
||||
for i in range(1, 66)]
|
||||
st = FakeStore(rows)
|
||||
out = self.get("?after=0", st=st)
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], list(range(1, 11))) # 오래된 것부터 10건
|
||||
out = self.get("?after=10", st=st) # 닫으면 그 뒤 것(화면이 본 것=10 으로 다시 묻는다)
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], list(range(11, 21)))
|
||||
out = self.get("?after=60", st=st)
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [61, 62, 63, 64, 65])
|
||||
|
||||
def test_invisible_alerts_ahead_do_not_hide_visible_ones(self):
|
||||
# 앞쪽 450건은 지금 볼 수 없는 작업(권한 회수) — 페이지를 넘겨 그 뒤의 볼 수 있는 알림을 찾는다
|
||||
rows = [{"id": i, "type": "mention", "title": "x", "is_read": False, "task_id": 9, "project_id": 9}
|
||||
for i in range(1, 451)]
|
||||
rows.append({"id": 500, "type": "mention", "title": "보임", "is_read": False, "task_id": 1, "project_id": 1})
|
||||
st = FakeStore(rows)
|
||||
out = self.get("?after=0", st=st,
|
||||
visible=lambda st, user, items: [n for n in items if n["project_id"] == 1])
|
||||
self.assertEqual([a["id"] for a in out["alerts"]], [500])
|
||||
self.assertEqual(st.pages, 3) # 200·200·51 — 끝까지 읽고 멈춘다
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user