[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
@@ -70,12 +70,12 @@ class PlaceService:
|
||||
# ---- 조회 ----
|
||||
async def list_places(self, user_info: UserInfo, pg: PageParams, search=None, category=None, status=None) -> Res_PlaceList:
|
||||
res = Res_PlaceList(page=pg.page, size=pg.size)
|
||||
cid = uuid.UUID(user_info.company_id)
|
||||
uid = uuid.UUID(user_info.user_id)
|
||||
err_type, rows, total = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.list_places(
|
||||
s, cid, search,
|
||||
s, uid, search,
|
||||
category.value if isinstance(category, PlaceCategory) else category,
|
||||
status.value if isinstance(status, PlaceStatus) else status,
|
||||
pg.skip, pg.size,
|
||||
@@ -102,7 +102,7 @@ class PlaceService:
|
||||
err_type, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.get_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)),
|
||||
lambda s: self.crud.get_place(s, uuid.UUID(user_info.user_id), uuid.UUID(place_id)),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return ErrorType.PLACE_NOT_FOUND, None
|
||||
@@ -122,8 +122,11 @@ class PlaceService:
|
||||
return res
|
||||
|
||||
place = places(
|
||||
company_id=uuid.UUID(user_info.company_id),
|
||||
owner_user_id=req.owner_user_id,
|
||||
# ★ 주인은 **토큰이 정한다.** 예전엔 요청 body 의 owner_user_id 를 그대로 넣었는데,
|
||||
# 그 값은 아무도 안 보내서 92건 전부 NULL 이었고 스코프는 회사가 대신 하고 있었다.
|
||||
# 회사를 걷어내면서 이 컬럼이 스코프 키가 됐다 — body 로 남의 계정을 적을 수 있으면
|
||||
# 만들자마자 남의 목록에 들어간다.
|
||||
owner_user_id=uuid.UUID(user_info.user_id),
|
||||
name=req.name.strip(),
|
||||
category=req.category.value,
|
||||
status=PlaceStatus.DRAFT.value,
|
||||
@@ -149,7 +152,7 @@ class PlaceService:
|
||||
if data:
|
||||
err_type, rowcount = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.update_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id), data),
|
||||
lambda s: self.crud.update_place(s, uuid.UUID(user_info.user_id), uuid.UUID(place_id), data),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
@@ -164,7 +167,7 @@ class PlaceService:
|
||||
err_type, rowcount = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.delete_place(
|
||||
s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)
|
||||
s, uuid.UUID(user_info.user_id), uuid.UUID(place_id)
|
||||
),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
@@ -251,7 +254,7 @@ class PlaceService:
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.update_place(
|
||||
s, uuid.UUID(user_info.company_id), uuid.UUID(place_id), {"name": official}
|
||||
s, uuid.UUID(user_info.user_id), uuid.UUID(place_id), {"name": official}
|
||||
),
|
||||
)
|
||||
if verified.place:
|
||||
@@ -292,7 +295,7 @@ class PlaceService:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
cid = uuid.UUID(user_info.company_id)
|
||||
uid = uuid.UUID(user_info.user_id)
|
||||
now = GTime.UTC()
|
||||
data = {
|
||||
"external_source": req.source.value,
|
||||
@@ -320,7 +323,7 @@ class PlaceService:
|
||||
}
|
||||
err_type, rowcount = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.update_place(s, cid, uuid.UUID(place_id), data),
|
||||
lambda s: self.crud.update_place(s, uid, uuid.UUID(place_id), data),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
@@ -508,7 +511,7 @@ class PlaceService:
|
||||
|
||||
payload = {
|
||||
"place_id": place_id,
|
||||
"company_id": user_info.company_id,
|
||||
"owner_user_id": user_info.user_id,
|
||||
"category": place.category,
|
||||
# 명시적으로 고른 링크가 있을 때만 대상을 제한한다. 기본 요청에서 현재
|
||||
# 확정 링크를 복사하면, 잡의 discover 단계가 새로 확정한 네이버 링크가
|
||||
@@ -537,7 +540,7 @@ class PlaceService:
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.update_place(
|
||||
s, uuid.UUID(user_info.company_id), uuid.UUID(place_id),
|
||||
s, uuid.UUID(user_info.user_id), uuid.UUID(place_id),
|
||||
{"status": PlaceStatus.COLLECTING.value},
|
||||
),
|
||||
)
|
||||
@@ -584,7 +587,7 @@ class PlaceService:
|
||||
|
||||
job_id, created = await enqueue_job(
|
||||
self.queue, JobType.VISION,
|
||||
{"place_id": place_id, "company_id": user_info.company_id, "force": req.force},
|
||||
{"place_id": place_id, "owner_user_id": user_info.user_id, "force": req.force},
|
||||
dedupe_key=f"vision:{place_id}",
|
||||
)
|
||||
if job_id is None:
|
||||
@@ -844,7 +847,7 @@ class PlaceService:
|
||||
|
||||
job_id, created = await enqueue_job(
|
||||
self.queue, JobType.COPY,
|
||||
{"place_id": place_id, "company_id": user_info.company_id, "requested_by": user_info.user_id},
|
||||
{"place_id": place_id, "owner_user_id": user_info.user_id, "requested_by": user_info.user_id},
|
||||
dedupe_key=f"copy:{place_id}",
|
||||
)
|
||||
if job_id is None:
|
||||
|
||||
Reference in new issue
Block a user