Files
dbx-main/tests/js/render_project.py
T
king 89ad338024 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>
2026-10-12 11:08:56 +09:00

102 lines
5.4 KiB
Python

"""project/project.html 을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
python tests/js/render_project.py # → tests/js/.out/project_render.html
"""
from __future__ import annotations
import io
import os
import jinja2
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
BASE_STUB = ("{% block head_extra %}{% endblock %}<body>{% block topbar_after_logout %}{% endblock %}{% block topbar_actions %}{% endblock %}"
"<main class='erp-page'>{% block content %}{% endblock %}</main></body>")
ME = "me@test.local"
STAGES = {
1: [{"id": 11, "project_id": 1, "name": "할 일", "is_done_stage": False, "sort_order": 0, "color": None,
"created_by": ME, "default_assignee_email": ""},
{"id": 12, "project_id": 1, "name": "완료", "is_done_stage": True, "sort_order": 1, "color": None,
"created_by": ME, "default_assignee_email": ""}],
2: [{"id": 21, "project_id": 2, "name": "할 일", "is_done_stage": False, "sort_order": 0, "color": None,
"created_by": ME, "default_assignee_email": ""}],
}
def task(tid: int, title: str, pid: int, stage: int, *, ctx: int | None = None, linked: bool = False) -> dict:
return {"id": tid, "title": title, "project_id": pid, "context_project_id": ctx or pid, "is_linked": linked,
"stage_id": stage, "home_stage_id": stage, "stage_name": "할 일", "is_done_stage": False,
"description": "", "assignee_email": "", "assignee_name": "", "priority": "normal",
"start_date": None, "due_date": None, "completed_at": None, "created_by": ME,
"parent_task_id": None, "comment_count": 0, "subtask_count": 0, "subtask_done": 0,
"project_name": {1: "P1", 2: "P2", 3: "비밀"}[pid], "project_color": "#4573d2", "sort_order": tid}
TASKS = [task(101, "작업 A", 1, 11), task(102, "작업 B", 1, 11), task(103, "작업 C", 2, 21),
task(301, "연결된 작업", 3, 99, ctx=1, linked=True)]
PROJECTS = [{"id": 1, "name": "P1", "color": "#4573d2", "icon": "", "start_date": None, "due_date": None,
"created_by": ME, "description": "", "status": "active"},
{"id": 2, "name": "P2", "color": "#f06a6a", "icon": "", "start_date": None, "due_date": None,
"created_by": ME, "description": "", "status": "active"}]
def main() -> None:
env = jinja2.Environment(loader=jinja2.ChoiceLoader([
jinja2.DictLoader({"erp_base.html": BASE_STUB}),
jinja2.FileSystemLoader(os.path.join(ROOT, "app", "modules", "project", "templates")),
]))
env.globals["pj_kr_holidays"] = {}
for name, admin in (("project_render.html", False), ("project_admin_render.html", True)):
render_one(env, name, admin)
render_inbox(env)
def render_inbox(env) -> None:
"""수신함(project/inbox.html) — 태그한 작업 101·102, 알림(작업 101·102·프로젝트만)."""
def mt(tid: int, title: str) -> dict:
return {"id": tid, "title": title, "project_id": 1, "project_name": "P1", "project_color": "#4573d2",
"unread_mentions": 1, "stage_name": "할 일", "due_label": "", "mention_actor": "bob@test.local",
"completed_at": None}
def nt(nid: int, ntype: str, title: str, task_id: int | None) -> dict:
return {"id": nid, "type": ntype, "title": title, "body": "P1", "task_id": task_id, "project_id": 1,
"is_read": False, "actor_email": "bob@test.local", "created_at": "2026-10-12T09:00:00+09:00"}
html = env.get_template("project/inbox.html").render(
user={"email": ME, "is_super_admin": False}, is_admin=False, pj_pro=False, pj_admin=False,
nav_projects=PROJECTS, goal_years=[2026], my_open_total=0, mention_unread=2,
color_palette=["#4573d2"], project_icons=["folder"], project_asana_icons=[],
mentioned_tasks=[mt(101, "작업 A"), mt(102, "작업 B")],
notifications=[nt(901, "assigned", "작업 배정: 작업 A", 101), nt(902, "comment", "새 댓글: 작업 B", 102),
nt(903, "completed", "프로젝트 알림", None)],
)
path = os.path.join(OUT_DIR, "inbox_render.html")
io.open(path, "w", encoding="utf-8", newline="\n").write(html)
print("rendered:", path)
def render_one(env, name: str, admin: bool) -> None:
html = env.get_template("project/project.html").render(
user={"email": ME, "is_super_admin": False}, is_admin=admin, pj_pro=admin, pj_admin=admin, can_manage=True,
project=PROJECTS[0], current_project_id=1, stages=STAGES[1], tasks=TASKS,
members=[{"user_email": ME, "role": "member"}, {"user_email": "bob@test.local", "role": "member"}],
projects_meta=PROJECTS, nav_projects=PROJECTS, stages_by_project=STAGES, board_stage_names=["할 일", "완료"],
avatars={}, priority_labels={"low": "낮음", "normal": "보통", "high": "높음"},
color_palette=["#4573d2"], project_icons=["folder"], stage_color_palette=["#c7c4c4"],
today="2026-09-30", holidays={}, year=2026, month=9, prev_y=2026, prev_m=8, next_y=2026, next_m=10,
weekdays=["일", "월", "화", "수", "목", "금", "토"], weeks=[], goal_years=[2026],
my_open_total=0, mention_unread=0,
)
os.makedirs(OUT_DIR, exist_ok=True)
path = os.path.join(OUT_DIR, name)
io.open(path, "w", encoding="utf-8", newline="\n").write(html)
print("rendered:", path)
if __name__ == "__main__":
main()