81b1204693
권한(서버) - 공통 권한 모듈 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>
152 lines
6.1 KiB
Python
152 lines
6.1 KiB
Python
"""프로젝트 관리 — 현재 접근 권한의 공통 기준(서버).
|
|
|
|
라우터·마감 알림이 같은 규칙을 쓰도록 한 곳에 모은다. 모든 판단은 "지금" 기준이다 —
|
|
예전에 멤버였거나 담당자·멘션·협업자로 기록돼 있어도, 지금 권한이 없으면 보이지도
|
|
바꾸지도 알림을 받지도 않는다(기록 자체는 업무 이력으로 남긴다).
|
|
|
|
프로젝트
|
|
관리(=보기·작업 CRUD) : 관리자(is_admin) · 프로젝트 owner · 배정 멤버. 모두 `project` 모듈 권한이 있어야 한다.
|
|
|
|
작업
|
|
FULL : 원 소속 프로젝트를 관리할 수 있음 → 보기·수정·댓글·첨부·삭제(삭제는 추가로 생성자 규칙)
|
|
READ : 원 소속 권한은 없지만, 이 작업(또는 상위 작업)이 연결된(멀티호밍) 프로젝트를 관리할 수 있음
|
|
→ 그 작업의 상세·하위 작업 목록·댓글·첨부 보기만. 원 소속의 다른 작업·멤버는 보이지 않는다.
|
|
연결된 프로젝트 안에서의 섹션 이동(POST /links, 이미 연결된 경우)은 예전처럼 허용.
|
|
None : 권한 없음 → 403/목록에서 제외/알림·메일 대상 제외
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Callable, Iterable
|
|
|
|
from . import store
|
|
|
|
FULL = "full"
|
|
READ = "read"
|
|
|
|
UserLookup = Callable[[str], "dict[str, Any] | None"]
|
|
|
|
|
|
def default_user_lookup(email: str) -> dict[str, Any] | None:
|
|
"""등록 사용자 레코드(app.main.user_store). 지연 import — 테스트는 lookup 을 직접 넘긴다."""
|
|
from app.main import user_store # noqa: WPS433
|
|
|
|
return user_store.get(store.norm_str(email, lower=True))
|
|
|
|
|
|
def _is_admin(user: dict[str, Any] | None) -> bool:
|
|
from app.store import is_admin # noqa: WPS433
|
|
|
|
return is_admin(user)
|
|
|
|
|
|
def can_use_module(user: dict[str, Any] | None) -> bool:
|
|
from app.store import has_module # noqa: WPS433
|
|
|
|
return bool(user) and has_module(user, "project")
|
|
|
|
|
|
def email_of(user: dict[str, Any] | None) -> str:
|
|
return store.norm_str((user or {}).get("email", ""), lower=True)
|
|
|
|
|
|
def can_manage_project(st: Any, user: dict[str, Any] | None, project_id: Any) -> bool:
|
|
"""프로젝트 관리(=보기·작업 CRUD) — 관리자 또는 owner/멤버. 모듈 권한이 없으면 False."""
|
|
if not can_use_module(user):
|
|
return False
|
|
if _is_admin(user):
|
|
return True
|
|
try:
|
|
pid = int(project_id)
|
|
except (TypeError, ValueError):
|
|
return False
|
|
return bool(st.is_member(project_id=pid, user_email=email_of(user)))
|
|
|
|
|
|
def visible_project_ids(st: Any, user: dict[str, Any]) -> set[int] | None:
|
|
"""관리할 수 있는 프로젝트 id 집합. 관리자는 None(=전체)."""
|
|
if _is_admin(user):
|
|
return None
|
|
if not can_use_module(user):
|
|
return set()
|
|
return {
|
|
int(p["id"]) for p in st.list_projects(include_archived=True, member_email=email_of(user))
|
|
}
|
|
|
|
|
|
def task_access(st: Any, user: dict[str, Any] | None, task: dict[str, Any] | None) -> str | None:
|
|
"""작업 하나에 대한 지금 권한: FULL / READ / None."""
|
|
if not task or not can_use_module(user):
|
|
return None
|
|
if can_manage_project(st, user, task.get("project_id")):
|
|
return FULL
|
|
for pid in link_scope(st, [int(task["id"])]).get(int(task["id"]), set()):
|
|
if can_manage_project(st, user, pid):
|
|
return READ
|
|
return None
|
|
|
|
|
|
def link_scope(st: Any, task_ids: Iterable[int]) -> dict[int, set[int]]:
|
|
"""작업 id → 이 작업 또는 상위 작업이 연결된 프로젝트 id 들. 연결 표가 없으면 빈 값."""
|
|
ids = [int(i) for i in task_ids]
|
|
if not ids:
|
|
return {}
|
|
try:
|
|
return st.task_link_scope(task_ids=ids)
|
|
except Exception: # noqa: BLE001 - 003 미적용(연결 기능 없음) → 연결로 보이는 작업 없음
|
|
return {}
|
|
|
|
|
|
def filter_visible_tasks(st: Any, user: dict[str, Any], tasks: list[dict[str, Any]],
|
|
*, key: str = "id") -> list[dict[str, Any]]:
|
|
"""목록에서 지금 볼 수 있는(FULL 또는 READ) 작업만 남긴다 — 내 작업·수신함·알림 공용."""
|
|
allowed = visible_project_ids(st, user)
|
|
if allowed is None:
|
|
return list(tasks)
|
|
ids = [int(t[key]) for t in tasks if t.get(key) is not None]
|
|
scope = link_scope(st, ids)
|
|
out = []
|
|
for t in tasks:
|
|
tid = t.get(key)
|
|
pid = t.get("project_id")
|
|
if pid is not None and int(pid) in allowed:
|
|
out.append(t)
|
|
elif tid is not None and scope.get(int(tid), set()) & allowed:
|
|
out.append(t)
|
|
return out
|
|
|
|
|
|
def email_task_access(st: Any, email: str, task: dict[str, Any],
|
|
lookup: UserLookup | None = None) -> str | None:
|
|
"""이메일(알림·멘션 대상)이 지금 이 작업을 볼 수 있는지. 등록 안 된 사람·모듈 권한 없는 사람은 None."""
|
|
rec = (lookup or default_user_lookup)(email)
|
|
if not rec:
|
|
return None
|
|
rec = {**rec, "email": rec.get("email") or email}
|
|
return task_access(st, rec, task)
|
|
|
|
|
|
def filter_recipients(st: Any, task: dict[str, Any], emails: Iterable[str],
|
|
lookup: UserLookup | None = None) -> list[str]:
|
|
"""알림·메일·멘션 대상 중 지금 이 작업을 볼 수 있는 사람만(순서 유지, 중복 제거)."""
|
|
out: list[str] = []
|
|
seen: set[str] = set()
|
|
for e in emails:
|
|
em = store.norm_str(e, lower=True)
|
|
if not em or em in seen:
|
|
continue
|
|
seen.add(em)
|
|
if email_task_access(st, em, task, lookup) is not None:
|
|
out.append(em)
|
|
return out
|
|
|
|
|
|
def can_assign(st: Any, email: str, project_id: Any, lookup: UserLookup | None = None) -> bool:
|
|
"""담당자·소유자 후보 — 등록된 사용자이고 project 모듈 권한이 있으며, 그 프로젝트를
|
|
관리할 수 있어야 한다(관리자 포함). 권한 없는 사람에게 작업 정보가 담긴 알림이 가지 않게."""
|
|
rec = (lookup or default_user_lookup)(email)
|
|
if not rec:
|
|
return False
|
|
rec = {**rec, "email": rec.get("email") or email}
|
|
return can_manage_project(st, rec, project_id)
|