feat(라이브): 호스트 등록 전용 권한 칩 live_host

live + live_host 칩이 있으면 새 호스트 등록만 가능. 계좌 등 개인정보 보기,
고치기, 지우기, 사용 여부 변경은 ERP 관리자만.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 13:02:52 +09:00
parent 4477a68819
commit 49b3b6a0dc
8 changed files with 93 additions and 15 deletions
+1 -1
View File
@@ -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` | — |
+1
View File
@@ -68,6 +68,7 @@ MODULE_LABELS: dict[str, str] = {
"inout": "입출고 관리",
"outreach": "안내문 발송",
"live": "라이브 커머스",
"live_host": "라이브 호스트 등록",
"expense_approver": "개인경비",
"vacation_approver": "휴가",
}
+1
View File
@@ -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`). 끝 시간이 시작보다 이르면 자정을 넘긴 방송.
+22 -8
View File
@@ -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, "호스트를 저장했습니다.")
+2 -2
View File
@@ -11,9 +11,9 @@
</nav>
<span class="lv-gap"></span>
{% include "live/_lang.html" %}
{% if is_admin %}<a class="erp-btn erp-btn-outline" href="/live/settings">{{ t('호스트 설정') }}</a>{% endif %}
{% if can_add_host %}<a class="erp-btn erp-btn-outline" href="/live/settings">{{ t('호스트 설정') }}</a>{% endif %}
<button type="button" class="erp-btn erp-btn-primary" id="lv-add"{% if not can_add %} disabled{% endif %}>{{ t('+ 방송 추가') }}</button>
</div>
{% if not can_add %}
<p class="lv-note">{{ t('방송을 추가하려면 먼저 호스트를 등록해야 합니다.') }} {% if is_admin %}<a href="/live/settings">{{ t('호스트 설정') }}</a>{% else %}{{ t('ERP 관리자에게 등록을 요청하세요.') }}{% endif %}</p>
<p class="lv-note">{{ t('방송을 추가하려면 먼저 호스트를 등록해야 합니다.') }} {% if can_add_host %}<a href="/live/settings">{{ t('호스트 설정') }}</a>{% else %}{{ t('ERP 관리자에게 등록을 요청하세요.') }}{% endif %}</p>
{% endif %}
@@ -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 %}<link rel="stylesheet" href="/static/live.css?v=20261104c" />{% endblock %}
{% block content %}
@@ -15,25 +15,29 @@
<div class="erp-card-block">
<div class="erp-table-wrap">
<table class="erp-table lv-table">
<thead><tr><th>{{ t('이름 (IC 기준)') }}</th><th>{{ t('전화번호') }}</th><th>{{ t('이메일') }}</th><th>{{ t('주소') }}</th><th>{{ t('은행명') }}</th><th>{{ t('계좌번호') }}</th><th>{{ t('틱톡 핸들') }}</th><th>{{ t('상태') }}</th><th></th></tr></thead>
<thead><tr><th>{{ t('이름 (IC 기준)') }}</th>{% if is_admin %}<th>{{ t('전화번호') }}</th><th>{{ t('이메일') }}</th><th>{{ t('주소') }}</th><th>{{ t('은행명') }}</th><th>{{ t('계좌번호') }}</th>{% endif %}<th>{{ t('틱톡 핸들') }}</th><th>{{ t('상태') }}</th>{% if is_admin %}<th></th>{% endif %}</tr></thead>
<tbody>
{% for h in hosts %}
<tr{% if not h.is_active %} class="lv-off"{% endif %}>
<td data-label="{{ t('이름 (IC 기준)') }}">{{ h.full_name }}</td>
{% if is_admin %}
<td class="lv-nowrap" data-label="{{ t('전화번호') }}">{{ h.phone }}</td>
<td data-label="{{ t('이메일') }}">{{ h.email }}</td>
<td data-label="{{ t('주소') }}">{{ h.address }}</td>
<td data-label="{{ t('은행명') }}">{{ h.bank_name }}</td>
<td class="lv-nowrap" data-label="{{ t('계좌번호') }}">{{ h.bank_account }}</td>
{% endif %}
<td data-label="{{ t('틱톡 핸들') }}">{% if h.tiktok_handle %}@{{ h.tiktok_handle }}{% endif %}</td>
<td class="lv-nowrap" data-label="{{ t('상태') }}">{{ t('사용') if h.is_active else t('사용 안 함') }}</td>
{% if is_admin %}
<td class="lv-actions">
<button type="button" class="erp-btn erp-btn-outline erp-btn-sm" data-edit='{{ {"id": h.id, "full_name": h.full_name, "phone": h.phone, "email": h.email, "address": h.address, "bank_name": h.bank_name, "bank_account": h.bank_account, "tiktok_handle": h.tiktok_handle, "is_active": h.is_active} | tojson }}'>{{ t('고치기') }}</button>
<button type="button" class="erp-btn erp-btn-outline erp-btn-sm" data-post="/live/settings/hosts/{{ h.id }}/delete" data-confirm="{{ t('{name} 호스트를 지울까요?').format(name=h.full_name) }}">{{ t('지우기') }}</button>
</td>
{% endif %}
</tr>
{% else %}
<tr><td colspan="9" class="erp-empty">{{ t('등록한 호스트가 없습니다.') }}</td></tr>
<tr><td colspan="{{ 9 if is_admin else 3 }}" class="erp-empty">{{ t('등록한 호스트가 없습니다.') }}</td></tr>
{% endfor %}
</tbody>
</table>
@@ -54,7 +58,7 @@
<label class="lv-field">{{ t('계좌번호') }} <input class="erp-input" type="text" name="bank_account" maxlength="40" inputmode="numeric" /></label>
</div>
<label class="lv-field">{{ t('틱톡 핸들') }} <input class="erp-input" type="text" name="tiktok_handle" maxlength="200" placeholder="@handle" /></label>
<label class="lv-check"><input type="checkbox" name="is_active" value="1" checked /> {{ t('사용 (끄면 새 방송에서 고를 수 없습니다)') }}</label>
{% if is_admin %}<label class="lv-check"><input type="checkbox" name="is_active" value="1" checked /> {{ t('사용 (끄면 새 방송에서 고를 수 없습니다)') }}</label>{% endif %}
<p class="lv-msg" data-msg role="alert" hidden></p>
<div class="lv-foot">
<button type="button" class="erp-btn erp-btn-outline" data-close>{{ t('취소') }}</button>
+1
View File
@@ -40,6 +40,7 @@ MODULE_KEYS: tuple[str, ...] = (
"inout",
"outreach",
"live",
"live_host",
"expense_approver",
"vacation_approver",
)
+57
View File
@@ -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)