feat(라이브): 호스트 등록 전용 권한 칩 live_host
live + live_host 칩이 있으면 새 호스트 등록만 가능. 계좌 등 개인정보 보기, 고치기, 지우기, 사용 여부 변경은 ERP 관리자만. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user