[refactor] solution/backend,frontend,postgres-init: 회사(테넌트) 제거 — 사장님 계정이 곧 스코프
가입 한 번이 회사를 하나 만들고 사장님이 그 회사의 직원이 됐다. 가입 폼은 "상호"를 묻고
에디터 헤더에는 "이름 · 회사명" 이 붙었다 — 쓰는 사람은 사장님 한 명인데.
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
This commit is contained in:
1 parent
00e13bca7f
commit
94551afdaf
53 files changed
+296
-456
No files matched your search
@@ -10,13 +10,13 @@ from common.enums import FactStatus, MediaStatus, PlaceCategory, SourceType
|
||||
from services.snapshot import build_snapshot
|
||||
|
||||
|
||||
async def _seed(db_engine, company_id, category=PlaceCategory.LODGING):
|
||||
async def _seed(db_engine, owner_id, category=PlaceCategory.LODGING):
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(
|
||||
text("INSERT INTO places (place_id, company_id, name, category, status, road_address, phone, verified_at) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status, road_address, phone, verified_at) "
|
||||
"VALUES (:p,:c,:n,:cat,3,:addr,:tel,now())"),
|
||||
{"p": pid, "c": uuid.UUID(company_id), "n": "스냅샷펜션", "cat": category.value,
|
||||
{"p": pid, "c": uuid.UUID(owner_id), "n": "스냅샷펜션", "cat": category.value,
|
||||
"addr": "강원특별자치도 양양군 현북면 하조대3길 11", "tel": "033-000-0000"},
|
||||
)
|
||||
return pid
|
||||
@@ -53,10 +53,10 @@ class _Place:
|
||||
self.longitude = None
|
||||
|
||||
|
||||
async def test_only_publishable_facts_enter_snapshot(db_engine, company_id):
|
||||
async def test_only_publishable_facts_enter_snapshot(db_engine, owner_id):
|
||||
"""검증: 여러 상태의 fact 를 섞어 넣는다.
|
||||
기대결과: ★ VERIFIED·CORRECTED 만 스냅샷에 담긴다 — 미검증 값이 사이트로 새지 않는다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _fact(db_engine, pid, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
await _fact(db_engine, pid, "wifi", "true", FactStatus.CORRECTED)
|
||||
await _fact(db_engine, pid, "parking", "true", FactStatus.UNVERIFIED)
|
||||
@@ -69,10 +69,10 @@ async def test_only_publishable_facts_enter_snapshot(db_engine, company_id):
|
||||
assert keys == {"check_in_time", "wifi"}
|
||||
|
||||
|
||||
async def test_only_approved_media_enters_snapshot(db_engine, company_id):
|
||||
async def test_only_approved_media_enters_snapshot(db_engine, owner_id):
|
||||
"""검증: 승인/확인대기/반려 사진을 섞어 넣는다.
|
||||
기대결과: ★ APPROVED 만 담긴다 — Vision 신뢰도가 낮아 확인 큐에 남은 사진은 안 나간다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _media(db_engine, pid, "https://cdn.test/ok.jpg", MediaStatus.APPROVED)
|
||||
await _media(db_engine, pid, "https://cdn.test/pending.jpg", MediaStatus.PENDING_REVIEW)
|
||||
await _media(db_engine, pid, "https://cdn.test/no.jpg", MediaStatus.REJECTED)
|
||||
@@ -81,10 +81,10 @@ async def test_only_approved_media_enters_snapshot(db_engine, company_id):
|
||||
assert [m["url"] for m in snap["media"]] == ["https://cdn.test/ok.jpg"]
|
||||
|
||||
|
||||
async def test_media_without_alt_is_excluded(db_engine, company_id):
|
||||
async def test_media_without_alt_is_excluded(db_engine, owner_id):
|
||||
"""검증: 승인됐지만 alt 텍스트가 없는 사진.
|
||||
기대결과: 빠진다 — alt 없는 이미지는 접근성도 AI 검색 신호도 없다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _media(db_engine, pid, "https://cdn.test/noalt.jpg", MediaStatus.APPROVED, alt="")
|
||||
await _media(db_engine, pid, "https://cdn.test/withalt.jpg", MediaStatus.APPROVED, alt="침실 사진")
|
||||
|
||||
@@ -92,10 +92,10 @@ async def test_media_without_alt_is_excluded(db_engine, company_id):
|
||||
assert [m["url"] for m in snap["media"]] == ["https://cdn.test/withalt.jpg"]
|
||||
|
||||
|
||||
async def test_fact_labels_come_from_category_schema(db_engine, company_id):
|
||||
async def test_fact_labels_come_from_category_schema(db_engine, owner_id):
|
||||
"""검증: 스냅샷의 fact 라벨.
|
||||
기대결과: 업종 스키마의 한글 라벨이 붙는다 — 화면이 key 를 그대로 노출하지 않게."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _fact(db_engine, pid, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
|
||||
snap = await build_snapshot(_Place(pid))
|
||||
@@ -104,10 +104,10 @@ async def test_fact_labels_come_from_category_schema(db_engine, company_id):
|
||||
assert f["scope"] == "place"
|
||||
|
||||
|
||||
async def test_unit_scoped_facts_carry_unit_id(db_engine, company_id):
|
||||
async def test_unit_scoped_facts_carry_unit_id(db_engine, owner_id):
|
||||
"""검증: 객실 단위 fact.
|
||||
기대결과: unit_id 가 실려 빌더가 객실별로 묶을 수 있다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
uid = uuid.uuid4()
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(text("INSERT INTO units (unit_id, place_id, name, sort_order) VALUES (:u,:p,:n,0)"),
|
||||
@@ -120,10 +120,10 @@ async def test_unit_scoped_facts_carry_unit_id(db_engine, company_id):
|
||||
assert snap["facts"][0]["scope"] == "unit"
|
||||
|
||||
|
||||
async def test_empty_place_gives_empty_snapshot(db_engine, company_id):
|
||||
async def test_empty_place_gives_empty_snapshot(db_engine, owner_id):
|
||||
"""검증: 아무것도 없는 사업장.
|
||||
기대결과: 빈 스냅샷 — 게이트가 고유 콘텐츠 0건으로 거부할 재료가 된다."""
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
snap = await build_snapshot(_Place(pid))
|
||||
assert snap["facts"] == [] and snap["media"] == [] and snap["faqs"] == []
|
||||
assert snap["place"]["name"] == "스냅샷펜션"
|
||||
@@ -156,13 +156,13 @@ class _RegionPlace(_Place):
|
||||
self.region_code = region_code
|
||||
|
||||
|
||||
async def test_only_published_local_content_enters_snapshot(db_engine, company_id):
|
||||
async def test_only_published_local_content_enters_snapshot(db_engine, owner_id):
|
||||
"""검증: 검수대기·종료·발행 지역 정보를 섞어 넣는다.
|
||||
기대결과: ★ PUBLISHED 만 담긴다 — 운영자가 검수하지 않은 외부 API 원문이 사이트로 새면
|
||||
'미검증 값 노출 금지'가 깨진다(fact 를 VERIFIED 로 거르는 것과 같은 규칙)."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "발행축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.REVIEW, "검수대기축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.ENDED, "종료축제")
|
||||
@@ -171,7 +171,7 @@ async def test_only_published_local_content_enters_snapshot(db_engine, company_i
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["발행축제"]
|
||||
|
||||
|
||||
async def test_local_content_outside_display_window_is_excluded(db_engine, company_id):
|
||||
async def test_local_content_outside_display_window_is_excluded(db_engine, owner_id):
|
||||
"""검증: 발행됐지만 노출 기간을 벗어난 지역 정보.
|
||||
기대결과: 빠진다 — 끝난 축제를 '이번 주말 행사'로 걸어두는 것도 틀린 정보다."""
|
||||
from datetime import datetime, timedelta, timezone
|
||||
@@ -179,7 +179,7 @@ async def test_local_content_outside_display_window_is_excluded(db_engine, compa
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "지금축제")
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "끝난축제",
|
||||
display_end_at=now - timedelta(days=1))
|
||||
@@ -190,12 +190,12 @@ async def test_local_content_outside_display_window_is_excluded(db_engine, compa
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["지금축제"]
|
||||
|
||||
|
||||
async def test_local_content_is_scoped_to_the_places_region(db_engine, company_id):
|
||||
async def test_local_content_is_scoped_to_the_places_region(db_engine, owner_id):
|
||||
"""검증: 지역 캐시는 region_code 로 묶인다.
|
||||
기대결과: 다른 지역의 발행 콘텐츠는 담기지 않는다."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "우리지역축제")
|
||||
await _local(db_engine, "5011025", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "남의지역축제")
|
||||
|
||||
@@ -203,7 +203,7 @@ async def test_local_content_is_scoped_to_the_places_region(db_engine, company_i
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["우리지역축제"]
|
||||
|
||||
|
||||
async def test_region_code_is_derived_from_the_address_when_missing(db_engine, company_id):
|
||||
async def test_region_code_is_derived_from_the_address_when_missing(db_engine, owner_id):
|
||||
"""검증: region_code 가 비어 있지만 도로명주소는 있는 사업장.
|
||||
기대결과: 주소에서 지역 키를 유도해 그 지역 콘텐츠를 담는다 — places.region_code 를 채우는
|
||||
코드가 생기기 전에 만들어진 사업장(실측 28곳 중 25곳)이 영영 지역 정보 없이 발행되지 않게 한다."""
|
||||
@@ -211,7 +211,7 @@ async def test_region_code_is_derived_from_the_address_when_missing(db_engine, c
|
||||
from services.external.naver import region_key
|
||||
|
||||
derived = region_key(_Place("x").road_address)
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, derived, LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "양양축제")
|
||||
|
||||
snap = await build_snapshot(_RegionPlace(pid, ""))
|
||||
@@ -219,12 +219,12 @@ async def test_region_code_is_derived_from_the_address_when_missing(db_engine, c
|
||||
assert [c["title"] for c in snap["local"]["contents"]] == ["양양축제"]
|
||||
|
||||
|
||||
async def test_place_without_any_region_key_gets_no_local_content(db_engine, company_id):
|
||||
async def test_place_without_any_region_key_gets_no_local_content(db_engine, owner_id):
|
||||
"""검증: 지역 코드도 읽을 만한 주소도 없는 사업장.
|
||||
기대결과: 빈 목록 — 조회할 캐시 키가 없다. 지어내지 않는다."""
|
||||
from common.enums import LocalContentStatus, LocalContentType
|
||||
|
||||
pid = await _seed(db_engine, company_id)
|
||||
pid = await _seed(db_engine, owner_id)
|
||||
await _local(db_engine, "4113500", LocalContentType.FESTIVAL, LocalContentStatus.PUBLISHED, "어딘가축제")
|
||||
|
||||
place = _RegionPlace(pid, "")
|
||||
|
||||
Reference in new issue
Block a user