fix(project): 권한 우회·작업 혼선·저장 유실 등 16개 항목 수정 — 지금 권한 기준·읽기 전용 연결 작업·원자적 파일 댓글
권한(서버) - 공통 권한 모듈 access.py: 모든 판단을 "지금" 권한으로 — 내 작업·수신함·알림·멘션·검색·상세·공유 링크· 댓글·첨부·알림/메일 수신자에서 권한을 잃은 사람 제외(기록은 이력으로 보존) - 소유자 변경·남을 소유자로 지정한 생성은 관리자만, 새 소유자는 권한 있는 등록 사용자 - 삭제는 생성자 규칙 + 지금 권한(멤버에서 빠진 생성자 거절), 댓글 수정·삭제도 지금 권한 - @태그는 볼 수 있는 사람만(mention_skipped), 태그 후보 all-users?task_id=, 새 담당자 권한 검사 - 연결(멀티호밍) 작업은 연결된 프로젝트 멤버에게 읽기 전용(task_link_scope), 볼 수 없는 연결 프로젝트 숨김 저장·동기화(화면) - 작업 창 세대(taskGen)·블록 ctxSeq 로 늦은 A 응답이 B 를 덮지 않게(A→B, A→B→A, 이미지 업로드 중 전환) - 자동 저장 성공/실패 반환, 실패 칸 재시도, 닫기·전환 전 저장 확인(버리기/계속 편집), 미저장 이탈 경고 - 실시간 동기화 observed/applied 분리·실패 재시도·겹침 방지, snapshot?scope=all 로 전체 범위 반영·권한 회수 안내 - 한국시간 기준 오늘(kstTodayIso), 한글 조합 중 Enter 는 제출하지 않음, 댓글 연타·재전송 중복 방지(client_token) 기타 - 파일 댓글은 본문+파일 한 트랜잭션(POST /comments/files), 실패 파일 표시·유지, 작업 창 댓글에 첨부 표시 - 날짜 범위 검증(부분 수정은 최종 상태), 완료 섹션에 바로 만든 작업 완료 처리·알림 - 마감 알림 발송 기록+수신함 알림 원자적(실패 시 재시도), 권한 없는 수신자 제외 - 테스트: tests/test_project_module.py(로컬 PostgreSQL 11개), tests/js/project_ui.test.js(jsdom 51개) - 문서(PROJECT_MODULE 6-10·도움말·CLAUDE.md), project.js/css 캐시 버전 20260930g, 새 마이그레이션·환경변수 없음 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+137
-5
@@ -100,6 +100,7 @@ class ProjectStore:
|
||||
ic = store.validate_project_icon(icon)
|
||||
sd = store.validate_date(start_date)
|
||||
dd = store.validate_date(due_date)
|
||||
store.validate_date_range(sd, dd)
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
if parent_id is not None:
|
||||
@@ -158,15 +159,26 @@ class ProjectStore:
|
||||
}
|
||||
sets: list[str] = []
|
||||
params: list[Any] = []
|
||||
clean: dict[str, Any] = {}
|
||||
for key, fn in allowed.items():
|
||||
if key in fields:
|
||||
clean[key] = fn(fields[key])
|
||||
sets.append(f"{key} = %s")
|
||||
params.append(fn(fields[key]))
|
||||
params.append(clean[key])
|
||||
if not sets:
|
||||
existing = self.get_project(project_id=project_id)
|
||||
if existing is None:
|
||||
raise KeyError(project_id)
|
||||
return existing
|
||||
if "start_date" in clean or "due_date" in clean:
|
||||
# 한쪽만 바꿔도 기존 값과 합친 최종 상태로 검사한다.
|
||||
existing = self.get_project(project_id=project_id)
|
||||
if existing is None:
|
||||
raise KeyError(project_id)
|
||||
store.validate_date_range(
|
||||
clean["start_date"] if "start_date" in clean else existing.get("start_date"),
|
||||
clean["due_date"] if "due_date" in clean else existing.get("due_date"),
|
||||
)
|
||||
params.append(project_id)
|
||||
with self._pool.connection() as conn:
|
||||
row = conn.execute(
|
||||
@@ -605,7 +617,9 @@ class ProjectStore:
|
||||
dd = store.validate_date(due_date)
|
||||
sti = store.validate_time(start_time)
|
||||
dti = store.validate_time(due_time)
|
||||
store.validate_date_range(sd, dd, sti, dti)
|
||||
assignee = store.norm_str(assignee_email, lower=True)
|
||||
done_at = None
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
if parent_task_id is not None:
|
||||
@@ -636,6 +650,13 @@ class ProjectStore:
|
||||
# 세션이 없어 해당 없음).
|
||||
if not assignee and stage_id is not None:
|
||||
assignee, assignee_name = self._stage_default_assignee(conn, stage_id, project_id)
|
||||
# 완료 섹션에 바로 만든 작업은 완료 섹션으로 옮긴 것과 같이 완료 처리(완료 시각·이력).
|
||||
if stage_id is not None:
|
||||
done_row = conn.execute(
|
||||
"SELECT is_done_stage FROM project_stages WHERE id = %s", (stage_id,)
|
||||
).fetchone()
|
||||
if done_row and done_row["is_done_stage"]:
|
||||
done_at = now_kst()
|
||||
nxt = conn.execute(
|
||||
"SELECT COALESCE(MAX(sort_order), -1) + 1 AS n FROM tasks "
|
||||
"WHERE project_id = %s",
|
||||
@@ -646,21 +667,26 @@ class ProjectStore:
|
||||
INSERT INTO tasks
|
||||
(project_id, stage_id, parent_task_id, title, description,
|
||||
assignee_email, assignee_name, priority, start_date, due_date,
|
||||
start_time, due_time, sort_order, created_by)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
start_time, due_time, sort_order, created_by, completed_at)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
RETURNING *
|
||||
""",
|
||||
(
|
||||
project_id, stage_id, parent_task_id, ttl, store.norm_str(description),
|
||||
assignee, store.norm_str(assignee_name), pr, sd, dd,
|
||||
sti, dti, int(nxt["n"]), store.norm_str(created_by, lower=True),
|
||||
sti, dti, int(nxt["n"]), store.norm_str(created_by, lower=True), done_at,
|
||||
),
|
||||
).fetchone()
|
||||
if assignee:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_ASSIGNED,
|
||||
detail=f"{ttl} → {assignee}")
|
||||
return self.get_task(task_id=row["id"])
|
||||
if done_at is not None:
|
||||
self._log(conn, project_id=project_id, task_id=row["id"],
|
||||
actor=created_by, action=store.ACTION_COMPLETED, detail=ttl)
|
||||
out = self.get_task(task_id=row["id"])
|
||||
out["_newly_completed"] = done_at is not None
|
||||
return out
|
||||
|
||||
def move_subtask(
|
||||
self, *, task_id: int, parent_task_id: int, actor: str = ""
|
||||
@@ -806,6 +832,15 @@ class ProjectStore:
|
||||
if not sets:
|
||||
return {**prev, "_newly_assigned": None, "_newly_completed": False}
|
||||
|
||||
# 날짜 범위 — 한쪽만 바꾸거나 지워도 기존 값과 합친 최종 상태로 검사.
|
||||
if any(k in fields for k in ("start_date", "due_date", "start_time", "due_time")):
|
||||
def final(key: str, fn: Any) -> Any:
|
||||
return fn(fields[key]) if key in fields else prev.get(key)
|
||||
store.validate_date_range(
|
||||
final("start_date", store.validate_date), final("due_date", store.validate_date),
|
||||
final("start_time", store.validate_time), final("due_time", store.validate_time),
|
||||
)
|
||||
|
||||
params.append(task_id)
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
@@ -1217,6 +1252,51 @@ class ProjectStore:
|
||||
).fetchone()
|
||||
return self._serialize(row)
|
||||
|
||||
def add_comment_with_attachments(
|
||||
self, *, task_id: int, author_email: str, author_name: str, body: str,
|
||||
files: list[dict[str, Any]], parent_id: int | None = None,
|
||||
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
"""댓글과 첨부를 한 트랜잭션에 — 둘 중 하나라도 실패하면 아무것도 남지 않는다
|
||||
(첨부 없이 빈 댓글만 남던 문제). files = [{filename, stored_name, content_type, size_bytes}].
|
||||
본문이 비어도 되지만 첨부가 한 개 이상 있어야 한다."""
|
||||
text = store.norm_str(body)
|
||||
if not files and not text:
|
||||
raise ValueError("댓글 내용이 비었습니다.")
|
||||
author = store.norm_str(author_email, lower=True)
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
root = None
|
||||
if parent_id:
|
||||
p = conn.execute(
|
||||
"SELECT id, task_id, parent_id FROM task_comments WHERE id = %s", (parent_id,)
|
||||
).fetchone()
|
||||
if not p or int(p["task_id"]) != int(task_id):
|
||||
raise ValueError("답글을 달 댓글을 찾을 수 없습니다.")
|
||||
root = int(p["parent_id"] or p["id"])
|
||||
if root is not None:
|
||||
row = conn.execute(
|
||||
"INSERT INTO task_comments (task_id, author_email, author_name, body, parent_id) "
|
||||
"VALUES (%s,%s,%s,%s,%s) RETURNING *",
|
||||
(task_id, author, store.norm_str(author_name), text, root),
|
||||
).fetchone()
|
||||
else:
|
||||
row = conn.execute(
|
||||
"INSERT INTO task_comments (task_id, author_email, author_name, body) "
|
||||
"VALUES (%s,%s,%s,%s) RETURNING *",
|
||||
(task_id, author, store.norm_str(author_name), text),
|
||||
).fetchone()
|
||||
atts = []
|
||||
for f in files:
|
||||
atts.append(conn.execute(
|
||||
"INSERT INTO task_attachments "
|
||||
"(task_id, filename, stored_name, content_type, size_bytes, uploaded_by, comment_id) "
|
||||
"VALUES (%s,%s,%s,%s,%s,%s,%s) RETURNING *",
|
||||
(task_id, store.norm_str(f["filename"]), f["stored_name"],
|
||||
store.norm_str(f.get("content_type") or "application/octet-stream"),
|
||||
int(f["size_bytes"]), author, row["id"]),
|
||||
).fetchone())
|
||||
return self._serialize(row), [self._serialize(a) for a in atts]
|
||||
|
||||
def update_comment(
|
||||
self, *, comment_id: int, requester: str, is_admin: bool, body: str
|
||||
) -> dict[str, Any]:
|
||||
@@ -1655,6 +1735,58 @@ class ProjectStore:
|
||||
).fetchall()
|
||||
return [self._serialize(r) for r in rows]
|
||||
|
||||
def add_reminder_notification(
|
||||
self, *, task_id: int, kind: str, due_date: str, recipient_email: str,
|
||||
project_id: int | None, title: str, body: str,
|
||||
) -> bool:
|
||||
"""마감 알림 발송 기록 + 수신함 알림을 한 트랜잭션에. 처음이면 둘 다 넣고 True,
|
||||
이미 보냈으면(UNIQUE) False. 알림 생성이 실패하면 발송 기록도 되돌려져 다음 실행에서
|
||||
다시 시도된다(예전엔 기록만 남아 영영 안 갔다). 동시에 두 번 돌아도 UNIQUE 로 한 번만."""
|
||||
rcpt = store.norm_str(recipient_email, lower=True)
|
||||
with self._pool.connection() as conn:
|
||||
with conn.transaction():
|
||||
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, rcpt),
|
||||
).fetchone()
|
||||
if row is None:
|
||||
return False
|
||||
conn.execute(
|
||||
"INSERT INTO project_notifications "
|
||||
"(recipient_email, actor_email, project_id, task_id, type, title, body) "
|
||||
"VALUES (%s,'',%s,%s,%s,%s,%s)",
|
||||
(rcpt, project_id, task_id, kind, store.norm_str(title), store.norm_str(body)),
|
||||
)
|
||||
return True
|
||||
|
||||
def task_link_scope(self, *, task_ids: list[int]) -> dict[int, set[int]]:
|
||||
"""작업 id → 이 작업 또는 그 상위 작업들이 연결(멀티호밍)된 프로젝트 id 집합.
|
||||
연결된 프로젝트 멤버가 그 작업(과 하위 작업)을 읽기 전용으로 볼 수 있는지 판단한다."""
|
||||
ids = sorted({int(i) for i in task_ids})
|
||||
if not ids:
|
||||
return {}
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
WITH RECURSIVE chain AS (
|
||||
SELECT id AS task_id, id AS anc_id, parent_task_id, 0 AS depth
|
||||
FROM tasks WHERE id = ANY(%s)
|
||||
UNION ALL
|
||||
SELECT c.task_id, t.id, t.parent_task_id, c.depth + 1
|
||||
FROM chain c JOIN tasks t ON t.id = c.parent_task_id
|
||||
WHERE c.depth < 20
|
||||
)
|
||||
SELECT c.task_id, l.project_id
|
||||
FROM chain c JOIN task_project_links l ON l.task_id = c.anc_id
|
||||
""",
|
||||
(ids,),
|
||||
).fetchall()
|
||||
out: dict[int, set[int]] = {}
|
||||
for r in rows:
|
||||
out.setdefault(int(r["task_id"]), set()).add(int(r["project_id"]))
|
||||
return out
|
||||
|
||||
def record_reminder(
|
||||
self, *, task_id: int, kind: str, due_date: str, recipient_email: str,
|
||||
) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user