feat(b08): 라이브러리 관리자 발행 — 프로그램 기본도 storage 작업본(git resources 는 씨앗 · 없는 코드만 · 덮어쓰기 금지) · [회사 라이브러리에 발행](마스터·시스템 관리자) · [프로그램 기본으로 발행](시스템 관리자) — [내 라이브러리에 저장]과 같은 모양 · 권한은 서버가 can_publish 로 내리고 화면은 그대로만 보임
화면(시스템 관리자 계정): 두 단추 보임 · 확인창 「모든 회사가 쓰는 프로그램 기본에 발행 — 같은 종류가 있으면 덮어씀」 · 공용 storage 라 취소로 멈춤(쓰기 없음 확인) · 쓰기는 시험(임시 storage)으로 잼 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016VBGFXB9AbJBwXP19z75Qq
This commit is contained in:
@@ -26,6 +26,25 @@ CODE_PATTERN = re.compile(r"^AX-ST-[0-9a-f]{8}$")
|
||||
LIBRARY_SUBDIR = "library"
|
||||
|
||||
|
||||
#: 프로그램 기본 작업본 자리 — 회사 번호 폴더와 안 겹치게 밑줄 이름.
|
||||
PROGRAM_SUBDIR = "_program"
|
||||
|
||||
|
||||
def program_library_dir() -> Path:
|
||||
"""프로그램 기본 **작업본**(시스템 관리자가 화면에서 고친 것) — storage(회사·개인 단과 같은 결).
|
||||
|
||||
git `resources/library_structure`(`TEMPLATE_DIR`)는 **씨앗** — 쓰기 금지(데이터 3층의 초기값 자리).
|
||||
"""
|
||||
return Path(STORAGE_BASE_DIR).resolve() / PROGRAM_SUBDIR / LIBRARY_SUBDIR
|
||||
|
||||
|
||||
def program_items() -> list[dict[str, Any]]:
|
||||
"""프로그램 기본 = 작업본 + 씨앗 중 **작업본에 없는 코드만**(관리자가 고친 것이 배포에 안 덮임)."""
|
||||
stored = _items(program_library_dir())
|
||||
codes = {item.get("code") for item in stored}
|
||||
return [*stored, *(item for item in _items(TEMPLATE_DIR) if item.get("code") not in codes)]
|
||||
|
||||
|
||||
def tier_dirs(company_id: Any, user_id: Any) -> dict[str, Path]:
|
||||
"""로그인한 사람의 3단 폴더. 회사가 없으면(시스템 관리자) 개인·회사 단은 없음."""
|
||||
dirs: dict[str, Path] = {}
|
||||
@@ -34,7 +53,7 @@ def tier_dirs(company_id: Any, user_id: Any) -> dict[str, Path]:
|
||||
if user_id is not None:
|
||||
dirs["personal"] = company / str(user_id) / LIBRARY_SUBDIR
|
||||
dirs["company"] = company / LIBRARY_SUBDIR
|
||||
dirs["program"] = TEMPLATE_DIR
|
||||
dirs["program"] = program_library_dir()
|
||||
return dirs
|
||||
|
||||
|
||||
@@ -44,6 +63,13 @@ def _items(folder: Path) -> list[dict[str, Any]]:
|
||||
return [json.loads(p.read_text(encoding="utf-8")) for p in sorted(folder.glob("*.json"))]
|
||||
|
||||
|
||||
def _tier_items(dirs: dict[str, Path], tier: str) -> list[dict[str, Any]]:
|
||||
"""단의 항목 — 프로그램 기본은 작업본 + 씨앗, 나머지는 그 폴더."""
|
||||
if tier == "program":
|
||||
return program_items()
|
||||
return _items(dirs[tier]) if tier in dirs else []
|
||||
|
||||
|
||||
def item_kind(item: dict[str, Any]) -> str:
|
||||
"""양식형(`form`) · 고정형(`fixed`) — 명세 13장: 칸은 같고 **식이 한 줄이라도 있나**로만 가름.
|
||||
저장된 `item_kind` 표시는 안 믿음 — 줄과 어긋나면 배지가 거짓이 됨."""
|
||||
@@ -66,16 +92,15 @@ def list_items(dirs: dict[str, Path], type_id: str) -> list[dict[str, Any]]:
|
||||
}
|
||||
for tier in TIERS
|
||||
if tier in dirs
|
||||
for item in _items(dirs[tier])
|
||||
for item in _tier_items(dirs, tier)
|
||||
if item.get("type_id") == type_id and item.get("code")
|
||||
]
|
||||
|
||||
|
||||
def find_item(dirs: dict[str, Path], tier: str, code: str) -> dict[str, Any] | None:
|
||||
folder = dirs.get(tier)
|
||||
if folder is None:
|
||||
if tier not in dirs:
|
||||
return None
|
||||
return next((item for item in _items(folder) if item.get("code") == code), None)
|
||||
return next((item for item in _tier_items(dirs, tier) if item.get("code") == code), None)
|
||||
|
||||
|
||||
def project_library_dir(project_root: str | Path) -> Path:
|
||||
@@ -98,7 +123,7 @@ def available_templates(project_root: str | Path | None) -> list[dict[str, Any]]
|
||||
|
||||
⛔ 개인·회사 단은 안 넣음 — 표를 그릴 때 라이브러리를 매번 읽지 않음(판정 Ⓑ).
|
||||
"""
|
||||
return [*_items(TEMPLATE_DIR), *project_templates(project_root).values()]
|
||||
return [*program_items(), *project_templates(project_root).values()]
|
||||
|
||||
|
||||
def import_item(project_root: str | Path, item: dict[str, Any], tier: str) -> None:
|
||||
@@ -127,9 +152,13 @@ def _write(folder: Path, item: dict[str, Any]) -> None:
|
||||
(folder / f"{item['code']}.json").write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def _personal_code(folder: Path, type_id: Any) -> str:
|
||||
"""개인 단 코드 — 같은 종류가 있으면 그 코드(덮어씀 · 판정 Ⓐ 종류당 하나), 없으면 새로."""
|
||||
same = [item for item in _items(folder) if item.get("type_id") == type_id]
|
||||
def _personal_code(folder: Path, type_id: Any, existing: list[dict[str, Any]] | None = None) -> str:
|
||||
"""그 단 코드 — 같은 종류가 있으면 그 코드(덮어씀 · 판정 Ⓐ 종류당 하나), 없으면 새로.
|
||||
|
||||
프로그램 기본은 씨앗까지 봄(`existing`) — 씨앗 코드로 덮어써야 작업본이 씨앗을 이김.
|
||||
"""
|
||||
items = _items(folder) if existing is None else existing
|
||||
same = [item for item in items if item.get("type_id") == type_id]
|
||||
return str(same[0]["code"]) if same else f"AX-ST-{secrets.token_hex(4)}"
|
||||
|
||||
|
||||
@@ -145,16 +174,19 @@ def save_personal(
|
||||
template: dict[str, Any],
|
||||
overrides: dict[str, Any] | None,
|
||||
unit_price_rows: list[dict[str, Any]] | None = None,
|
||||
tier: str = "personal",
|
||||
) -> str:
|
||||
"""[내 라이브러리에 저장] — 양식 + 고친 식·줄 조합을 **개인 단에 한 벌**로 씀. 코드.
|
||||
"""[내 라이브러리에 저장]·발행 — 양식 + 고친 식·줄 조합을 **그 단에 한 벌**로 씀. 코드.
|
||||
|
||||
⚠ 반대 방향(작업본 → 개인 단)이라 프로젝트는 안 바꿈(브레인 판정 Ⓑ).
|
||||
⚠ 개인 단에 같은 종류가 있으면 **그 코드로 덮어씀** — 지금은 종류당 하나(판정 Ⓐ).
|
||||
⚠ 반대 방향(작업본 → 라이브러리)이라 프로젝트는 안 바꿈(브레인 판정 Ⓑ).
|
||||
⚠ 같은 종류가 있으면 **그 코드로 덮어씀** — 지금은 종류당 하나(판정 Ⓐ).
|
||||
⚠ `tier` — 회사(MASTER)·프로그램 기본(SYSTEM_ADMIN) 발행도 같은 모양(2026-09-14 브레인 승인).
|
||||
⛔ 수동 단가는 안 실음 — 프로젝트의 값이라 양식에 실으면 남의 프로젝트로 감(브레인 판정).
|
||||
"""
|
||||
from B08_Quantity.B08_Quantity_Engine_StructureTemplate import overridden_rows
|
||||
|
||||
code = _personal_code(folder, template.get("type_id"))
|
||||
existing = program_items() if tier == "program" else None
|
||||
code = _personal_code(folder, template.get("type_id"), existing)
|
||||
# 고친 식·반올림이 곧 이 항목의 값 — 「사용자」 표시와 되돌릴 자리는 떼어 냄.
|
||||
dropped = {"default_formula", "default_rounding"}
|
||||
rows = [
|
||||
@@ -164,7 +196,7 @@ def save_personal(
|
||||
item = {k: v for k, v in template.items() if k != "imported_from"}
|
||||
if unit_price_rows is not None:
|
||||
item["unit_price"] = {**(item.get("unit_price") or {}), "rows": unit_price_rows}
|
||||
_write(folder, {**item, "code": code, "library_tier": "personal", "rows": rows})
|
||||
_write(folder, {**item, "code": code, "library_tier": tier, "rows": rows})
|
||||
return code
|
||||
|
||||
|
||||
@@ -186,7 +218,7 @@ def pin_program_templates(project_root: str | Path) -> int:
|
||||
"""
|
||||
pinned = project_templates(project_root)
|
||||
count = 0
|
||||
for item in _items(TEMPLATE_DIR):
|
||||
for item in program_items():
|
||||
if item.get("type_id") and item.get("code") and item["type_id"] not in pinned:
|
||||
import_item(project_root, item, "program")
|
||||
count += 1
|
||||
|
||||
Reference in New Issue
Block a user