From 49b3b6a0dcba41d0e95c9417b2fa479076c84932 Mon Sep 17 00:00:00 2001 From: king Date: Thu, 5 Nov 2026 13:02:52 +0900 Subject: [PATCH] =?UTF-8?q?feat(=EB=9D=BC=EC=9D=B4=EB=B8=8C):=20=ED=98=B8?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=93=B1=EB=A1=9D=20=EC=A0=84=EC=9A=A9=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=20=EC=B9=A9=20live=5Fhost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit live + live_host 칩이 있으면 새 호스트 등록만 가능. 계좌 등 개인정보 보기, 고치기, 지우기, 사용 여부 변경은 ERP 관리자만. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- app/main.py | 1 + app/modules/live/CLAUDE.md | 1 + app/modules/live/router.py | 30 +++++++--- app/modules/live/templates/live/_bar.html | 4 +- app/modules/live/templates/live/settings.html | 12 ++-- app/store.py | 1 + tests/test_live.py | 57 +++++++++++++++++++ 8 files changed, 93 insertions(+), 15 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 238d8c1..e1eda17 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -47,7 +47,7 @@ | `[공지]` `[긴급공지]` | `notice/` | `project_db`(024) | 수퍼관리자 | `docs/NOTICE_MODULE.md` | `erp-notice*` | | `[자산]` | `asset/` | `asset_db` | `asset` | `docs/ASSET_MODULE.md` | `asset.*` | | `[안내문 발송]` | `outreach/` | `outreach_db` | `outreach` | (모듈 CLAUDE.md) | `outreach.*` | -| `[라이브커머스]` `[라이브]` | `live/` | `live_db` | `live` | (모듈 CLAUDE.md) | `live.*` | +| `[라이브커머스]` `[라이브]` | `live/` | `live_db` | `live`, `live_host` | (모듈 CLAUDE.md) | `live.*` | | `[공통]` `[ERP]` | `app/main.py`, `app/templates/`(셸·로그인·관리자), 인증·권한 | — | — | `docs/PROJECT_OVERVIEW.md`, `docs/DESIGN.md` | `erp*.js/css`, `styles.css` | | `[배포]` `[서버]` | `docker-compose*.yml`, `Dockerfile`, `scripts/` | — | — | `docs/DEPLOYMENT.md` | — | | `[DB]` | `scripts/sql/` | — | — | `docs/DATABASES.md` | — | diff --git a/app/main.py b/app/main.py index 342f495..9c430c4 100644 --- a/app/main.py +++ b/app/main.py @@ -68,6 +68,7 @@ MODULE_LABELS: dict[str, str] = { "inout": "입출고 관리", "outreach": "안내문 발송", "live": "라이브 커머스", + "live_host": "라이브 호스트 등록", "expense_approver": "개인경비", "vacation_approver": "휴가", } diff --git a/app/modules/live/CLAUDE.md b/app/modules/live/CLAUDE.md index 755a5cd..fc57f3f 100644 --- a/app/modules/live/CLAUDE.md +++ b/app/modules/live/CLAUDE.md @@ -7,6 +7,7 @@ - 말레이시아 라이브 커머스 방송의 호스트 정보·방송 스케줄. 권한키 `live`, DB `LIVE_DB_URL`(없으면 "설정 필요" 안내). - **호스트 설정** `/live/settings` — Full Name (as per IC)(필수)·Phone Number·Email·Address·Bank Name·Bank Account Number·Tiktok Handle(`@`·주소를 붙여 넣어도 계정명만 저장). **계좌 등 개인정보라 ERP 관리자만**(`is_admin`) — 화면·저장·지우기 모두. 스케줄 화면에는 `db.host_choices`(이름·틱톡·사용 여부)만 넘긴다. + **`live_host` 칩**(+ `live` 칩 필요) = 새 호스트 **등록만**: 설정 화면에 이름·틱톡·상태만 보이고, 입력한 계좌 등은 저장 후 못 봄. 고치기·지우기 불가, 사용 여부 못 고름(항상 사용). 사용 안 함 = 새 방송에서 못 고름(그 호스트로 이미 등록된 방송을 고칠 때만 보임). 방송 기록이 있는 호스트는 못 지움(FK RESTRICT). - **스케줄표** `/live/?month=YYYY-MM`(`live` 권한자 모두) — 호스트·날짜·시작/끝 시간·방송 장소·판매금액·커미션·호스트 비용·결과 이미지. 호스트·날짜·시작·끝 시간 필수(판매금액은 방송 후 입력). 시간은 입력한 말레이시아 시간 그대로(시간대 변환 없음, DATE·TIME). 판매금액 단위 RM(`NUMERIC(14,2)`, `store.parse_money`). 끝 시간이 시작보다 이르면 자정을 넘긴 방송. diff --git a/app/modules/live/router.py b/app/modules/live/router.py index fa4fe66..35cd035 100644 --- a/app/modules/live/router.py +++ b/app/modules/live/router.py @@ -6,9 +6,10 @@ POST /live/broadcasts/{id}/move 달력에서 끌어 옮기기(broadcast_date·start_time) 또는 맞바꾸기(swap_with) POST /live/ad-spend 날짜별 광고비(빈칸 = 지우기) GET /live/images/{id} 결과 이미지(?thumb=1 = 작은 그림) · POST /live/images/{id}/delete - GET /live/settings 설정 — 호스트 정보(ERP 관리자만, 계좌 등 개인정보) + GET /live/settings 설정 — 호스트 정보(ERP 관리자만, 계좌 등 개인정보. `live_host` 칩은 이름·틱톡·상태만) POST /live/settings/hosts 호스트 추가·고치기 · POST /live/settings/hosts/{id}/delete -권한: 모듈 권한키 `live`(스케줄), 설정은 ERP 관리자. DB: LIVE_DB_URL(live_db) — 없으면 "설정 필요" 안내. +권한: 모듈 권한키 `live`(스케줄), 설정은 ERP 관리자, `live` + `live_host` 칩 = 새 호스트 등록만. +DB: LIVE_DB_URL(live_db) — 없으면 "설정 필요" 안내. 저장 요청은 live.js 가 fetch 로 보내고 JSON {ok, message} 를 받는다(틀려도 입력한 값이 창에 남게). """ @@ -61,6 +62,12 @@ def _admin(request: Request) -> dict[str, Any]: return user +def _can_add_host(user: dict[str, Any]) -> bool: + from app.store import has_module, is_admin # noqa: WPS433 + + return is_admin(user) or has_module(user, "live_host") + + def _db(request: Request) -> Any: st = _store(request) if st is None: @@ -93,7 +100,7 @@ def _render(request: Request, name: str, user: dict[str, Any], ctx: dict[str, An from app.store import is_admin # noqa: WPS433 lang = _lang(request) - return render_template(request, name, {"user": user, "is_admin": is_admin(user), "lang": lang, + return render_template(request, name, {"user": user, "is_admin": is_admin(user), "can_add_host": _can_add_host(user), "lang": lang, "t": lambda text: i18n.t(text, lang), "js_text": i18n.js_text(lang), "nav_items": build_erp_nav(user, active="live"), **ctx}) @@ -242,7 +249,7 @@ def image_delete(request: Request, image_id: int) -> JSONResponse: # ──────────────────────────────────────────────────────────── -# 설정 — 호스트 정보(ERP 관리자만: 계좌 등 개인정보) +# 설정 — 호스트 정보(ERP 관리자만: 계좌 등 개인정보). `live_host` 칩 = 새 호스트 등록만. # ──────────────────────────────────────────────────────────── @router.get("/settings", response_class=HTMLResponse) def settings(request: Request) -> Any: @@ -253,22 +260,29 @@ def settings(request: Request) -> Any: if not isinstance(got, tuple): return got st, user = got - if not is_admin(user): + if not _can_add_host(user): return render_template(request, "denied.html", {"reason": _t(request, "호스트 정보는 ERP 관리자만 볼 수 있습니다."), "is_admin": False}, status_code=403) - return _render(request, "live/settings.html", user, {"hosts": st.list_hosts()}) + # host_choices = 이름·틱톡·상태뿐 — 계좌 등 개인정보는 관리자에게만 + return _render(request, "live/settings.html", user, {"hosts": st.list_hosts() if is_admin(user) else st.host_choices()}) @router.post("/settings/hosts") def host_save(request: Request, id: str = Form(""), full_name: str = Form(""), phone: str = Form(""), email: str = Form(""), address: str = Form(""), bank_name: str = Form(""), bank_account: str = Form(""), tiktok_handle: str = Form(""), is_active: str = Form("")) -> JSONResponse: - user = _admin(request) + from app.store import is_admin # noqa: WPS433 + + # `live_host` 칩은 새 등록만 — id 가 있으면 고치기라 관리자 검사로 + user = _user(request) + if id.strip() or not _can_add_host(user): + _admin(request) st = _db(request) try: values = store.clean_host({"full_name": full_name, "phone": phone, "email": email, "address": address, "bank_name": bank_name, "bank_account": bank_account, "tiktok_handle": tiktok_handle}) - st.save_host(_opt_id(id), values, is_active=bool(is_active), by=user.get("email", "")) + # 칩 권한자 화면엔 사용 여부 칸이 없다 — 항상 사용(사용 안 함으로 만들면 본인이 되돌릴 수 없음) + st.save_host(_opt_id(id), values, is_active=bool(is_active) or not is_admin(user), by=user.get("email", "")) except ValueError as exc: return _fail(request, exc) return _ok(request, "호스트를 저장했습니다.") diff --git a/app/modules/live/templates/live/_bar.html b/app/modules/live/templates/live/_bar.html index 390fcd4..a2fb003 100644 --- a/app/modules/live/templates/live/_bar.html +++ b/app/modules/live/templates/live/_bar.html @@ -11,9 +11,9 @@ {% include "live/_lang.html" %} - {% if is_admin %}{{ t('호스트 설정') }}{% endif %} + {% if can_add_host %}{{ t('호스트 설정') }}{% endif %} {% if not can_add %} -

{{ t('방송을 추가하려면 먼저 호스트를 등록해야 합니다.') }} {% if is_admin %}{{ t('호스트 설정') }}{% else %}{{ t('ERP 관리자에게 등록을 요청하세요.') }}{% endif %}

+

{{ t('방송을 추가하려면 먼저 호스트를 등록해야 합니다.') }} {% if can_add_host %}{{ t('호스트 설정') }}{% else %}{{ t('ERP 관리자에게 등록을 요청하세요.') }}{% endif %}

{% endif %} diff --git a/app/modules/live/templates/live/settings.html b/app/modules/live/templates/live/settings.html index 9c30b3c..35e0c0f 100644 --- a/app/modules/live/templates/live/settings.html +++ b/app/modules/live/templates/live/settings.html @@ -1,5 +1,5 @@ {% extends "erp_base.html" %} -{#- 라이브 커머스 설정(2026-11-04) — 호스트 정보. 계좌 등 개인정보라 ERP 관리자만(router.settings). 추가·고치기는 같은 창(live.js). 문구 = t()(i18n.py). -#} +{#- 라이브 커머스 설정(2026-11-04) — 호스트 정보. 계좌 등 개인정보·고치기·지우기는 ERP 관리자만(router.settings), `live_host` 칩은 이름·틱톡·상태 + 새 등록만. 추가·고치기는 같은 창(live.js). 문구 = t()(i18n.py). -#} {% block head_extra %}{% endblock %} {% block content %} @@ -15,25 +15,29 @@
- + {% if is_admin %}{% endif %}{% if is_admin %}{% endif %} {% for h in hosts %} + {% if is_admin %} + {% endif %} + {% if is_admin %} + {% endif %} {% else %} - + {% endfor %}
{{ t('이름 (IC 기준)') }}{{ t('전화번호') }}{{ t('이메일') }}{{ t('주소') }}{{ t('은행명') }}{{ t('계좌번호') }}{{ t('틱톡 핸들') }}{{ t('상태') }}
{{ t('이름 (IC 기준)') }}{{ t('전화번호') }}{{ t('이메일') }}{{ t('주소') }}{{ t('은행명') }}{{ t('계좌번호') }}{{ t('틱톡 핸들') }}{{ t('상태') }}
{{ h.full_name }}{{ h.phone }} {{ h.email }} {{ h.address }} {{ h.bank_name }} {{ h.bank_account }}{% if h.tiktok_handle %}@{{ h.tiktok_handle }}{% endif %} {{ t('사용') if h.is_active else t('사용 안 함') }}
{{ t('등록한 호스트가 없습니다.') }}
{{ t('등록한 호스트가 없습니다.') }}
@@ -54,7 +58,7 @@
- + {% if is_admin %}{% endif %}
diff --git a/app/store.py b/app/store.py index fa383b3..bd93eda 100644 --- a/app/store.py +++ b/app/store.py @@ -40,6 +40,7 @@ MODULE_KEYS: tuple[str, ...] = ( "inout", "outreach", "live", + "live_host", "expense_approver", "vacation_approver", ) diff --git a/tests/test_live.py b/tests/test_live.py index eff0fb7..567c5d1 100644 --- a/tests/test_live.py +++ b/tests/test_live.py @@ -213,6 +213,63 @@ def body(c): assert nav and nav[0]["label"] == "라이브 커머스" # 사이드바는 짧게 print("OK") run(body) +''') + self.assertEqual(res.returncode, 0, res.stdout + res.stderr) + self.assertIn("OK", res.stdout) + + def test_live_host_chip_adds_only(self): + """`live_host` 칩 = 새 호스트 등록만 — 계좌 안 보임, 고치기·지우기·사용 안 함 불가. DB 없이 가짜 저장소로.""" + res = _run(''' +from app.store import MODULE_KEYS +assert "live_host" in MODULE_KEYS and "live_host" in main.MODULE_LABELS + +class Fake: + saved = [] + def host_choices(self): + return [{"id": 1, "full_name": "Siti", "tiktok_handle": "siti", "is_active": True}] + def list_hosts(self): + return [{"id": 1, "full_name": "Siti", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank", + "bank_account": "998877", "tiktok_handle": "siti", "is_active": True}] + def list_broadcasts(self, start, end): + return [] + def save_host(self, host_id, values, *, is_active, by): + self.saved.append((host_id, values["full_name"], is_active, by)) + return 2 + def delete_host(self, host_id): + self.saved.append(("deleted", host_id)) + +fake = main.app.state.live_store = Fake() +adder = U("adder@t.local"); adder["modules"]["live_host"] = True +chip_only = U("chip@t.local", live=False); chip_only["modules"]["live_host"] = True +new = {"full_name": "New Host", "bank_account": "111"} + +def body(c): + who["u"] = adder + assert 'href="/live/settings"' in c.get("/live/").text + page = c.get("/live/settings") + assert page.status_code == 200 and "Siti" in page.text and 'name="full_name"' in page.text + for hidden in ("998877", "Maybank", "s@e.my", "data-edit='", "/delete", 'name="is_active"'): + assert hidden not in page.text, hidden + assert c.post("/live/settings/hosts", data=new).json()["ok"] + assert fake.saved == [(None, "New Host", True, "adder@t.local")], fake.saved + assert c.post("/live/settings/hosts", data={**new, "id": "1"}).status_code == 403 + assert c.post("/live/settings/hosts/1/delete").status_code == 403 + assert len(fake.saved) == 1, fake.saved + + for no_add in (U("staff@t.local"), chip_only): + who["u"] = no_add + assert c.get("/live/settings").status_code == 403 + assert c.post("/live/settings/hosts", data=new).status_code == 403 + assert len(fake.saved) == 1, fake.saved + + # 관리자는 그대로 — 계좌 보임, 고치기, 사용 안 함 + who["u"] = U("a@t.local", role="admin") + page = c.get("/live/settings").text + assert "998877" in page and "data-edit='" in page and 'name="is_active"' in page + assert c.post("/live/settings/hosts", data={**new, "id": "1"}).json()["ok"] + assert fake.saved[-1] == (1, "New Host", False, "a@t.local"), fake.saved + print("OK") +run(body) ''') self.assertEqual(res.returncode, 0, res.stdout + res.stderr) self.assertIn("OK", res.stdout)