가입 한 번이 회사를 하나 만들고 사장님이 그 회사의 직원이 됐다. 가입 폼은 "상호"를 묻고
에디터 헤더에는 "이름 · 회사명" 이 붙었다 — 쓰는 사람은 사장님 한 명인데.
negodata 보일러플레이트의 멀티테넌트 스코프 키를 그대로 물려받은 것이고,
DECISIONS.md 2절이 "대행사/운영사 단위로 그대로 쓴다" 로 유지 결정을 적어 뒀던 자리다.
- gmodel: `UserInfo.company_id` 삭제 — JWT 클레임에서도 사라진다. 스코프 키는 `user_id` 다
- place_crud·site_crud: WHERE 를 `places.owner_user_id` 로. `list_company_sites` → `list_owner_sites`
- place_service: **주인은 토큰이 정한다.** `Req_CreatePlace.owner_user_id` 를 없앴다 —
body 로 받으면 남의 계정을 적어 만들자마자 남의 목록에 넣을 수 있다.
실측: 기존 92건은 아무도 안 보내서 전부 NULL 이었고 스코프는 회사가 대신 하고 있었다
- 워커(collect·copy·build·vision): 잡 페이로드 키 `company_id` → `owner_user_id`.
잡이 세우는 `UserInfo.user_id` 는 이제 **사업장 주인**이다 — 예전엔 요청자·검증자·랜덤 uuid
순으로 채웠는데, 그 랜덤 uuid 가 스코프 키가 되는 순간 "남의 사업장" 이라 fact 조회가 0건이 된다
- auth: `Res_Me.company` · `Req_Signup.company_name` · `CompanyData` 삭제
- models·init.sql: `company.companies` 테이블 · `users.company_id` 삭제,
`places.owner_user_id` NOT NULL. 마이그레이션은 백필 → NOT NULL → DROP 순서다.
회사에 계정이 여럿이면 **가장 먼저 만든 계정**에게 몰고, 주인을 못 찾은 행은 지운다 —
스코프가 없으면 아무에게도 안 보이는 유령이다.
실측(로컬): place 92 → 91(고아 1건 삭제), `demoebf050` 56 · `test` 35
- 프론트: 가입 폼의 상호 칸, 내 정보의 상호 항목, 헤더의 "이름 · 회사명" 삭제
- 테스트: `company_id`/`other_company_id` 픽스처 → `owner_id` 하나.
격리는 `auth_headers("o2")` 를 한 번 더 부르면 그게 남이다
남긴 것 — DB 스키마 이름 `company` 는 그대로다. rename 은 모든 모델의 `__table_args__` 를
건드려야 해서 이번 변경에 섞지 않았다.
검증: 전체 568 passed(실패 1건은 HEAD 에서도 깨지는 레이트리밋 테스트) ·
프론트 tsc+eslint 통과 · 실제 API 로 가입→사업장→목록→격리→발행 한 바퀴
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLWEFx4X3XRmKewUKjJWow
91 lines
4.1 KiB
Python
91 lines
4.1 KiB
Python
"""내 사이트 목록 — 로그인한 사장님이 자기 사이트 전부를 보는 화면의 뒷단.
|
|
|
|
이 경로가 절대 하면 안 되는 것:
|
|
- 사이트가 아직 없는 사업장을 빼는 것 — 위저드를 걸어오다 만 가게가 목록에서 사라지면
|
|
사장님은 그걸 다시 찾을 길이 없다(에디터 주소를 아무도 기억하지 않는다).
|
|
- 사장님 스코프를 놓치는 것 — 남의 가게가 내 목록에 섞이면 그건 목록이 아니라 사고다.
|
|
- 단건(GET /v1/place/{id}/site)과 다른 재빌드 판정을 내는 것 — 목록과 에디터가 서로 다른
|
|
답을 하면 사장님은 어느 쪽을 믿을지 알 수 없다.
|
|
"""
|
|
import uuid
|
|
|
|
from sqlalchemy import text
|
|
|
|
from common.enums import ErrorType, SiteStatus
|
|
|
|
|
|
async def _place(client, headers, name):
|
|
r = await client.post("/v1/place", headers=headers, json={"name": name, "category": 1})
|
|
return r.json()["place"]["place_id"]
|
|
|
|
|
|
async def _list(client, headers, **params):
|
|
return (await client.get("/v1/site/list", headers=headers, params=params)).json()
|
|
|
|
|
|
async def test_place_without_site_is_still_listed(auth_headers, client):
|
|
"""검증: 사이트 행이 없는 사업장(위저드만 걸어온 것)도 목록에 나온다.
|
|
기대결과: 줄은 있고 site_id 는 없다 — 화면이 '만드는 중'으로 그릴 근거다."""
|
|
h = await auth_headers("my1")
|
|
await _place(client, h, "아직펜션")
|
|
|
|
body = await _list(client, h)
|
|
assert body["result"]["code"] == ErrorType.SUCCESS.value
|
|
assert body["total"] == 1
|
|
row = body["sites"][0]
|
|
assert row["name"] == "아직펜션"
|
|
assert row.get("site_id") is None
|
|
assert row.get("status") is None
|
|
|
|
|
|
async def test_site_row_is_joined_into_the_line(auth_headers, client):
|
|
"""검증: 사업장과 사이트가 한 줄로 합쳐져 온다(줄마다 사이트를 다시 묻지 않는다).
|
|
기대결과: 템플릿·주소가 목록에 그대로 보인다."""
|
|
h = await auth_headers("my2")
|
|
pid = await _place(client, h, "합쳐진펜션")
|
|
await client.post(f"/v1/place/{pid}/site/template", headers=h, json={"template_id": "stay-quiet-margin"})
|
|
await client.post(f"/v1/place/{pid}/site/slug", headers=h, json={"slug": "joined-stay"})
|
|
|
|
row = (await _list(client, h))["sites"][0]
|
|
assert row["site_id"]
|
|
assert row["template_id"] == "stay-quiet-margin"
|
|
assert row["domain"] == "joined-stay"
|
|
assert row["status"] == SiteStatus.DRAFT.value
|
|
|
|
|
|
async def test_other_owners_sites_are_not_listed(auth_headers, client):
|
|
"""검증: 사장님 스코프. 남의 사업장은 보이지 않는다.
|
|
기대결과: 각자 자기 것만 1건."""
|
|
mine = await auth_headers("my3")
|
|
theirs = await auth_headers("my3b")
|
|
await _place(client, mine, "내펜션")
|
|
await _place(client, theirs, "남의펜션")
|
|
|
|
assert [r["name"] for r in (await _list(client, mine))["sites"]] == ["내펜션"]
|
|
assert [r["name"] for r in (await _list(client, theirs))["sites"]] == ["남의펜션"]
|
|
|
|
|
|
async def test_needs_rebuild_matches_the_single_site_answer(auth_headers, client, db_engine):
|
|
"""검증: 재빌드 판정이 단건 조회와 같은 답을 낸다.
|
|
기대결과: 노출값이 바뀐 사업장은 목록에서도 needs_rebuild=true."""
|
|
h = await auth_headers("my4")
|
|
pid = await _place(client, h, "고친펜션")
|
|
# 템플릿 저장이 사이트 행을 만든다. 그 뒤 노출값이 바뀐 것으로 표시한다.
|
|
await client.post(f"/v1/place/{pid}/site/template", headers=h, json={"template_id": "t"})
|
|
async with db_engine.begin() as conn:
|
|
await conn.execute(
|
|
text("UPDATE places SET content_updated_at = now() WHERE place_id = :pid"),
|
|
{"pid": uuid.UUID(pid)},
|
|
)
|
|
|
|
single = (await client.get(f"/v1/place/{pid}/site", headers=h)).json()
|
|
row = (await _list(client, h))["sites"][0]
|
|
assert row["needs_rebuild"] is True
|
|
assert row["needs_rebuild"] == single["needs_rebuild"]
|
|
|
|
|
|
async def test_list_requires_login(client):
|
|
"""검증: 내 것을 보는 화면이므로 토큰 없이는 열리지 않는다.
|
|
기대결과: 401."""
|
|
assert (await client.get("/v1/site/list")).status_code == 401
|