Merge branch 'main' into feat-tourApi
This commit is contained in:
commit
3b43446fe6
131 files changed
+4624
-1558
No files matched your search
@@ -10,7 +10,6 @@ from common.enums import (
|
||||
DBType,
|
||||
UserStatus,
|
||||
UserRole,
|
||||
CompanyStatus,
|
||||
PlaceStatus,
|
||||
FactStatus,
|
||||
MediaStatus,
|
||||
@@ -45,30 +44,11 @@ class MainTableMixin(_DBTypeMixin):
|
||||
|
||||
|
||||
# ERD 도메인 모델
|
||||
class companies(MainTableMixin, MAIN_BASE):
|
||||
__tablename__ = "companies"
|
||||
__table_args__ = {"schema": "company"}
|
||||
|
||||
company_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column(String(100), nullable=False)
|
||||
business_number = Column(String(30), nullable=True)
|
||||
code = Column(Integer, nullable=True) # 내부 인덱스용
|
||||
representative_name = Column(String(50), nullable=True)
|
||||
email = Column(String(255), nullable=True)
|
||||
contact_number = Column(String(20), nullable=True)
|
||||
website_url = Column(String(255), nullable=True)
|
||||
industry = Column(SmallInteger, nullable=True) # 업종 코드 (스키마 SMALLINT)
|
||||
status = Column(SmallInteger, nullable=False, default=CompanyStatus.ACTIVE.value) # CompanyStatus
|
||||
# 회사별 커스터마이징 설정. branding(CI)/labels(용어)/features(동작)
|
||||
settings = Column(JSONB, nullable=True)
|
||||
|
||||
|
||||
class users(MainTableMixin, MAIN_BASE):
|
||||
__tablename__ = "users"
|
||||
__table_args__ = {"schema": "company"}
|
||||
|
||||
user_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
company_id = Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||
# 20자였다. 구글 계정의 로그인 아이디를 `google_<sub>`(최대 28자)로 만들면서 넓혔다 —
|
||||
# sub 를 잘라 쓰면 앞자리가 같은 두 계정이 한 아이디로 겹친다.
|
||||
id = Column(String(64), nullable=False, unique=True, index=True) # 로그인 아이디
|
||||
@@ -102,8 +82,8 @@ class places(MainTableMixin, MAIN_BASE):
|
||||
)
|
||||
|
||||
place_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
company_id = Column(UUID(as_uuid=True), nullable=False, index=True) # 테넌트 스코프(company.companies)
|
||||
owner_user_id = Column(UUID(as_uuid=True), nullable=True, index=True) # 사장님 계정(company.users)
|
||||
# ★ 스코프 키. 사장님 한 명이 자기 가게만 본다 — 회사(테넌트)를 걷어내면서 이 컬럼이 그 자리를 받았다.
|
||||
owner_user_id = Column(UUID(as_uuid=True), nullable=False, index=True) # 사장님 계정(company.users)
|
||||
name = Column(String(200), nullable=False) # 상호명(입력값)
|
||||
category = Column(SmallInteger, nullable=False) # PlaceCategory — 업종 스키마 선택 키
|
||||
status = Column(SmallInteger, nullable=False, server_default=text("1"), default=PlaceStatus.DRAFT.value)
|
||||
|
||||
@@ -67,9 +67,8 @@ class PageParams:
|
||||
class UserInfo(StructModel):
|
||||
"""JWT subject 로 인코딩되는 유저 식별 정보."""
|
||||
|
||||
user_id: str # users.user_id (uuid) — 데이터 스코프 키
|
||||
user_id: str # users.user_id (uuid) — 데이터 스코프 키. 사업장은 owner_user_id 로 이 값에 매인다
|
||||
id: str # users.id (로그인 아이디) — get_me 재조회 키
|
||||
company_id: str # users.company_id (uuid) — 멀티테넌트 스코프 키
|
||||
role: int # users.role (UserRole) — 권한 게이트(최고관리자 등) 판단 키
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
|
||||
@@ -14,7 +14,7 @@ from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
|
||||
from common.database.model.models import MAIN_BASE
|
||||
from common.enums import CompanyStatus
|
||||
from common.enums import UserRole, UserStatus
|
||||
from config.server_configs import main_db_config
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ async def db_engine(_test_db_lifecycle):
|
||||
# 도메인 테이블 전부 비워 격리 (CASCADE: FK 미설정이라 안전망)
|
||||
await conn.execute(
|
||||
text(
|
||||
"TRUNCATE TABLE users, companies, places, place_aliases, place_links, units, media, "
|
||||
"TRUNCATE TABLE users, places, place_aliases, place_links, units, media, "
|
||||
"facts, faqs, local_contents, routes, nearby_links, "
|
||||
"sites, site_versions, publish_logs, ai_check_results, jobs RESTART IDENTITY CASCADE"
|
||||
)
|
||||
@@ -102,30 +102,24 @@ async def db_engine(_test_db_lifecycle):
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def company_id(db_engine) -> str:
|
||||
"""테스트용 소속사 1개를 시드하고 company_id(uuid str)를 돌려준다.
|
||||
users 는 company_id 를 요구하므로 계정 생성 테스트의 선행 조건이다.
|
||||
async def owner_id(db_engine) -> str:
|
||||
"""사장님 계정 1개를 시드하고 user_id(uuid str)를 돌려준다.
|
||||
|
||||
★ 예전엔 `company_id`(소속사)였다. 회사(테넌트)를 걷어내면서 사업장이 `owner_user_id` 로
|
||||
계정에 직접 매이게 됐다 — DB 를 직접 시드하는 테스트가 place 에 넣을 주인이 이 값이다.
|
||||
"""
|
||||
cid = uuid.uuid4()
|
||||
uid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
# status 는 NOT NULL(모델 default 는 ORM 전용이라 raw INSERT 엔 안 먹음) → 명시.
|
||||
# status·role 은 NOT NULL(모델 default 는 ORM 전용이라 raw INSERT 엔 안 먹음) → 명시.
|
||||
await conn.execute(
|
||||
text("INSERT INTO companies (company_id, name, status) VALUES (:cid, :name, :status)"),
|
||||
{"cid": cid, "name": "테스트사", "status": CompanyStatus.ACTIVE.value},
|
||||
text(
|
||||
"INSERT INTO users (user_id, id, password, name, status, role, last_accessed_at) "
|
||||
"VALUES (:uid, :id, NULL, :name, :status, :role, now())"
|
||||
),
|
||||
{"uid": uid, "id": f"seed{uid.hex[:8]}", "name": "시드사장",
|
||||
"status": UserStatus.ACTIVE.value, "role": UserRole.USER.value},
|
||||
)
|
||||
return str(cid)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def other_company_id(db_engine) -> str:
|
||||
"""company_id 와 다른 소속사 1개(회사 스코프/IDOR 격리 테스트용)."""
|
||||
cid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text("INSERT INTO companies (company_id, name, status) VALUES (:cid, :name, :status)"),
|
||||
{"cid": cid, "name": "다른회사", "status": CompanyStatus.ACTIVE.value},
|
||||
)
|
||||
return str(cid)
|
||||
return str(uid)
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
@@ -139,28 +133,27 @@ async def client(db_engine):
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def auth_headers(db_engine, client, company_id):
|
||||
async def auth_headers(db_engine, client):
|
||||
"""테스트 유저를 시드하고 로그인 헤더(Bearer)를 돌려주는 팩토리.
|
||||
|
||||
계정 생성 API 가 없으므로 users 행을 직접 INSERT(비번 bcrypt 해시)한 뒤 /v1/auth/login 으로 토큰을 받는다.
|
||||
company 미지정 시 기본 소속사(company_id 픽스처). role 로 OWNER 계정도 만들 수 있다.
|
||||
호출: `h = await auth_headers("user1")` / `await auth_headers("userB", other_company_id)`.
|
||||
★ 회사 인자가 없다. 스코프가 계정 자체이므로 **다른 login_id 로 한 번 더 부르면 그게 남**이다
|
||||
— 격리 테스트는 `await auth_headers("o2")` 하나면 된다.
|
||||
호출: `h = await auth_headers("user1")`.
|
||||
"""
|
||||
from common.enums import UserRole, UserStatus
|
||||
from router.v1.validator.dependencies import GetHashedPW
|
||||
|
||||
async def _make(login_id, company=None, *, password="pw1234", role=UserRole.USER.value, name="n"):
|
||||
cid = company or company_id
|
||||
async def _make(login_id, *, password="pw1234", role=UserRole.USER.value, name="n"):
|
||||
hashed = await GetHashedPW(password)
|
||||
async with db_engine.begin() as conn:
|
||||
# status·role 은 NOT NULL — ORM default 는 raw INSERT 에 안 먹으므로 명시(companies.status 와 동일).
|
||||
# status·role 은 NOT NULL — ORM default 는 raw INSERT 에 안 먹으므로 명시.
|
||||
await conn.execute(
|
||||
text(
|
||||
"INSERT INTO users (user_id, company_id, id, password, name, status, role, last_accessed_at) "
|
||||
"VALUES (:uid, :cid, :id, :pw, :name, :status, :role, now())"
|
||||
"INSERT INTO users (user_id, id, password, name, status, role, last_accessed_at) "
|
||||
"VALUES (:uid, :id, :pw, :name, :status, :role, now())"
|
||||
),
|
||||
{
|
||||
"uid": uuid.uuid4(), "cid": uuid.UUID(cid), "id": login_id, "pw": hashed,
|
||||
"uid": uuid.uuid4(), "id": login_id, "pw": hashed,
|
||||
"name": name, "status": UserStatus.ACTIVE.value, "role": role,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -11,26 +11,26 @@ from common.logger import LOG
|
||||
from common.utils.gtime import GTime
|
||||
|
||||
|
||||
# 사업장 CRUD. 모든 조회는 company_id(테넌트)로 스코프한다 — 남의 회사 사업장이 보이면 안 된다.
|
||||
# 사업장 CRUD. 모든 조회는 owner_user_id(사장님)로 스코프한다 — 남의 가게가 보이면 안 된다.
|
||||
class IPlaceCRUD(ABC):
|
||||
@abstractmethod
|
||||
async def add_place(self, cdb: AsyncSession, place: places) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_place(self, cdb: AsyncSession, company_id, place_id) -> Tuple[ErrorType, places]:
|
||||
async def get_place(self, cdb: AsyncSession, owner_user_id, place_id) -> Tuple[ErrorType, places]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def list_places(self, cdb: AsyncSession, company_id, search, category, status, skip, limit) -> Tuple[ErrorType, list, int]:
|
||||
async def list_places(self, cdb: AsyncSession, owner_user_id, search, category, status, skip, limit) -> Tuple[ErrorType, list, int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def update_place(self, cdb: AsyncSession, company_id, place_id, data: dict) -> Tuple[ErrorType, int]:
|
||||
async def update_place(self, cdb: AsyncSession, owner_user_id, place_id, data: dict) -> Tuple[ErrorType, int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def delete_place(self, cdb: AsyncSession, company_id, place_id) -> Tuple[ErrorType, int]:
|
||||
async def delete_place(self, cdb: AsyncSession, owner_user_id, place_id) -> Tuple[ErrorType, int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@@ -73,11 +73,11 @@ class PlaceCRUD(IPlaceCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def get_place(self, cdb: AsyncSession, company_id, place_id) -> Tuple[ErrorType, places]:
|
||||
async def get_place(self, cdb: AsyncSession, owner_user_id, place_id) -> Tuple[ErrorType, places]:
|
||||
try:
|
||||
query = (
|
||||
select(places)
|
||||
.where(places.place_id == place_id, places.company_id == company_id, places.deleted == False) # noqa: E712
|
||||
.where(places.place_id == place_id, places.owner_user_id == owner_user_id, places.deleted == False) # noqa: E712
|
||||
.limit(1)
|
||||
)
|
||||
err_type, row_list = await DB_SESSION_MNG.execute(cdb, query)
|
||||
@@ -91,11 +91,11 @@ class PlaceCRUD(IPlaceCRUD):
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def list_places(
|
||||
self, cdb: AsyncSession, company_id, search: Optional[str], category: Optional[int],
|
||||
self, cdb: AsyncSession, owner_user_id, search: Optional[str], category: Optional[int],
|
||||
status: Optional[int], skip: int, limit: int,
|
||||
) -> Tuple[ErrorType, list, int]:
|
||||
try:
|
||||
conditions = [places.deleted == False, places.company_id == company_id] # noqa: E712
|
||||
conditions = [places.deleted == False, places.owner_user_id == owner_user_id] # noqa: E712
|
||||
if category is not None:
|
||||
conditions.append(places.category == category)
|
||||
if status is not None:
|
||||
@@ -126,14 +126,14 @@ class PlaceCRUD(IPlaceCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, [], 0
|
||||
|
||||
async def update_place(self, cdb: AsyncSession, company_id, place_id, data: dict) -> Tuple[ErrorType, int]:
|
||||
async def update_place(self, cdb: AsyncSession, owner_user_id, place_id, data: dict) -> Tuple[ErrorType, int]:
|
||||
"""회사 스코프를 WHERE 에 걸어 남의 회사 사업장을 못 건드리게 한다. (ErrorType, 적용행수)."""
|
||||
try:
|
||||
if not data:
|
||||
return ErrorType.SUCCESS, 0
|
||||
query = (
|
||||
update(places)
|
||||
.where(places.place_id == place_id, places.company_id == company_id, places.deleted == False) # noqa: E712
|
||||
.where(places.place_id == place_id, places.owner_user_id == owner_user_id, places.deleted == False) # noqa: E712
|
||||
.values(**data, updated_at=GTime.UTC())
|
||||
)
|
||||
return await DB_SESSION_MNG.add_with_rowcount(cdb, query)
|
||||
@@ -141,12 +141,12 @@ class PlaceCRUD(IPlaceCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, 0
|
||||
|
||||
async def delete_place(self, cdb: AsyncSession, company_id, place_id) -> Tuple[ErrorType, int]:
|
||||
async def delete_place(self, cdb: AsyncSession, owner_user_id, place_id) -> Tuple[ErrorType, int]:
|
||||
"""사업장을 실제 삭제한다. 회사 스코프 밖의 행은 건드리지 않는다."""
|
||||
try:
|
||||
query = (
|
||||
delete(places)
|
||||
.where(places.place_id == place_id, places.company_id == company_id, places.deleted == False) # noqa: E712
|
||||
.where(places.place_id == place_id, places.owner_user_id == owner_user_id, places.deleted == False) # noqa: E712
|
||||
)
|
||||
return await DB_SESSION_MNG.add_with_rowcount(cdb, query)
|
||||
except Exception as ex:
|
||||
|
||||
@@ -22,7 +22,7 @@ class ISiteCRUD(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def list_company_sites(self, cdb: AsyncSession, company_id, skip, limit) -> Tuple[ErrorType, list, int]:
|
||||
async def list_owner_sites(self, cdb: AsyncSession, owner_user_id, skip, limit) -> Tuple[ErrorType, list, int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@@ -93,13 +93,13 @@ class SiteCRUD(ISiteCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def list_company_sites(self, cdb: AsyncSession, company_id, skip: int, limit: int) -> Tuple[ErrorType, list, int]:
|
||||
"""회사의 사업장 + 사이트 + 마지막 빌드 시각. (ErrorType, [(place, site, built_at)], 총건수).
|
||||
async def list_owner_sites(self, cdb: AsyncSession, owner_user_id, skip: int, limit: int) -> Tuple[ErrorType, list, int]:
|
||||
"""사장님의 사업장 + 사이트 + 마지막 빌드 시각. (ErrorType, [(place, site, built_at)], 총건수).
|
||||
|
||||
따로 읽으면 줄마다 사이트를 다시 물어 N+1 이다. LEFT JOIN 이라 사이트가 없는 사업장
|
||||
(위저드만 걸어온 것)도 내려간다 — 빠지면 만들다 만 것을 찾을 길이 없다."""
|
||||
try:
|
||||
where = and_(places.deleted == False, places.company_id == company_id) # noqa: E712
|
||||
where = and_(places.deleted == False, places.owner_user_id == owner_user_id) # noqa: E712
|
||||
|
||||
cnt_err, cnt_rows = await DB_SESSION_MNG.execute(cdb, select(func.count()).select_from(places).where(where))
|
||||
if cnt_err != ErrorType.SUCCESS:
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional, Tuple
|
||||
from typing import Tuple
|
||||
|
||||
from sqlalchemy import select, func, and_, or_, update
|
||||
from sqlalchemy import select, func, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import users, companies
|
||||
from common.enums import ErrorType, UserRole
|
||||
from common.database.model.models import users
|
||||
from common.enums import ErrorType
|
||||
from common.logger import LOG
|
||||
from common.utils.gtime import GTime
|
||||
|
||||
@@ -39,22 +39,6 @@ class IUserCRUD(ABC):
|
||||
async def update_last_accessed(self, cdb: AsyncSession, user_id) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def add_company(self, cdb: AsyncSession, company: companies) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_company(self, cdb: AsyncSession, company_id) -> Tuple[ErrorType, companies]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def update_company_settings(self, cdb: AsyncSession, company_id, settings: dict) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def list_by_company(self, cdb: AsyncSession, company_id, search, skip, limit, hide_dev: bool = False) -> Tuple[ErrorType, list, int]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_by_user_id(self, cdb: AsyncSession, user_id) -> Tuple[ErrorType, users]:
|
||||
pass
|
||||
@@ -145,72 +129,6 @@ class UserCRUD(IUserCRUD):
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def add_company(self, cdb: AsyncSession, company: companies) -> ErrorType:
|
||||
try:
|
||||
return await DB_SESSION_MNG.insert(cdb, company)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def get_company(self, cdb: AsyncSession, company_id) -> Tuple[ErrorType, companies]:
|
||||
try:
|
||||
query = select(companies).where(companies.company_id == company_id, companies.deleted == False).limit(1) # noqa: E712
|
||||
err_type, row_list = await DB_SESSION_MNG.execute(cdb, query)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, None
|
||||
if len(row_list) != 1:
|
||||
return ErrorType.DB_INVALID_KEY, None
|
||||
return ErrorType.SUCCESS, row_list[0]
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def update_company_settings(self, cdb: AsyncSession, company_id, settings: dict) -> ErrorType:
|
||||
try:
|
||||
query = (
|
||||
update(companies)
|
||||
.where(companies.company_id == company_id, companies.deleted == False) # noqa: E712
|
||||
.values(settings=settings, updated_at=GTime.UTC())
|
||||
)
|
||||
return await DB_SESSION_MNG.add(cdb, query)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def list_by_company(
|
||||
self, cdb: AsyncSession, company_id, search: Optional[str], skip: int, limit: int, hide_dev: bool = False
|
||||
) -> Tuple[ErrorType, list, int]:
|
||||
try:
|
||||
conditions = [users.deleted == False, users.company_id == company_id] # noqa: E712
|
||||
# 개발자(내부 운영) 계정은 고객사에 존재 자체가 보이면 안 된다 — 목록에서 빼고 총계에도 넣지 않는다.
|
||||
if hide_dev:
|
||||
conditions.append(users.role != UserRole.DEVELOPER.value)
|
||||
if search:
|
||||
conditions.append(
|
||||
or_(
|
||||
users.id.ilike(f"%{search}%"),
|
||||
users.name.ilike(f"%{search}%"),
|
||||
users.email.ilike(f"%{search}%"),
|
||||
)
|
||||
)
|
||||
where = and_(*conditions)
|
||||
|
||||
cnt_err, cnt_rows = await DB_SESSION_MNG.execute(cdb, select(func.count()).select_from(users).where(where))
|
||||
if cnt_err != ErrorType.SUCCESS:
|
||||
return cnt_err, [], 0
|
||||
total = int(cnt_rows[0] or 0) if cnt_rows else 0
|
||||
|
||||
list_err, rows = await DB_SESSION_MNG.execute(
|
||||
cdb,
|
||||
select(users).where(where).order_by(users.created_at.desc()).offset(skip).limit(limit),
|
||||
)
|
||||
if list_err != ErrorType.SUCCESS:
|
||||
return list_err, [], 0
|
||||
return ErrorType.SUCCESS, list(rows), total
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, [], 0
|
||||
|
||||
async def get_by_user_id(self, cdb: AsyncSession, user_id) -> Tuple[ErrorType, users]:
|
||||
try:
|
||||
query = select(users).where(users.user_id == user_id, users.deleted == False).limit(1) # noqa: E712
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from common.enums import AuthProvider, UserRole
|
||||
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
|
||||
|
||||
@@ -17,7 +15,7 @@ class Req_Login(AuthProtocol):
|
||||
|
||||
|
||||
class Req_Signup(AuthProtocol):
|
||||
"""id/pw 가입. 가입 = 새 테넌트(회사) 1개 + 그 회사의 첫 계정 1개다.
|
||||
"""id/pw 가입. 가입 = 계정 1개다.
|
||||
|
||||
★ 이메일을 필수로 받는 이유: 같은 이메일이 이미 구글로 가입돼 있는지 판단할 근거가 없으면
|
||||
한 사람에게 계정이 둘 생긴다. 지금 이메일 인증 절차는 없다 — 소유 증명이 아니라
|
||||
@@ -27,7 +25,6 @@ class Req_Signup(AuthProtocol):
|
||||
password: str = ""
|
||||
name: Optional[str] = None
|
||||
email: str = ""
|
||||
company_name: Optional[str] = None # 상호. 비우면 이름 → 아이디 순으로 채운다
|
||||
|
||||
|
||||
class Req_GoogleLogin(AuthProtocol):
|
||||
@@ -46,7 +43,7 @@ class Res_Login(Res_WebPacketProtocol):
|
||||
|
||||
|
||||
class Req_UpdateMe(AuthProtocol):
|
||||
# 본인 정보 수정. role·company·id 는 받지 않는다(자기 권한·소속 변경 불가).
|
||||
# 본인 정보 수정. role·id 는 받지 않는다(자기 권한 변경 불가).
|
||||
name: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
contact_number: Optional[str] = None
|
||||
@@ -58,11 +55,6 @@ class Res_RefreshToken(Res_WebPacketProtocol):
|
||||
token_type: str = "bearer"
|
||||
|
||||
|
||||
class CompanyData(WebPacketProtocol):
|
||||
company_id: str = ""
|
||||
name: str = ""
|
||||
|
||||
|
||||
class Res_Me(Res_WebPacketProtocol):
|
||||
user_id: str = ""
|
||||
id: str = ""
|
||||
@@ -73,4 +65,3 @@ class Res_Me(Res_WebPacketProtocol):
|
||||
# 이 계정이 무엇으로 로그인하는가. 구글 계정에는 바꿀 비밀번호가 없어서(update_me 가 막는다)
|
||||
# 내 정보 화면이 붙을 때 이 값으로 갈라야 한다.
|
||||
provider: AuthProvider = AuthProvider.LOCAL
|
||||
company: Optional[CompanyData] = Field(default=None)
|
||||
@@ -31,7 +31,7 @@ from .protocol import (
|
||||
Res_UnitList,
|
||||
)
|
||||
|
||||
# 사업장 라우터. 모든 조회·변경은 토큰의 회사(company_id)로 스코프된다.
|
||||
# 사업장 라우터. 모든 조회·변경은 토큰의 사장님(places.owner_user_id)으로 스코프된다.
|
||||
router = APIRouter(prefix="/v1/place", tags=["Place"], responses={404: {"description": "Not found"}})
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ class Req_CreatePlace(PlaceProtocol):
|
||||
# 상호명 하나로 시작한다. 나머지는 카카오 로컬 검증이 채운다.
|
||||
name: str = ""
|
||||
category: PlaceCategory = PlaceCategory.LODGING
|
||||
owner_user_id: Optional[uuid.UUID] = None
|
||||
# ★ 주인은 받지 않는다 — 토큰이 정한다(place_service.create_place). 여기로 받으면
|
||||
# 남의 계정을 적어 만들자마자 남의 목록에 넣을 수 있다.
|
||||
|
||||
|
||||
class Req_VerifyPlace(PlaceProtocol):
|
||||
@@ -60,8 +61,8 @@ class Req_VerifyPlaceByUrl(PlaceProtocol):
|
||||
|
||||
|
||||
class Req_UpdatePlace(PlaceProtocol):
|
||||
# ★ 주인은 못 바꾼다(위 Req_CreatePlace 주석). 소유권 이전은 아직 기능이 아니다.
|
||||
name: Optional[str] = None
|
||||
owner_user_id: Optional[uuid.UUID] = None
|
||||
status: Optional[PlaceStatus] = None
|
||||
|
||||
|
||||
@@ -214,7 +215,7 @@ class Res_VerifyCandidates(Res_WebPacketProtocol):
|
||||
class PlaceSearchItem(WebPacketProtocol):
|
||||
"""공개 검색 결과 1건.
|
||||
|
||||
★ 외부 장소 DB 가 공개적으로 주는 값만 담는다. 우리 DB 값(place_id·company_id·소유자)은
|
||||
★ 외부 장소 DB 가 공개적으로 주는 값만 담는다. 우리 DB 값(place_id·소유자)은
|
||||
하나도 나가지 않는다 — 로그인 없이 열려 있는 응답이라 여기에 우리 것을 실으면 그대로 샌다.
|
||||
★ 좌표·전화번호도 뺐다. 랜딩이 하는 일은 '어느 가게인지 고르게 하는 것'뿐이고,
|
||||
확정과 수집은 로그인 뒤 기존 경로(POST /place → verify)가 그대로 한다."""
|
||||
|
||||
@@ -85,6 +85,8 @@ class MySiteData(WebPacketProtocol):
|
||||
domain: Optional[str] = None
|
||||
template_id: Optional[str] = None
|
||||
published_at: Optional[datetime] = None
|
||||
# 목록 카드의 그림. 발행에 성공해야 채워지고, 발행마다 `?v=` 가 바뀐다(site_thumbnail.public_url).
|
||||
thumbnail_url: Optional[str] = None
|
||||
# 단건과 같은 규칙 — 노출값이 마지막 빌드보다 나중에 바뀌었으면 재발행 대상이다.
|
||||
needs_rebuild: bool = False
|
||||
|
||||
@@ -235,7 +237,7 @@ class ShowcaseItem(WebPacketProtocol):
|
||||
"""랜딩 쇼케이스 카드 한 장. **로그인 없이 나가는 값이다.**
|
||||
|
||||
★ 여기 있는 것은 전부 이미 발행된 페이지에 적혀 있는 것뿐이다.
|
||||
place_id·company_id·전화번호·상세 주소는 절대 싣지 않는다 — 사이트 한 곳을 여는 것과
|
||||
place_id·소유자·전화번호·상세 주소는 절대 싣지 않는다 — 사이트 한 곳을 여는 것과
|
||||
발행 업소 명단을 통째로 긁는 것은 다른 일이다. 지역도 시·군·구까지만 준다."""
|
||||
|
||||
name: str
|
||||
|
||||
@@ -53,13 +53,11 @@ async def main():
|
||||
engine = create_async_engine(dsn)
|
||||
|
||||
from router.v1.validator.dependencies import GetHashedPW
|
||||
cid, uid, login = uuid.uuid4(), uuid.uuid4(), f"demo{uuid.uuid4().hex[:6]}"
|
||||
uid, login = uuid.uuid4(), f"demo{uuid.uuid4().hex[:6]}"
|
||||
async with engine.begin() as c:
|
||||
await c.execute(text("INSERT INTO company.companies (company_id,name,status) VALUES (:c,:n,1)"),
|
||||
{"c": cid, "n": "데모대행사"})
|
||||
await c.execute(text("INSERT INTO company.users (user_id,company_id,id,password,name,status,role,last_accessed_at) "
|
||||
"VALUES (:u,:c,:i,:p,:n,:s,:r,now())"),
|
||||
{"u": uid, "c": cid, "i": login, "p": await GetHashedPW("pw1234"),
|
||||
await c.execute(text("INSERT INTO company.users (user_id,id,password,name,status,role,last_accessed_at) "
|
||||
"VALUES (:u,:i,:p,:n,:s,:r,now())"),
|
||||
{"u": uid, "i": login, "p": await GetHashedPW("pw1234"),
|
||||
"n": "데모", "s": UserStatus.ACTIVE.value, "r": UserRole.OWNER.value})
|
||||
|
||||
from router.router import app
|
||||
|
||||
@@ -41,12 +41,11 @@ async def main():
|
||||
engine = create_async_engine(dsn)
|
||||
|
||||
from router.v1.validator.dependencies import GetHashedPW
|
||||
cid, uid, login = uuid.uuid4(), uuid.uuid4(), f"demo{uuid.uuid4().hex[:6]}"
|
||||
uid, login = uuid.uuid4(), f"demo{uuid.uuid4().hex[:6]}"
|
||||
async with engine.begin() as c:
|
||||
await c.execute(text("INSERT INTO company.companies (company_id,name,status) VALUES (:c,:n,1)"), {"c": cid, "n": "데모대행사"})
|
||||
await c.execute(text("INSERT INTO company.users (user_id,company_id,id,password,name,status,role,last_accessed_at) "
|
||||
"VALUES (:u,:c,:i,:p,:n,:s,:r,now())"),
|
||||
{"u": uid, "c": cid, "i": login, "p": await GetHashedPW("pw1234"),
|
||||
await c.execute(text("INSERT INTO company.users (user_id,id,password,name,status,role,last_accessed_at) "
|
||||
"VALUES (:u,:i,:p,:n,:s,:r,now())"),
|
||||
{"u": uid, "i": login, "p": await GetHashedPW("pw1234"),
|
||||
"n": "데모", "s": UserStatus.ACTIVE.value, "r": UserRole.OWNER.value})
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ import uuid
|
||||
from fastapi import Depends
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import companies, users
|
||||
from common.enums import AuthProvider, CompanyStatus, DBWRType, ErrorType, UserRole, UserStatus
|
||||
from common.database.model.models import users
|
||||
from common.enums import AuthProvider, DBWRType, ErrorType, UserRole, UserStatus
|
||||
from common.logger import LOG
|
||||
from common.models.gmodel import UserInfo
|
||||
from crud.user_crud import IUserCRUD, UserCRUD
|
||||
from router.v1.auth.protocol import (
|
||||
CompanyData,
|
||||
Req_GoogleLogin,
|
||||
Req_Signup,
|
||||
Req_UpdateMe,
|
||||
@@ -71,11 +70,11 @@ class AuthService:
|
||||
|
||||
@staticmethod
|
||||
def _user_info(user: users) -> UserInfo:
|
||||
# uuid → str (JWT json 직렬화 위해). 기능 라우터는 company_id 로 스코프한다.
|
||||
# uuid → str (JWT json 직렬화 위해). 기능 라우터는 user_id 로 스코프한다
|
||||
# — 사업장이 places.owner_user_id 로 이 값에 매여 있다.
|
||||
return UserInfo(
|
||||
user_id=str(user.user_id),
|
||||
id=user.id,
|
||||
company_id=str(user.company_id),
|
||||
role=user.role,
|
||||
)
|
||||
|
||||
@@ -140,26 +139,17 @@ class AuthService:
|
||||
password_hash: str | None,
|
||||
name: str | None,
|
||||
email: str | None,
|
||||
company_name: str,
|
||||
provider: AuthProvider,
|
||||
provider_uid: str | None,
|
||||
) -> tuple[ErrorType, users]:
|
||||
"""회사 1개 + 그 회사의 첫 계정 1개를 한 트랜잭션으로 만든다.
|
||||
"""계정 1개를 만든다.
|
||||
|
||||
★ 가입은 곧 새 테넌트다. users.company_id 가 NOT NULL 이고 모든 도메인(사업장·사이트)이
|
||||
company_id 로 스코프되므로, 회사 없는 계정은 아무것도 만들지 못한다.
|
||||
★ uuid 를 여기서 미리 만든다. 모델 default 는 flush 시점에 적용돼서, 그 전에
|
||||
company.company_id 를 읽으면 None 이다 — 그대로 넣으면 NOT NULL 위반이다."""
|
||||
company_uuid = uuid.uuid4()
|
||||
company = companies(
|
||||
company_id=company_uuid,
|
||||
name=_fit(company_name, 100),
|
||||
email=_fit(email, 255),
|
||||
status=CompanyStatus.ACTIVE.value,
|
||||
)
|
||||
★ 예전엔 가입 한 번이 **회사(테넌트) 하나**를 같이 만들었고 모든 도메인이 그 회사로
|
||||
스코프됐다. 쓰는 사람은 사장님 혼자인데 자기 회사에 소속된 직원이 되는 구조라
|
||||
걷어냈다(2026-09-08) — 이제 사업장이 `places.owner_user_id` 로 이 계정에 직접 매인다.
|
||||
★ uuid 를 여기서 미리 만든다. 모델 default 는 flush 시점에 적용돼서 그 전에 읽으면 None 이다."""
|
||||
user = users(
|
||||
user_id=uuid.uuid4(),
|
||||
company_id=company_uuid,
|
||||
id=login_id,
|
||||
password=password_hash,
|
||||
name=_fit(name, 50),
|
||||
@@ -171,10 +161,7 @@ class AuthService:
|
||||
)
|
||||
err_type = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[users.DBType()],
|
||||
[
|
||||
lambda s: self.user_crud.add_company(s, company),
|
||||
lambda s: self.user_crud.add_user(s, user),
|
||||
],
|
||||
[lambda s: self.user_crud.add_user(s, user)],
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, None
|
||||
@@ -226,7 +213,6 @@ class AuthService:
|
||||
password_hash=await GetHashedPW(req.password),
|
||||
name=name,
|
||||
email=email,
|
||||
company_name=(req.company_name or "").strip() or name or login_id,
|
||||
provider=AuthProvider.LOCAL,
|
||||
provider_uid=None,
|
||||
)
|
||||
@@ -268,13 +254,12 @@ class AuthService:
|
||||
res.result.SetResult(ErrorType.ACCOUNT_PROVIDER_CONFLICT)
|
||||
return res
|
||||
|
||||
# 3) 첫 방문 — 계정과 회사를 만든다.
|
||||
# 3) 첫 방문 — 계정을 만든다.
|
||||
err_type, user = await self._create_account(
|
||||
login_id=_google_login_id(account.sub),
|
||||
password_hash=None,
|
||||
name=account.name or None,
|
||||
email=account.email or None,
|
||||
company_name=account.name or account.email or _google_login_id(account.sub),
|
||||
provider=AuthProvider.GOOGLE,
|
||||
provider_uid=account.sub,
|
||||
)
|
||||
@@ -299,16 +284,6 @@ class AuthService:
|
||||
return res
|
||||
user: users
|
||||
|
||||
# 2) 소속사 조회 (없어도 치명적 아님)
|
||||
company = None
|
||||
c_err, company_row = await DB_SESSION_MNG.execute_lambda(
|
||||
users.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.user_crud.get_company(s, user.company_id),
|
||||
)
|
||||
if c_err == ErrorType.SUCCESS and company_row is not None:
|
||||
company = CompanyData(company_id=str(company_row.company_id), name=company_row.name)
|
||||
|
||||
res.user_id = str(user.user_id)
|
||||
res.id = user.id
|
||||
res.name = user.name
|
||||
@@ -316,7 +291,6 @@ class AuthService:
|
||||
res.contact_number = user.contact_number
|
||||
res.role = UserRole(user.role)
|
||||
res.provider = AuthProvider(user.provider)
|
||||
res.company = company
|
||||
return res
|
||||
|
||||
async def update_me(self, user_info: UserInfo, req: Req_UpdateMe) -> Res_Me:
|
||||
|
||||
@@ -98,18 +98,18 @@ async def _log(site_id, version_id, action: PublishAction, result: PublishResult
|
||||
|
||||
|
||||
async def run_build(job: dict) -> dict:
|
||||
"""BUILD 잡 핸들러. payload: {place_id, company_id, publish?, requested_by?}
|
||||
"""BUILD 잡 핸들러. payload: {place_id, owner_user_id, publish?, requested_by?}
|
||||
|
||||
publish=True 면 게이트를 통과했을 때 바로 발행까지 한다."""
|
||||
payload = job["payload"]
|
||||
place_id = payload["place_id"]
|
||||
company_id = payload["company_id"]
|
||||
owner_user_id = payload["owner_user_id"]
|
||||
want_publish = bool(payload.get("publish"))
|
||||
|
||||
err, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(company_id), uuid.UUID(place_id)),
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(owner_user_id), uuid.UUID(place_id)),
|
||||
)
|
||||
if err != ErrorType.SUCCESS or place is None:
|
||||
raise BuildAborted(f"사업장을 찾을 수 없다: {place_id}")
|
||||
@@ -258,7 +258,7 @@ async def run_build(job: dict) -> dict:
|
||||
result["azure"] = azure_result
|
||||
# ★ 페이지가 실제로 올라간 뒤에 썸네일을 남긴다 — 없는 페이지의 그림을 쇼케이스에 걸지 않는다.
|
||||
# 실패해도 발행은 성공이다(스크린샷이 아니라 대표 사진이라, 없으면 글자 카드로 떨어진다).
|
||||
thumbnail_url = await site_thumbnail.store(slug, snapshot)
|
||||
thumbnail_url = await site_thumbnail.store(slug, snapshot, version_no)
|
||||
if thumbnail_url:
|
||||
result["thumbnail_url"] = thumbnail_url
|
||||
# ★ 정적 파일이 올라간 **뒤에** 통보한다. 먼저 알리면 크롤러가 옛 파일을 가져간다.
|
||||
@@ -305,7 +305,7 @@ async def run_build(job: dict) -> dict:
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: _place_crud.update_place(
|
||||
s, uuid.UUID(company_id), uuid.UUID(place_id), {"status": PlaceStatus.PUBLISHED.value}
|
||||
s, uuid.UUID(owner_user_id), uuid.UUID(place_id), {"status": PlaceStatus.PUBLISHED.value}
|
||||
),
|
||||
)
|
||||
await _log(site.site_id, version.site_version_id, PublishAction.PUBLISH, PublishResult.SUCCESS, None,
|
||||
|
||||
@@ -431,12 +431,12 @@ async def run_collect(job: dict) -> dict:
|
||||
"""COLLECT 잡 핸들러. 반환값이 jobs.result 에 저장돼 폴링·감사에 쓰인다."""
|
||||
payload = job["payload"]
|
||||
place_id = payload["place_id"]
|
||||
company_id = payload["company_id"]
|
||||
owner_user_id = payload["owner_user_id"]
|
||||
|
||||
err, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(company_id), uuid.UUID(place_id)),
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(owner_user_id), uuid.UUID(place_id)),
|
||||
)
|
||||
if err != ErrorType.SUCCESS or place is None:
|
||||
raise CollectAborted(f"사업장을 찾을 수 없다: {place_id}")
|
||||
@@ -464,7 +464,7 @@ async def run_collect(job: dict) -> dict:
|
||||
|
||||
if not targets:
|
||||
result["note"] = "크롤링 대상이 없다(어댑터가 처리할 수 있는 확정 URL 0건)"
|
||||
await _finish(place_id, company_id, PlaceStatus.REVIEW)
|
||||
await _finish(place_id, owner_user_id, PlaceStatus.REVIEW)
|
||||
return result
|
||||
|
||||
# ★ 이미 충분하면 크롤링 자체를 건너뛴다(force 가 아닐 때).
|
||||
@@ -472,16 +472,19 @@ async def run_collect(job: dict) -> dict:
|
||||
if before["enough"] and not payload.get("force"):
|
||||
result["coverage"] = before
|
||||
result["note"] = "이미 필수 항목이 다 차 있다 — 크롤링 생략(force=true 로 강제 가능)"
|
||||
await _finish(place_id, company_id, PlaceStatus.REVIEW)
|
||||
await _finish(place_id, owner_user_id, PlaceStatus.REVIEW)
|
||||
LOG.i(f"[collect] 충분함 place={place_id} {before['covered']}/{before['total']} — 크롤링 생략")
|
||||
return result
|
||||
|
||||
from common.models.gmodel import UserInfo
|
||||
|
||||
actor = UserInfo(
|
||||
user_id=payload.get("requested_by") or str(place.verified_by or uuid.uuid4()),
|
||||
# ★ 잡이 쓰는 신원. user_id 는 **사업장 주인**이어야 한다 — FactService 가 이 값으로
|
||||
# 사업장을 스코프하고(fact_service._load_place) verified_by 에도 그대로 박는다.
|
||||
# 회사를 걷어내기 전에는 스코프가 company_id 였고 여기엔 요청자·검증자·랜덤 uuid 가
|
||||
# 순서대로 들어갔다. 그 랜덤 uuid 가 이제는 "남의 사업장" 이 되어 조회가 0건이 된다.
|
||||
user_id=owner_user_id,
|
||||
id="collector",
|
||||
company_id=company_id,
|
||||
role=1,
|
||||
)
|
||||
|
||||
@@ -538,24 +541,24 @@ async def run_collect(job: dict) -> dict:
|
||||
# 사진이 들어왔으면 분석을 이어서 건다 — 수집과 분석은 각각 몇 분이라 한 잡에 묶지 않는다.
|
||||
# (묶으면 분석에서 죽었을 때 수집까지 다시 하게 되고, 유료 API 를 두 번 태운다.)
|
||||
if result["media"]["stored"] > 0:
|
||||
result["vision_job_id"] = await _enqueue_vision(place_id, company_id)
|
||||
result["vision_job_id"] = await _enqueue_vision(place_id, owner_user_id)
|
||||
|
||||
await _finish(place_id, company_id, PlaceStatus.REVIEW)
|
||||
await _finish(place_id, owner_user_id, PlaceStatus.REVIEW)
|
||||
LOG.i(f"[collect] 완료 place={place_id} fact {result['facts']['stored']}건 · 사진 {result['media']['stored']}장")
|
||||
return result
|
||||
|
||||
|
||||
async def _finish(place_id: str, company_id: str, status: PlaceStatus):
|
||||
async def _finish(place_id: str, owner_user_id: str, status: PlaceStatus):
|
||||
"""수집이 끝나면 사업장을 검수 대기로 돌린다 — 수집값은 전부 후보라 사람이 봐야 한다."""
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: _place_crud.update_place(
|
||||
s, uuid.UUID(company_id), uuid.UUID(place_id), {"status": status.value}
|
||||
s, uuid.UUID(owner_user_id), uuid.UUID(place_id), {"status": status.value}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def _enqueue_vision(place_id: str, company_id: str) -> str | None:
|
||||
async def _enqueue_vision(place_id: str, owner_user_id: str) -> str | None:
|
||||
"""사진 분석 잡을 적재한다. 키가 없거나 중복이면 조용히 건너뛴다(수집 자체는 성공이다)."""
|
||||
from common.enums import JobType
|
||||
from crud.job_crud import JobQueue
|
||||
@@ -567,7 +570,7 @@ async def _enqueue_vision(place_id: str, company_id: str) -> str | None:
|
||||
return None
|
||||
job_id, _created = await enqueue_job(
|
||||
JobQueue(), JobType.VISION,
|
||||
{"place_id": place_id, "company_id": company_id},
|
||||
{"place_id": place_id, "owner_user_id": owner_user_id},
|
||||
dedupe_key=f"vision:{place_id}",
|
||||
)
|
||||
return job_id
|
||||
@@ -40,10 +40,10 @@ class CopyAborted(RuntimeError):
|
||||
|
||||
|
||||
async def run_copy(job: dict) -> dict:
|
||||
"""COPY 잡 핸들러. payload: {place_id, company_id, requested_by?}"""
|
||||
"""COPY 잡 핸들러. payload: {place_id, owner_user_id, requested_by?}"""
|
||||
payload = job["payload"]
|
||||
place_id = payload["place_id"]
|
||||
company_id = payload["company_id"]
|
||||
owner_user_id = payload["owner_user_id"]
|
||||
|
||||
if not gemini_text.is_configured():
|
||||
raise CopyAborted("GEMINI_API_KEY 미설정 — 소개문·FAQ 를 생성할 수 없다")
|
||||
@@ -51,7 +51,7 @@ async def run_copy(job: dict) -> dict:
|
||||
err, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(company_id), uuid.UUID(place_id)),
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(owner_user_id), uuid.UUID(place_id)),
|
||||
)
|
||||
if err != ErrorType.SUCCESS or place is None:
|
||||
raise CopyAborted(f"사업장을 찾을 수 없다: {place_id}")
|
||||
@@ -165,9 +165,12 @@ async def run_copy(job: dict) -> dict:
|
||||
}
|
||||
|
||||
actor = UserInfo(
|
||||
user_id=payload.get("requested_by") or str(place.verified_by or uuid.uuid4()),
|
||||
# ★ 잡이 쓰는 신원. user_id 는 **사업장 주인**이어야 한다 — FactService 가 이 값으로
|
||||
# 사업장을 스코프하고(fact_service._load_place) verified_by 에도 그대로 박는다.
|
||||
# 회사를 걷어내기 전에는 스코프가 company_id 였고 여기엔 요청자·검증자·랜덤 uuid 가
|
||||
# 순서대로 들어갔다. 그 랜덤 uuid 가 이제는 "남의 사업장" 이 되어 조회가 0건이 된다.
|
||||
user_id=owner_user_id,
|
||||
id="generator",
|
||||
company_id=company_id,
|
||||
role=1,
|
||||
)
|
||||
service = FactService(_fact_crud, _place_crud)
|
||||
|
||||
@@ -73,7 +73,7 @@ class FactService:
|
||||
err_type, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.place_crud.get_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)),
|
||||
lambda s: self.place_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
|
||||
|
||||
@@ -38,14 +38,14 @@ class FaqService:
|
||||
self.crud = crud
|
||||
self.place_crud = place_crud
|
||||
|
||||
# ---- 사업장 로드(회사 스코프) ----
|
||||
# ---- 사업장 로드(사장님 스코프) ----
|
||||
async def _load_place(self, user_info: UserInfo, place_id: str):
|
||||
"""company_id 를 WHERE 에 걸어 조회한다 — 남의 회사 place_id 를 넣으면 PLACE_NOT_FOUND.
|
||||
"""owner_user_id 를 WHERE 에 걸어 조회한다 — 남의 place_id 를 넣으면 PLACE_NOT_FOUND.
|
||||
'없다'와 '권한 없다'를 구분해 주지 않는 것도 의도다(존재 여부를 흘리지 않는다)."""
|
||||
err_type, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.place_crud.get_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)),
|
||||
lambda s: self.place_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
|
||||
|
||||
@@ -41,7 +41,7 @@ class MediaService:
|
||||
err_type, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.place_crud.get_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)),
|
||||
lambda s: self.place_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
|
||||
|
||||
@@ -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:
|
||||
@@ -253,7 +256,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:
|
||||
@@ -294,7 +297,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,
|
||||
@@ -325,7 +328,7 @@ class PlaceService:
|
||||
data["external_category"] = req.category_name.strip()[:200]
|
||||
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)
|
||||
@@ -513,7 +516,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 단계가 새로 확정한 네이버 링크가
|
||||
@@ -542,7 +545,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},
|
||||
),
|
||||
)
|
||||
@@ -589,7 +592,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:
|
||||
@@ -849,7 +852,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:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
고르는 자리를 한 곳으로 모았다. 사이트 한 곳을 여는 것과 발행 업소 명단을 통째로
|
||||
긁는 것은 다른 일이라, 페이지에 이미 적혀 있는 것만 나간다.
|
||||
|
||||
나가지 않는 것: place_id · company_id · site_id · 전화번호 · 상세 주소 · 좌표.
|
||||
나가지 않는 것: place_id · 소유자 · site_id · 전화번호 · 상세 주소 · 좌표.
|
||||
"""
|
||||
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
|
||||
@@ -104,7 +104,7 @@ class SiteService:
|
||||
err_type, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.place_crud.get_place(s, uuid.UUID(user_info.company_id), uuid.UUID(place_id)),
|
||||
lambda s: self.place_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
|
||||
@@ -420,16 +420,16 @@ class SiteService:
|
||||
return cleaned
|
||||
|
||||
async def list_my_sites(self, user_info: UserInfo, pg: PageParams) -> Res_MySites:
|
||||
"""로그인한 계정(회사)이 가진 사이트 전부.
|
||||
"""로그인한 사장님이 가진 사이트 전부.
|
||||
|
||||
사업장 목록(/v1/place/list)과 따로 두는 이유: 화면이 알아야 하는 건 '사업장이 있다'가 아니라
|
||||
'발행돼 있나 · 주소가 뭔가 · 다시 구워야 하나'다."""
|
||||
res = Res_MySites(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_company_sites(s, cid, pg.skip, pg.size),
|
||||
lambda s: self.crud.list_owner_sites(s, uid, pg.skip, pg.size),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
@@ -454,6 +454,7 @@ class SiteService:
|
||||
domain=getattr(site, "domain", None),
|
||||
template_id=getattr(site, "template_id", None),
|
||||
published_at=getattr(site, "published_at", None),
|
||||
thumbnail_url=getattr(site, "thumbnail_url", None),
|
||||
needs_rebuild=bool(site is not None and changed and (built_at is None or changed > built_at)),
|
||||
)
|
||||
|
||||
@@ -526,7 +527,7 @@ class SiteService:
|
||||
job_id, created = await enqueue_job(
|
||||
self.queue, JobType.BUILD,
|
||||
{
|
||||
"place_id": place_id, "company_id": user_info.company_id,
|
||||
"place_id": place_id, "owner_user_id": user_info.user_id,
|
||||
"publish": req.publish, "requested_by": user_info.user_id,
|
||||
},
|
||||
dedupe_key=f"build:{place_id}",
|
||||
|
||||
@@ -18,7 +18,7 @@ import asyncio
|
||||
import os
|
||||
|
||||
import httpx
|
||||
from azure.storage.blob import BlobServiceClient, ContentSettings
|
||||
from azure.storage.blob import BlobClient, BlobServiceClient, ContentSettings
|
||||
|
||||
from common.logger import LOG
|
||||
from services import azure_static, site_payload
|
||||
@@ -46,19 +46,71 @@ MAX_BYTES = 5 * 1024 * 1024
|
||||
CACHE_CONTROL = "public, max-age=60, must-revalidate"
|
||||
|
||||
|
||||
# ── 썸네일 전용 저장소 ────────────────────────────────────────────────────────
|
||||
# ★ 왜 스위치를 따로 두나
|
||||
# 원래는 `AZURE_STORAGE_CONNECTION_STRING` 하나가 사이트 업로드(azure_static)와 썸네일을
|
||||
# **같이** 켰다. 그런데 그 둘은 필요한 저장소가 다르다 — 사이트는 정적 호스팅(`$web`)이고
|
||||
# 썸네일은 그냥 이미지 버킷이면 된다. 하나로 묶어 두면 "썸네일 좀 보자" 고 키를 꽂는 순간
|
||||
# **발행할 때마다 사이트 전체가 그 버킷에 업로드된다.** 지금 우리가 빌려 쓰는 곳은
|
||||
# negodata·infinith 와 공용인 미디어 컨테이너라 그렇게 되면 안 된다.
|
||||
#
|
||||
# ★ 값 출처: o2o-negosium/negodata/backend/config/config.local.toml `[StorageConfig]`.
|
||||
# 같은 계정/컨테이너를 root 디렉터리로만 가른다(negodata/ · infinith/ · web4ai/) —
|
||||
# 그쪽 관례를 그대로 따른 것이지 우리 계정이 아니다.
|
||||
#
|
||||
# ⚠️ **임시다.** 이 컨테이너는 정적 사이트 호스팅이 아니라 발행본을 못 올린다. 그리고 SAS 가
|
||||
# 컨테이너 전체에 racwdl(삭제 포함)이라, 남의 프로젝트 파일에 닿을 수 있는 자리다 —
|
||||
# web4ai 전용 스토리지 계정이 생기면 이 블록을 걷고 azure_static 쪽으로 되돌린다.
|
||||
_BASE_ENV = "THUMBNAIL_BLOB_BASE_URL" # https://<계정>.blob.core.windows.net/<컨테이너>
|
||||
_SAS_ENV = "THUMBNAIL_BLOB_SAS_TOKEN" # `?sv=...` (앞의 물음표는 있어도 없어도 된다)
|
||||
_ROOT_ENV = "THUMBNAIL_BLOB_ROOT" # 컨테이너 안에서 우리가 쓰는 디렉터리. 예: web4ai
|
||||
|
||||
|
||||
def _blob_base() -> str:
|
||||
return os.environ.get(_BASE_ENV, "").strip().rstrip("/")
|
||||
|
||||
|
||||
def _blob_sas() -> str:
|
||||
return os.environ.get(_SAS_ENV, "").strip().lstrip("?")
|
||||
|
||||
|
||||
def _blob_root() -> str:
|
||||
return os.environ.get(_ROOT_ENV, "").strip().strip("/")
|
||||
|
||||
|
||||
def uses_blob_store() -> bool:
|
||||
"""썸네일 전용 저장소를 쓰는가. 아니면 예전대로 azure_static 설정을 따른다."""
|
||||
return bool(_blob_base() and _blob_sas())
|
||||
|
||||
|
||||
def is_configured() -> bool:
|
||||
return azure_static.is_configured()
|
||||
return uses_blob_store() or azure_static.is_configured()
|
||||
|
||||
|
||||
def blob_name(slug: str, ext: str) -> str:
|
||||
if uses_blob_store():
|
||||
# base_url 에 컨테이너까지 들어 있다 — 여기서는 컨테이너 안쪽 경로만 만든다.
|
||||
return "/".join(part for part in (_blob_root(), THUMB_DIR, f"{slug}.{ext}") if part)
|
||||
prefix = os.environ.get("AZURE_STORAGE_PREFIX", azure_static.DEFAULT_PREFIX).strip().strip("/")
|
||||
return "/".join(part for part in (prefix, THUMB_DIR, f"{slug}.{ext}") if part)
|
||||
|
||||
|
||||
def public_url(slug: str, ext: str) -> str:
|
||||
def public_url(slug: str, ext: str, version: int | None = None) -> str:
|
||||
"""공개 주소. 발행 사이트와 같은 오리진이다 — 접두사는 오리진 경로로 흡수된다
|
||||
(CLAUDE.md 'AZURE_STORAGE_PREFIX 와 루트 절대경로는 충돌한다')."""
|
||||
return f"{site_payload.publish_origin()}/{THUMB_DIR}/{slug}.{ext}"
|
||||
(CLAUDE.md 'AZURE_STORAGE_PREFIX 와 루트 절대경로는 충돌한다').
|
||||
|
||||
★ `?v=<버전>` 은 캐시 무효화다. 블롭 이름은 발행마다 그대로고 내용만 덮어쓰므로
|
||||
(overwrite=True), 주소가 안 변하면 브라우저·CDN 이 **옛 그림을 계속 보여준다.**
|
||||
아래 CACHE_CONTROL(60초)만으로는 부족하다 — 그 60초 동안 사장님은 방금 바꾼 사진이
|
||||
아니라 지난 발행의 사진을 본다. 버전을 붙이면 발행 즉시 새 주소가 된다.
|
||||
★ 이름에 버전을 넣지 않는 이유: 사이트당 블롭이 발행 횟수만큼 쌓이고, 지우는 코드가 없다.
|
||||
★ version 이 None 이면 붙이지 않는다 — 옛 발행분을 사후에 채우는 경로
|
||||
(scripts/backfill_thumbnails.py)에는 그 시점의 버전이 없다."""
|
||||
# ★ 저장소가 발행 오리진 밖이면 주소도 그쪽이다. 여기서 publish_origin 을 쓰면
|
||||
# 그림은 블롭에 올라가 있는데 카드는 우리 사이트 주소를 가리켜 전부 404 다.
|
||||
base = f"{_blob_base()}/{blob_name(slug, ext)}" if uses_blob_store() \
|
||||
else f"{site_payload.publish_origin()}/{THUMB_DIR}/{slug}.{ext}"
|
||||
return f"{base}?v={version}" if version is not None else base
|
||||
|
||||
|
||||
async def _fetch(url: str) -> tuple[bytes, str, str] | None:
|
||||
@@ -109,6 +161,18 @@ async def _fetch(url: str) -> tuple[bytes, str, str] | None:
|
||||
|
||||
|
||||
def _upload_sync(slug: str, data: bytes, content_type: str, ext: str) -> str:
|
||||
name = blob_name(slug, ext)
|
||||
settings = ContentSettings(content_type=content_type, cache_control=CACHE_CONTROL)
|
||||
|
||||
if uses_blob_store():
|
||||
# ★ SAS 는 연결 문자열이 아니다 — from_connection_string 이 못 받는다.
|
||||
# 블롭 주소에 토큰을 붙여 그 한 파일에만 붙는다(컨테이너 클라이언트를 만들지 않는다:
|
||||
# 남의 디렉터리를 훑을 수 있는 핸들을 굳이 들고 있지 않는다).
|
||||
BlobClient.from_blob_url(f"{_blob_base()}/{name}?{_blob_sas()}").upload_blob(
|
||||
data, overwrite=True, content_settings=settings
|
||||
)
|
||||
return name
|
||||
|
||||
connection_string = os.environ["AZURE_STORAGE_CONNECTION_STRING"].strip()
|
||||
container_name = (
|
||||
os.environ.get("AZURE_STORAGE_CONTAINER", azure_static.DEFAULT_CONTAINER).strip()
|
||||
@@ -116,18 +180,12 @@ def _upload_sync(slug: str, data: bytes, content_type: str, ext: str) -> str:
|
||||
)
|
||||
service = BlobServiceClient.from_connection_string(connection_string)
|
||||
container = service.get_container_client(container_name)
|
||||
name = blob_name(slug, ext)
|
||||
container.upload_blob(
|
||||
name=name,
|
||||
data=data,
|
||||
overwrite=True,
|
||||
# cache_control 은 ContentSettings 에 담아야 블롭 속성으로 실제로 박힌다.
|
||||
content_settings=ContentSettings(content_type=content_type, cache_control=CACHE_CONTROL),
|
||||
)
|
||||
# cache_control 은 ContentSettings 에 담아야 블롭 속성으로 실제로 박힌다.
|
||||
container.upload_blob(name=name, data=data, overwrite=True, content_settings=settings)
|
||||
return name
|
||||
|
||||
|
||||
async def store(slug: str, snapshot: dict) -> str | None:
|
||||
async def store(slug: str, snapshot: dict, version: int | None = None) -> str | None:
|
||||
"""대표 사진을 썸네일로 올리고 공개 URL 을 돌려준다. 못 하면 None(발행은 그대로 간다).
|
||||
|
||||
SDK 의 동기 I/O 는 별도 스레드에서 돈다 — azure_static.publish 와 같은 이유로,
|
||||
@@ -153,4 +211,4 @@ async def store(slug: str, snapshot: dict) -> str | None:
|
||||
return None
|
||||
|
||||
LOG.i(f"[thumbnail] {slug} → {name} ({len(data)} bytes · {content_type})")
|
||||
return public_url(slug, ext)
|
||||
return public_url(slug, ext, version)
|
||||
@@ -28,10 +28,10 @@ class VisionAborted(RuntimeError):
|
||||
|
||||
|
||||
async def run_vision(job: dict) -> dict:
|
||||
"""VISION 잡 핸들러. payload: {place_id, company_id, force?}"""
|
||||
"""VISION 잡 핸들러. payload: {place_id, owner_user_id, force?}"""
|
||||
payload = job["payload"]
|
||||
place_id = payload["place_id"]
|
||||
company_id = payload["company_id"]
|
||||
owner_user_id = payload["owner_user_id"]
|
||||
force = bool(payload.get("force"))
|
||||
|
||||
if not gemini.is_configured():
|
||||
@@ -40,7 +40,7 @@ async def run_vision(job: dict) -> dict:
|
||||
err, place = await DB_SESSION_MNG.execute_lambda(
|
||||
places.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(company_id), uuid.UUID(place_id)),
|
||||
lambda s: _place_crud.get_place(s, uuid.UUID(owner_user_id), uuid.UUID(place_id)),
|
||||
)
|
||||
if err != ErrorType.SUCCESS or place is None:
|
||||
raise VisionAborted(f"사업장을 찾을 수 없다: {place_id}")
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
"""
|
||||
|
||||
|
||||
async def test_login_and_me_flow(auth_headers, client, company_id):
|
||||
async def test_login_and_me_flow(auth_headers, client):
|
||||
"""검증: 시드된 유저가 로그인해 받은 토큰으로 /me 호출.
|
||||
기대결과: 200, 본인 id·name·소속사(company_id)가 그대로 반환."""
|
||||
기대결과: 200, 본인 id·name 이 그대로 반환."""
|
||||
h = await auth_headers("user1", name="홍길동")
|
||||
|
||||
r = await client.get("/v1/auth/me", headers=h)
|
||||
@@ -14,7 +14,8 @@ async def test_login_and_me_flow(auth_headers, client, company_id):
|
||||
me = r.json()
|
||||
assert me["id"] == "user1"
|
||||
assert me["name"] == "홍길동"
|
||||
assert me["company"]["company_id"] == company_id
|
||||
# ★ 소속사 필드는 없다. 회사(테넌트)를 걷어냈다(2026-09-08) — 쓰는 사람은 사장님 혼자다.
|
||||
assert "company" not in me
|
||||
|
||||
|
||||
async def test_login_with_wrong_password(auth_headers, client):
|
||||
@@ -49,7 +50,7 @@ _SIGNUP = {"id": "sajang1", "password": "pw12345678", "name": "김사장", "emai
|
||||
|
||||
async def test_signup_creates_account_and_logs_in(client, db_engine):
|
||||
"""검증: 가입 → 받은 토큰으로 곧바로 /me.
|
||||
기대결과: 토큰이 실려 오고, /me 가 방금 만든 신원과 **새로 생긴 소속사**를 돌려준다."""
|
||||
기대결과: 토큰이 실려 오고, /me 가 방금 만든 신원을 돌려준다."""
|
||||
r = await client.post("/v1/auth/signup", json=_SIGNUP)
|
||||
body = r.json()
|
||||
assert body["result"]["success"] is True
|
||||
@@ -59,7 +60,6 @@ async def test_signup_creates_account_and_logs_in(client, db_engine):
|
||||
assert me["id"] == "sajang1"
|
||||
assert me["email"] == "boss@example.com"
|
||||
assert me["provider"] == 1 # AuthProvider.LOCAL
|
||||
assert me["company"]["name"] == "김사장" # 회사명 미입력 → 이름으로 채운다
|
||||
|
||||
|
||||
async def test_signup_rejects_duplicate_id(client, db_engine):
|
||||
|
||||
@@ -264,12 +264,12 @@ async def test_versions_accumulate(auth_headers, client, db_engine):
|
||||
assert [v["version"] for v in versions] == [2, 1]
|
||||
|
||||
|
||||
async def test_site_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사이트를 본다.
|
||||
async def test_site_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사이트를 본다.
|
||||
기대결과: PLACE_NOT_FOUND."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _place(client, h1, "스코프펜션")
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.get(f"/v1/place/{pid}/site", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
@@ -156,13 +156,13 @@ async def test_targeted_collect_payload_carries_requested_confirmed_link(auth_he
|
||||
assert job["payload"]["link_ids"] == [confirmed]
|
||||
|
||||
|
||||
async def test_collect_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 수집을 시작한다.
|
||||
async def test_collect_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장 수집을 시작한다.
|
||||
기대결과: PLACE_NOT_FOUND — 사업장이 안 보이니 수집도 못 건다."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _place(client, h1, kakao="c7")
|
||||
await _confirmed_link(client, h1, pid)
|
||||
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.post(f"/v1/place/{pid}/collect", headers=h2, json={})
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
@@ -208,7 +208,7 @@ async def test_recollect_cannot_overwrite_corrected_value(auth_headers, client):
|
||||
assert check_in[0]["status"] == FactStatus.CORRECTED.value
|
||||
|
||||
|
||||
async def test_pipeline_refuses_unverified_place(db_engine, company_id):
|
||||
async def test_pipeline_refuses_unverified_place(db_engine, owner_id):
|
||||
"""검증: 검증 안 된 사업장의 수집 잡이 큐에 직접 들어간 경우(잡 적재 후 검증이 취소된 상황).
|
||||
기대결과: 잡이 실패한다 — ★ 잡 실행 시점에도 게이트를 다시 확인한다."""
|
||||
from sqlalchemy import text
|
||||
@@ -216,13 +216,13 @@ async def test_pipeline_refuses_unverified_place(db_engine, company_id):
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text("INSERT INTO places (place_id, company_id, name, category, status) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status) "
|
||||
"VALUES (:pid, :cid, :n, 1, 1)"),
|
||||
{"pid": pid, "cid": uuid.UUID(company_id), "n": "미검증펜션"},
|
||||
{"pid": pid, "cid": uuid.UUID(owner_id), "n": "미검증펜션"},
|
||||
)
|
||||
|
||||
q = JobQueue()
|
||||
job_id = await q.enqueue(JobType.COLLECT.value, {"place_id": str(pid), "company_id": company_id}, max_attempts=1)
|
||||
job_id = await q.enqueue(JobType.COLLECT.value, {"place_id": str(pid), "owner_user_id": owner_id}, max_attempts=1)
|
||||
worker = Worker("test-worker", q, build_handler(), backoff_fn=lambda _a: 0)
|
||||
await worker.process_one()
|
||||
|
||||
|
||||
@@ -269,12 +269,12 @@ async def test_crawl_only_does_not_mark_rebuild(auth_headers, client):
|
||||
assert place.get("content_updated_at") is None
|
||||
|
||||
|
||||
async def test_facts_are_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 fact 를 조회한다.
|
||||
async def test_facts_are_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장 fact 를 조회한다.
|
||||
기대결과: PLACE_NOT_FOUND — 사업장이 안 보이니 fact 도 안 보인다."""
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _verified_place(client, h1, kakao="p6")
|
||||
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
r = await client.get(f"/v1/place/{pid}/fact/list", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
@@ -22,17 +22,17 @@ from common.enums import (
|
||||
)
|
||||
|
||||
|
||||
async def _seed_place(db_engine, company_id) -> str:
|
||||
async def _seed_place(db_engine, owner_id) -> str:
|
||||
"""검증까지 끝난 사업장 1개를 시드하고 place_id 를 돌려준다."""
|
||||
pid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text(
|
||||
"INSERT INTO places (place_id, company_id, name, category, status, external_place_id, verified_at) "
|
||||
"INSERT INTO places (place_id, owner_user_id, name, category, status, external_place_id, verified_at) "
|
||||
"VALUES (:pid, :cid, :name, :cat, :status, :kakao, now())"
|
||||
),
|
||||
{
|
||||
"pid": pid, "cid": uuid.UUID(company_id), "name": "테스트펜션",
|
||||
"pid": pid, "cid": uuid.UUID(owner_id), "name": "테스트펜션",
|
||||
"cat": PlaceCategory.LODGING.value, "status": PlaceStatus.DRAFT.value,
|
||||
"kakao": "12345678",
|
||||
},
|
||||
@@ -54,20 +54,20 @@ async def _insert_fact(db_engine, place_id, key, value, status, unit_id=None):
|
||||
)
|
||||
|
||||
|
||||
async def test_published_fact_is_unique_per_place_and_key(db_engine, company_id):
|
||||
async def test_published_fact_is_unique_per_place_and_key(db_engine, owner_id):
|
||||
"""검증: 같은 사업장·같은 key 로 노출 상태 fact 를 두 번 넣는다.
|
||||
기대결과: 두 번째 INSERT 가 유니크 인덱스에 막힌다(체크인 시간이 두 값으로 갈라지지 않는다)."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.CORRECTED)
|
||||
|
||||
|
||||
async def test_candidates_coexist_with_published_value(db_engine, company_id):
|
||||
async def test_candidates_coexist_with_published_value(db_engine, owner_id):
|
||||
"""검증: 노출값이 있는 상태에서 재수집 후보를 여러 건 넣는다.
|
||||
기대결과: 전부 공존한다 — ★ 재수집이 노출 중인 사실을 밀어내지 않는다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.VERIFIED)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.PENDING_OWNER)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "14:00", FactStatus.UNVERIFIED)
|
||||
@@ -80,10 +80,10 @@ async def test_candidates_coexist_with_published_value(db_engine, company_id):
|
||||
assert len(rows) == 3, "노출값 1건 + 후보 2건이 공존해야 한다"
|
||||
|
||||
|
||||
async def test_rejected_fact_frees_the_key(db_engine, company_id):
|
||||
async def test_rejected_fact_frees_the_key(db_engine, owner_id):
|
||||
"""검증: 기존 값을 REJECTED 로 내린 뒤 같은 key 를 새로 노출한다.
|
||||
기대결과: 통과 — 틀린 값은 이력으로 남고, 새 값이 노출 자리를 차지한다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "15:00", FactStatus.REJECTED)
|
||||
await _insert_fact(db_engine, place_id, "check_in_time", "16:00", FactStatus.VERIFIED)
|
||||
|
||||
@@ -95,18 +95,18 @@ async def test_rejected_fact_frees_the_key(db_engine, company_id):
|
||||
assert len(rows) == 2, "REJECTED 이력과 새 값이 함께 남아야 한다"
|
||||
|
||||
|
||||
async def test_expired_fact_frees_the_key(db_engine, company_id):
|
||||
async def test_expired_fact_frees_the_key(db_engine, owner_id):
|
||||
"""검증: 유효기간이 지나 EXPIRED 로 내린 값과 새 수집값의 공존.
|
||||
기대결과: 통과 — EXPIRED 도 유니크에서 빠진다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
await _insert_fact(db_engine, place_id, "cancel_policy", "구 규정", FactStatus.EXPIRED)
|
||||
await _insert_fact(db_engine, place_id, "cancel_policy", "새 규정", FactStatus.VERIFIED)
|
||||
|
||||
|
||||
async def test_same_key_allowed_across_units(db_engine, company_id):
|
||||
async def test_same_key_allowed_across_units(db_engine, owner_id):
|
||||
"""검증: 객실이 다르면 같은 key 를 각각 가질 수 있는지.
|
||||
기대결과: 통과 — A동·B동이 각자의 기준 인원을 갖는다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
unit_a, unit_b = uuid.uuid4(), uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
for uid, name in ((unit_a, "A동"), (unit_b, "B동")):
|
||||
@@ -122,10 +122,10 @@ async def test_same_key_allowed_across_units(db_engine, company_id):
|
||||
await _insert_fact(db_engine, place_id, "standard_capacity", "6", FactStatus.CORRECTED, unit_id=unit_a)
|
||||
|
||||
|
||||
async def test_unit_fact_and_place_fact_are_separate(db_engine, company_id):
|
||||
async def test_unit_fact_and_place_fact_are_separate(db_engine, owner_id):
|
||||
"""검증: 같은 key 를 사업장 단위와 객실 단위로 동시에 갖는 경우.
|
||||
기대결과: 통과 — 부분 인덱스가 unit_id NULL 여부로 갈라져 있다."""
|
||||
place_id = await _seed_place(db_engine, company_id)
|
||||
place_id = await _seed_place(db_engine, owner_id)
|
||||
unit_id = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
|
||||
@@ -56,14 +56,14 @@ async def test_generated_faq_is_pending_and_not_publishable(auth_headers, client
|
||||
assert (await _list(client, h, pid, publishable_only=True)).get("faqs", []) == []
|
||||
|
||||
|
||||
async def test_other_company_cannot_read_or_touch_faq(auth_headers, client, db_engine, other_company_id):
|
||||
"""검증: 남의 회사 사용자가 place_id 를 알아내 FAQ 를 조회·전이한다.
|
||||
async def test_other_owner_cannot_read_or_touch_faq(auth_headers, client, db_engine):
|
||||
"""검증: 남의 사용자가 place_id 를 알아내 FAQ 를 조회·전이한다.
|
||||
기대결과: PLACE_NOT_FOUND — 존재 여부조차 알려주지 않는다."""
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place(client, h)
|
||||
fid = await _seed_generated_faq(db_engine, pid)
|
||||
|
||||
other = await auth_headers("u2", other_company_id)
|
||||
other = await auth_headers("u2")
|
||||
assert (await _list(client, other, pid))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
body = await _transition(client, other, pid, fid, {"status": FactStatus.VERIFIED.value})
|
||||
assert body["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
이 경로가 절대 하면 안 되는 것:
|
||||
- 사이트가 아직 없는 사업장을 빼는 것 — 위저드를 걸어오다 만 가게가 목록에서 사라지면
|
||||
사장님은 그걸 다시 찾을 길이 없다(에디터 주소를 아무도 기억하지 않는다).
|
||||
- 회사 스코프를 놓치는 것 — 남의 가게가 내 목록에 섞이면 그건 목록이 아니라 사고다.
|
||||
- 사장님 스코프를 놓치는 것 — 남의 가게가 내 목록에 섞이면 그건 목록이 아니라 사고다.
|
||||
- 단건(GET /v1/place/{id}/site)과 다른 재빌드 판정을 내는 것 — 목록과 에디터가 서로 다른
|
||||
답을 하면 사장님은 어느 쪽을 믿을지 알 수 없다.
|
||||
"""
|
||||
@@ -53,11 +53,47 @@ async def test_site_row_is_joined_into_the_line(auth_headers, client):
|
||||
assert row["status"] == SiteStatus.DRAFT.value
|
||||
|
||||
|
||||
async def test_other_company_sites_are_not_listed(auth_headers, client, other_company_id):
|
||||
"""검증: 회사(테넌트) 스코프. 남의 회사 사업장은 보이지 않는다.
|
||||
async def test_row_carries_what_the_card_draws(auth_headers, client, db_engine):
|
||||
"""검증: 목록 줄이 카드가 그릴 값을 다 들고 온다 — 주소·생성일·썸네일.
|
||||
|
||||
★ 왜 이걸 본다: 같은 상호로 만든 사업장이 여러 줄일 때(실측: 한 계정에 '버터브루' 4줄)
|
||||
이름과 상태 배지만으로는 어느 게 어느 건지 가릴 수 없다. 가르는 값은 주소와 시각이고,
|
||||
**한 번이라도 발행한 줄은 그림**이다."""
|
||||
h = await auth_headers("my2b")
|
||||
pid = await _place(client, h, "카드펜션")
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text("UPDATE places SET road_address = :addr WHERE place_id = :pid"),
|
||||
{"addr": "강원특별자치도 양양군 현북면 하조대3길 12", "pid": uuid.UUID(pid)},
|
||||
)
|
||||
await conn.execute(
|
||||
text("INSERT INTO sites (site_id, place_id, domain, status, thumbnail_url) "
|
||||
"VALUES (:s, :p, :d, :st, :t)"),
|
||||
{"s": uuid.uuid4(), "p": uuid.UUID(pid), "d": "card-stay",
|
||||
"st": SiteStatus.PUBLISHED.value, "t": "https://w4ai.o2o.kr/thumbs/card-stay.jpg?v=2"},
|
||||
)
|
||||
|
||||
row = (await _list(client, h))["sites"][0]
|
||||
assert row["road_address"] == "강원특별자치도 양양군 현북면 하조대3길 12"
|
||||
assert row["created_at"]
|
||||
assert row["thumbnail_url"] == "https://w4ai.o2o.kr/thumbs/card-stay.jpg?v=2"
|
||||
|
||||
|
||||
async def test_row_without_a_site_has_no_thumbnail(auth_headers, client):
|
||||
"""검증: 아직 발행 안 한 줄은 그림이 없다(키 자체가 없다).
|
||||
기대결과: 화면이 '그림 없음' 자리를 그릴 근거가 된다 — 빈 문자열로 오면 깨진 이미지가 뜬다."""
|
||||
h = await auth_headers("my2c")
|
||||
await _place(client, h, "그림없는펜션")
|
||||
|
||||
row = (await _list(client, h))["sites"][0]
|
||||
assert "thumbnail_url" not in row
|
||||
|
||||
|
||||
async def test_other_owners_sites_are_not_listed(auth_headers, client):
|
||||
"""검증: 사장님 스코프. 남의 사업장은 보이지 않는다.
|
||||
기대결과: 각자 자기 것만 1건."""
|
||||
mine = await auth_headers("my3")
|
||||
theirs = await auth_headers("my3b", other_company_id)
|
||||
theirs = await auth_headers("my3b")
|
||||
await _place(client, mine, "내펜션")
|
||||
await _place(client, theirs, "남의펜션")
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""places 도메인 e2e — 등록 / 동일 업소 검증 / 회사 스코프 / 채널 URL 확정 게이트.
|
||||
"""places 도메인 e2e — 등록 / 동일 업소 검증 / 사장님 스코프 / 채널 URL 확정 게이트.
|
||||
|
||||
★ 이 도메인의 핵심 규칙 두 개를 고정한다:
|
||||
1. 검증(verify) 전에는 채널 URL 을 확정할 수 없다 → 크롤링이 안 열린다
|
||||
2. 남의 회사 사업장은 '없음'으로 보인다
|
||||
2. 남의 사업장은 '없음'으로 보인다
|
||||
"""
|
||||
import uuid
|
||||
|
||||
@@ -61,7 +61,7 @@ async def test_verify_place_opens_collection(auth_headers, client):
|
||||
|
||||
|
||||
async def test_duplicate_kakao_place_is_allowed(auth_headers, client):
|
||||
"""검증: 같은 회사에서 같은 카카오 장소를 두 사업장에 붙인다.
|
||||
"""검증: 같은 사장님이 같은 카카오 장소를 두 사업장에 붙인다.
|
||||
기대결과: 둘 다 등록된다 — 한 사용자가 같은 실제 업장으로 여러 프로젝트를 만들 수 있다."""
|
||||
h = await auth_headers("u1")
|
||||
first = (await _create_place(client, h, "A펜션"))["place"]["place_id"]
|
||||
@@ -138,13 +138,13 @@ async def test_verify_without_any_identifier_is_rejected(auth_headers, client):
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_VERIFY_NO_CANDIDATE.value
|
||||
|
||||
|
||||
async def test_place_is_scoped_to_company(auth_headers, client, other_company_id):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장을 조회한다.
|
||||
async def test_place_is_scoped_to_owner(auth_headers, client):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장을 조회한다.
|
||||
기대결과: PLACE_NOT_FOUND — 존재 자체가 보이지 않는다(IDOR 차단)."""
|
||||
h1 = await auth_headers("owner1")
|
||||
pid = (await _create_place(client, h1))["place"]["place_id"]
|
||||
|
||||
h2 = await auth_headers("owner2", other_company_id)
|
||||
h2 = await auth_headers("owner2")
|
||||
r = await client.get(f"/v1/place/{pid}", headers=h2)
|
||||
assert r.json()["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ async def test_search_leaks_nothing_of_ours(client, monkeypatch):
|
||||
|
||||
item = (await client.get("/v1/place/search", params={"q": "하조대펜션"})).json()["items"][0]
|
||||
|
||||
for leaked in ("place_id", "company_id", "owner_user_id", "phone", "latitude", "longitude",
|
||||
for leaked in ("place_id", "owner_user_id", "phone", "latitude", "longitude",
|
||||
"external_place_id", "address"):
|
||||
assert leaked not in item, f"{leaked} 가 공개 응답에 나갔다"
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_empty_site_returns_actionable_failures():
|
||||
assert any(c["status"] == "fail" and c["recommendation"] for c in report["checks"])
|
||||
|
||||
|
||||
async def test_audit_api_is_company_scoped(auth_headers, client, other_company_id):
|
||||
async def test_audit_api_is_owner_scoped(auth_headers, client):
|
||||
h1 = await auth_headers("audit-owner")
|
||||
pid = (await client.post("/v1/place", headers=h1, json={"name": "진단가게", "category": 2})).json()["place"]["place_id"]
|
||||
|
||||
@@ -41,6 +41,6 @@ async def test_audit_api_is_company_scoped(auth_headers, client, other_company_i
|
||||
assert 0 <= own["aeo_score"] <= 100
|
||||
assert own["checks"]
|
||||
|
||||
h2 = await auth_headers("audit-other", other_company_id)
|
||||
h2 = await auth_headers("audit-other")
|
||||
denied = (await client.get(f"/v1/place/{pid}/site/audit", headers=h2)).json()
|
||||
assert denied["result"]["success"] is False
|
||||
@@ -13,14 +13,14 @@ from sqlalchemy import text
|
||||
from common.enums import PlaceCategory, PlaceStatus, SiteStatus
|
||||
|
||||
|
||||
async def _publish(db_engine, company_id, name, *, status, domain, thumb=None, minutes_ago=0):
|
||||
async def _publish(db_engine, owner_id, name, *, status, domain, thumb=None, minutes_ago=0):
|
||||
"""places + sites 를 직접 넣는다 — 여기서 보는 건 목록 조회지 빌드 파이프라인이 아니다."""
|
||||
pid, sid = uuid.uuid4(), 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, address, phone) "
|
||||
text("INSERT INTO places (place_id, owner_user_id, name, category, status, road_address, address, phone) "
|
||||
"VALUES (:p,:c,:n,:cat,:st,:road,:addr,:phone)"),
|
||||
{"p": pid, "c": uuid.UUID(company_id), "n": name, "cat": PlaceCategory.LODGING.value,
|
||||
{"p": pid, "c": uuid.UUID(owner_id), "n": name, "cat": PlaceCategory.LODGING.value,
|
||||
"st": PlaceStatus.PUBLISHED.value,
|
||||
"road": "강원특별자치도 양양군 현북면 하조대3길 12-3", "addr": "강원특별자치도 양양군 현북면 하광정리 1-2",
|
||||
"phone": "033-672-0000"},
|
||||
@@ -34,12 +34,12 @@ async def _publish(db_engine, company_id, name, *, status, domain, thumb=None, m
|
||||
return str(pid)
|
||||
|
||||
|
||||
async def test_발행된_사이트만_로그인_없이_보인다(client, db_engine, company_id):
|
||||
async def test_발행된_사이트만_로그인_없이_보인다(client, db_engine, owner_id):
|
||||
"""검증: 발행본 1개 + 미발행(DRAFT) 1개를 두고 인증 헤더 없이 부른다.
|
||||
기대결과: 발행본만 나온다."""
|
||||
await _publish(db_engine, company_id, "하조대펜션", status=SiteStatus.PUBLISHED.value,
|
||||
await _publish(db_engine, owner_id, "하조대펜션", status=SiteStatus.PUBLISHED.value,
|
||||
domain="hajodae", thumb="https://w4ai.o2o.kr/thumbs/hajodae.jpg")
|
||||
await _publish(db_engine, company_id, "아직펜션", status=SiteStatus.DRAFT.value, domain="notyet")
|
||||
await _publish(db_engine, owner_id, "아직펜션", status=SiteStatus.DRAFT.value, domain="notyet")
|
||||
|
||||
res = await client.get("/v1/showcase")
|
||||
|
||||
@@ -51,10 +51,10 @@ async def test_발행된_사이트만_로그인_없이_보인다(client, db_engi
|
||||
assert items[0]["category"] == PlaceCategory.LODGING.value
|
||||
|
||||
|
||||
async def test_개인정보와_내부값은_나가지_않는다(client, db_engine, company_id):
|
||||
async def test_개인정보와_내부값은_나가지_않는다(client, db_engine, owner_id):
|
||||
"""검증: 응답 항목의 키를 그대로 본다.
|
||||
기대결과: 상호명·업종·지역·주소·썸네일뿐. 지역은 시·군까지고 상세 주소는 없다."""
|
||||
await _publish(db_engine, company_id, "하조대펜션", status=SiteStatus.PUBLISHED.value, domain="hajodae")
|
||||
await _publish(db_engine, owner_id, "하조대펜션", status=SiteStatus.PUBLISHED.value, domain="hajodae")
|
||||
|
||||
item = (await client.get("/v1/showcase")).json()["items"][0]
|
||||
|
||||
@@ -66,10 +66,10 @@ async def test_개인정보와_내부값은_나가지_않는다(client, db_engin
|
||||
assert "하조대3길" not in body
|
||||
|
||||
|
||||
async def test_썸네일이_없으면_키가_없다(client, db_engine, company_id):
|
||||
async def test_썸네일이_없으면_키가_없다(client, db_engine, owner_id):
|
||||
"""★ 썸네일은 발행의 부수 효과라 실패할 수 있다(대표 사진이 없거나 CDN 이 죽었거나).
|
||||
그때 카드는 글자로 떨어져야지 목록에서 사라지면 안 된다."""
|
||||
await _publish(db_engine, company_id, "그림없는집", status=SiteStatus.PUBLISHED.value, domain="nopic")
|
||||
await _publish(db_engine, owner_id, "그림없는집", status=SiteStatus.PUBLISHED.value, domain="nopic")
|
||||
|
||||
item = (await client.get("/v1/showcase")).json()["items"][0]
|
||||
|
||||
@@ -77,9 +77,9 @@ async def test_썸네일이_없으면_키가_없다(client, db_engine, company_i
|
||||
assert "thumbnail_url" not in item
|
||||
|
||||
|
||||
async def test_최신_발행순이고_limit_로_자른다(client, db_engine, company_id):
|
||||
await _publish(db_engine, company_id, "먼저", status=SiteStatus.PUBLISHED.value, domain="first", minutes_ago=60)
|
||||
await _publish(db_engine, company_id, "나중", status=SiteStatus.PUBLISHED.value, domain="second", minutes_ago=1)
|
||||
async def test_최신_발행순이고_limit_로_자른다(client, db_engine, owner_id):
|
||||
await _publish(db_engine, owner_id, "먼저", status=SiteStatus.PUBLISHED.value, domain="first", minutes_ago=60)
|
||||
await _publish(db_engine, owner_id, "나중", status=SiteStatus.PUBLISHED.value, domain="second", minutes_ago=1)
|
||||
|
||||
items = (await client.get("/v1/showcase")).json()["items"]
|
||||
assert [i["name"] for i in items] == ["나중", "먼저"]
|
||||
|
||||
@@ -129,11 +129,11 @@ async def test_published_site_slug_is_locked(auth_headers, client, db_engine):
|
||||
assert same["site"]["domain"] == "published-stay"
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장 주소는 확인도 예약도 못 한다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장 주소는 확인도 예약도 못 한다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("slug5")
|
||||
intruder = await auth_headers("slug6", other_company_id)
|
||||
intruder = await auth_headers("slug6")
|
||||
pid = await _place(client, h)
|
||||
|
||||
assert (await _check(client, intruder, pid, "doflo"))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -99,11 +99,11 @@ async def test_published_site_template_is_not_locked(auth_headers, client, db_en
|
||||
assert changed["needs_rebuild"] is True
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장의 템플릿은 바꿀 수 없다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장의 템플릿은 바꿀 수 없다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("tpl6")
|
||||
intruder = await auth_headers("tpl7", other_company_id)
|
||||
intruder = await auth_headers("tpl7")
|
||||
pid = await _place(client, h)
|
||||
|
||||
blocked = await _set_template(client, intruder, pid, "stay-quiet-margin")
|
||||
|
||||
@@ -129,11 +129,11 @@ async def test_published_site_theme_is_not_locked(auth_headers, client, db_engin
|
||||
assert changed["needs_rebuild"] is True
|
||||
|
||||
|
||||
async def test_other_company_place_is_blocked(auth_headers, client, other_company_id):
|
||||
"""검증: 남의 회사 사업장의 디자인은 바꿀 수 없다.
|
||||
async def test_other_owners_place_is_blocked(auth_headers, client):
|
||||
"""검증: 남의 사업장의 디자인은 바꿀 수 없다.
|
||||
기대결과: PLACE_NOT_FOUND(존재 여부조차 알려주지 않는다)."""
|
||||
h = await auth_headers("thm7")
|
||||
intruder = await auth_headers("thm8", other_company_id)
|
||||
intruder = await auth_headers("thm8")
|
||||
pid = await _place(client, h)
|
||||
|
||||
assert (await _set_theme(client, intruder, pid, _THEME))["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
@@ -110,9 +110,11 @@ async def test_사이트_디렉터리_밖의_thumbs_에_올린다(blob, monkeypa
|
||||
_transport(monkeypatch, lambda req: httpx.Response(200, headers={"content-type": "image/jpeg"}, content=b"jpegbytes"))
|
||||
snapshot = _snapshot({"media_id": "m1", "url": "https://cdn.test/front.jpg", "unit_id": None})
|
||||
|
||||
url = await site_thumbnail.store("butter", snapshot)
|
||||
url = await site_thumbnail.store("butter", snapshot, 3)
|
||||
|
||||
assert url == "https://w4ai.o2o.kr/thumbs/butter.jpg"
|
||||
# ★ `?v=` 는 캐시 무효화다. 블롭 이름은 그대로 덮어쓰므로 주소가 안 변하면
|
||||
# 브라우저·CDN 이 지난 발행의 그림을 계속 보여준다(site_thumbnail.public_url).
|
||||
assert url == "https://w4ai.o2o.kr/thumbs/butter.jpg?v=3"
|
||||
name = f"{azure_static.DEFAULT_PREFIX}/thumbs/butter.jpg"
|
||||
assert set(blob.uploads) == {name}
|
||||
assert not name.startswith(f"{azure_static.DEFAULT_PREFIX}/{azure_static.SITE_ROOT_DIR}/")
|
||||
@@ -131,8 +133,8 @@ async def test_발행하면_사이트에_썸네일_주소가_남는다(auth_head
|
||||
from services import build_service
|
||||
from tests.test_build_publish import _approved_media, _place, _run, _verified_facts
|
||||
|
||||
async def _store(slug, snapshot):
|
||||
return f"https://w4ai.o2o.kr/thumbs/{slug}.jpg"
|
||||
async def _store(slug, snapshot, version=None):
|
||||
return f"https://w4ai.o2o.kr/thumbs/{slug}.jpg?v={version}"
|
||||
|
||||
monkeypatch.setattr(build_service.site_thumbnail, "store", _store)
|
||||
|
||||
@@ -146,6 +148,15 @@ async def test_발행하면_사이트에_썸네일_주소가_남는다(auth_head
|
||||
|
||||
site = (await client.get(f"/v1/place/{pid}/site", headers=h)).json()["site"]
|
||||
assert site["thumbnail_url"].startswith("https://w4ai.o2o.kr/thumbs/")
|
||||
assert site["thumbnail_url"].endswith("?v=1")
|
||||
|
||||
# ★ 재발행하면 주소가 바뀌어야 한다. 블롭 이름은 그대로 덮어쓰므로, 주소가 그대로면
|
||||
# 사장님은 사진을 바꾸고 다시 발행해도 캐시에 남은 **지난 그림**을 계속 본다.
|
||||
await client.post(f"/v1/place/{pid}/site/build", headers=h, json={"publish": True})
|
||||
await _run()
|
||||
again = (await client.get(f"/v1/place/{pid}/site", headers=h)).json()["site"]
|
||||
assert again["thumbnail_url"].endswith("?v=2")
|
||||
assert again["thumbnail_url"] != site["thumbnail_url"]
|
||||
|
||||
|
||||
async def test_썸네일을_못_만들어도_발행은_성공한다(auth_headers, client, db_engine, monkeypatch):
|
||||
@@ -154,7 +165,7 @@ async def test_썸네일을_못_만들어도_발행은_성공한다(auth_headers
|
||||
from services import build_service
|
||||
from tests.test_build_publish import _approved_media, _place, _run, _verified_facts
|
||||
|
||||
async def _store(slug, snapshot):
|
||||
async def _store(slug, snapshot, version=None):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(build_service.site_thumbnail, "store", _store)
|
||||
|
||||
@@ -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, "")
|
||||
|
||||
@@ -136,13 +136,13 @@ async def test_candidates_require_configured_source(auth_headers, client, monkey
|
||||
assert body["result"]["code"] == ErrorType.LOCAL_NOT_CONFIGURED.value
|
||||
|
||||
|
||||
async def test_candidates_scoped_to_company(auth_headers, client, other_company_id, monkeypatch):
|
||||
"""검증: 다른 회사 계정으로 남의 사업장 후보를 조회한다.
|
||||
async def test_candidates_scoped_to_owner(auth_headers, client, monkeypatch):
|
||||
"""검증: 다른 사장님 계정으로 남의 사업장 후보를 조회한다.
|
||||
기대결과: PLACE_NOT_FOUND."""
|
||||
_patch_naver(monkeypatch, _match(kakao_client.MatchOutcome.MATCHED, _np("a", "b"), [], "x"))
|
||||
h1 = await auth_headers("o1")
|
||||
pid = await _place(client, h1)
|
||||
h2 = await auth_headers("o2", other_company_id)
|
||||
h2 = await auth_headers("o2")
|
||||
body = (await client.get(f"/v1/place/{pid}/verify/candidates", headers=h2)).json()
|
||||
assert body["result"]["code"] == ErrorType.PLACE_NOT_FOUND.value
|
||||
|
||||
|
||||
Reference in new issue
Block a user