feat(project): 검색·필터·정렬 + 팔로워 + 마감 알림
검색·필터·정렬 - 좌측 사이드바 전체 검색(/api/search): 제목·설명·댓글, 볼 수 있는 프로젝트의 업무(하위 업무 포함). 설명 HTML 태그에만 걸린 결과는 본문 텍스트로 재확인해 제거. 어디서 걸렸는지 + 미리보기, 키보드(/ ↑↓ Enter). - 프로젝트 화면 필터 바: 찾기·상태·담당자·마감·우선순위·정렬. visibleTasks() 에서 걸러 보드/리스트/달력/타임라인/대시보드 모두 적용, 프로젝트별 기억. 필터·정렬 중엔 보드 카드 순서 드래그 차단. - 내 업무 화면에도 찾기·마감·우선순위 필터. 팔로워 · 알림 - task_followers(008): 만든 사람·담당자·댓글 작성자·@태그된 사람 자동 팔로우, 기존 업무 백필. 업무 팝업에서 추가/빼기/내 팔로우 토글. - 완료·댓글 인앱 알림 수신자: 프로젝트 멤버 전원 → 담당자 + 팔로워. 008 미적용이면 예전 방식 폴백. - 마감 알림(reminders.py, lifespan 에서 데몬 스레드): 영업일(주말·공휴일 skip) 09시 KST 1회, 다음 영업일까지 마감/오늘 마감/지남(7일 이내). 수신자 담당자(없으면 팔로워). task_reminders UNIQUE 로 중복 방지, 마감일 바뀌면 재알림. PROJECT_REMINDER_EMAIL=true 면 요약 메일. - 008: pg_trgm GIN 인덱스(제목·설명·댓글), 미완료 마감일 부분 인덱스. 버그 - 업무 팝업 담당자 선택지가 프로젝트 멤버뿐이라, 멤버 목록에 없는 담당자 (프로젝트 owner, 멤버에서 빠진 사람)의 업무를 열고 저장하면 담당자가 지워지던 문제 수정. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1155,6 +1155,127 @@ class ProjectStore:
|
||||
)
|
||||
return cur.rowcount or 0
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 팔로워(task_followers, 마이그레이션 008) — 아사나의 "협업자".
|
||||
# 업무 알림(완료·댓글)은 담당자 + 팔로워에게만 간다. 008 미적용이면
|
||||
# psycopg_errors.UndefinedTable 이 나고, 라우터가 예전 동작으로 폴백한다.
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def list_followers(self, *, task_id: int) -> list[str]:
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT user_email FROM task_followers WHERE task_id = %s "
|
||||
"ORDER BY created_at ASC, user_email ASC",
|
||||
(task_id,),
|
||||
).fetchall()
|
||||
return [r["user_email"] for r in rows]
|
||||
|
||||
def add_followers(self, *, task_id: int, emails: list[str]) -> list[str]:
|
||||
"""팔로워 추가(이미 있으면 무시). 새로 추가된 이메일만 돌려준다."""
|
||||
targets = store.normalize_emails(emails)
|
||||
if not targets:
|
||||
return []
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"INSERT INTO task_followers (task_id, user_email) "
|
||||
"SELECT %s, e FROM unnest(%s::text[]) AS e "
|
||||
"ON CONFLICT DO NOTHING RETURNING user_email",
|
||||
(task_id, targets),
|
||||
).fetchall()
|
||||
return [r["user_email"] for r in rows]
|
||||
|
||||
def remove_follower(self, *, task_id: int, user_email: str) -> None:
|
||||
with self._pool.connection() as conn:
|
||||
conn.execute(
|
||||
"DELETE FROM task_followers WHERE task_id = %s AND user_email = %s",
|
||||
(task_id, store.norm_str(user_email, lower=True)),
|
||||
)
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 전체 검색 — 제목·설명·댓글 (008 의 pg_trgm 인덱스가 있으면 그걸 탄다)
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def search_tasks(
|
||||
self, *, query: str, project_ids: set[int] | None, limit: int = 30,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""제목/설명/댓글에 검색어가 들어간 업무(하위 업무 포함).
|
||||
|
||||
project_ids 가 None 이면 전체(관리자), 아니면 그 프로젝트들만.
|
||||
설명은 HTML 이라 태그 이름·속성에만 걸린 경우(예: "img")를 걸러내려고
|
||||
넉넉히 가져온 뒤 라우터가 본문 텍스트로 다시 확인한다.
|
||||
"""
|
||||
q = store.norm_str(query)
|
||||
if not q:
|
||||
return []
|
||||
if project_ids is not None and not project_ids:
|
||||
return []
|
||||
pat = "%" + q.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%"
|
||||
params: dict[str, Any] = {"pat": pat, "limit": int(limit)}
|
||||
scope = ""
|
||||
if project_ids is not None:
|
||||
scope = "AND t.project_id = ANY(%(ids)s)"
|
||||
params["ids"] = sorted(project_ids)
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
f"""
|
||||
SELECT t.id, t.title, t.description, t.project_id, t.parent_task_id,
|
||||
t.completed_at, t.due_date, t.assignee_email,
|
||||
p.name AS project_name, p.color AS project_color,
|
||||
pt.title AS parent_title,
|
||||
(t.title ILIKE %(pat)s) AS hit_title,
|
||||
(SELECT c.body FROM task_comments c
|
||||
WHERE c.task_id = t.id AND c.body ILIKE %(pat)s
|
||||
ORDER BY c.created_at DESC LIMIT 1) AS comment_hit
|
||||
FROM tasks t
|
||||
JOIN projects p ON p.id = t.project_id
|
||||
LEFT JOIN tasks pt ON pt.id = t.parent_task_id
|
||||
WHERE (t.title ILIKE %(pat)s
|
||||
OR t.description ILIKE %(pat)s
|
||||
OR t.id IN (SELECT c.task_id FROM task_comments c WHERE c.body ILIKE %(pat)s))
|
||||
{scope}
|
||||
ORDER BY (t.title ILIKE %(pat)s) DESC, (t.completed_at IS NULL) DESC,
|
||||
t.updated_at DESC, t.id DESC
|
||||
LIMIT %(limit)s
|
||||
""",
|
||||
params,
|
||||
).fetchall()
|
||||
return [self._serialize(r) for r in rows]
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 마감 알림 (task_reminders, 마이그레이션 008) — reminders.py 가 부른다
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def list_open_tasks_due_between(self, *, start: date, end: date) -> list[dict[str, Any]]:
|
||||
"""미완료 + 마감일이 [start, end] 인 업무(하위 업무 포함) + 팔로워 목록.
|
||||
보관(archived) 프로젝트는 뺀다."""
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT t.id, t.title, t.due_date, t.assignee_email, t.project_id,
|
||||
t.parent_task_id, p.name AS project_name,
|
||||
COALESCE((SELECT array_agg(f.user_email ORDER BY f.user_email)
|
||||
FROM task_followers f WHERE f.task_id = t.id),
|
||||
'{}'::text[]) AS followers
|
||||
FROM tasks t
|
||||
JOIN projects p ON p.id = t.project_id
|
||||
WHERE t.completed_at IS NULL
|
||||
AND t.due_date BETWEEN %s AND %s
|
||||
AND p.status <> 'archived'
|
||||
ORDER BY t.due_date ASC, t.id ASC
|
||||
""",
|
||||
(start, end),
|
||||
).fetchall()
|
||||
return [self._serialize(r) for r in rows]
|
||||
|
||||
def record_reminder(
|
||||
self, *, task_id: int, kind: str, due_date: str, recipient_email: str,
|
||||
) -> bool:
|
||||
"""이 알림을 처음 보내는 거면 기록하고 True. 이미 보냈으면 False(중복 방지)."""
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute(
|
||||
"INSERT INTO task_reminders (task_id, kind, due_date, recipient_email) "
|
||||
"VALUES (%s,%s,%s,%s) ON CONFLICT DO NOTHING RETURNING id",
|
||||
(task_id, kind, due_date, store.norm_str(recipient_email, lower=True)),
|
||||
).fetchone()
|
||||
return row is not None
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 실시간 새로고침 — 프로젝트/업무/댓글/멤버/단계 중 가장 최근 변경 시각
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user