89ad338024
- 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>
118 lines
6.0 KiB
Python
118 lines
6.0 KiB
Python
"""알림 팝업 API — 기준점·태그/배정만·읽지 않은 것·after 이후·오래된 것부터. DB 없이 가짜 저장소로."""
|
|
import importlib
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
api = importlib.import_module("app.modules.project.router")
|
|
|
|
ROWS = [ # 최신순(list_notifications 와 같게)
|
|
{"id": 9, "type": "completed", "title": "완료", "is_read": False, "task_id": 1, "project_id": 1},
|
|
{"id": 8, "type": "mention", "title": "나를 태그함: A", "is_read": False, "task_id": 1, "project_id": 1},
|
|
{"id": 7, "type": "assigned", "title": "작업 배정: B", "is_read": True, "task_id": 2, "project_id": 1},
|
|
{"id": 6, "type": "assigned", "title": "작업 배정: C", "is_read": False, "task_id": 3, "project_id": 1},
|
|
{"id": 2, "type": "assigned", "title": "작업 배정: 옛것", "is_read": False, "task_id": 4, "project_id": 1},
|
|
]
|
|
|
|
|
|
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 = 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]
|
|
|
|
|
|
class AlertsApiTests(unittest.TestCase):
|
|
def setUp(self):
|
|
app = FastAPI()
|
|
app.include_router(api.router)
|
|
self.client = TestClient(app)
|
|
|
|
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=vis):
|
|
return self.client.get("/project/api/notifications/alerts" + qs).json()
|
|
|
|
def test_without_after_returns_only_baseline(self):
|
|
out = self.get()
|
|
self.assertEqual((out["me"], out["latest_id"], out["alerts"]), ("me@test.local", 9, []))
|
|
|
|
def test_after_returns_unread_mentions_and_assignments_oldest_first(self):
|
|
out = self.get("?after=5")
|
|
self.assertEqual([a["id"] for a in out["alerts"]], [6, 8]) # 완료 알림(9)·읽은 것(7)·옛것(2) 제외
|
|
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))
|
|
|
|
def test_notifier_check_failure_keeps_web_popup(self):
|
|
class Broken(FakeStore):
|
|
def notifier_active(self, email):
|
|
raise RuntimeError("db down")
|
|
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()
|