feat(chat): 협상 유의사항 안내 팝업 2종 이식 + 팝업 숨김 저장 API
KT-NEGOWIZ fe_v2 의 서비스 안내 팝업을 우리 구조로 이식.
- frontend: GuideContent(공용 본문, VAT/배송비는 chat init 메타로 동적 표시)
+ ServiceInfoPopup(채팅 진입 시 자동 — 안내 보지 않기/오늘 하루 보지 않기)
+ ServiceGuidePopup(메뉴 유의사항·이용 가이드 버튼 수동 — X/배경/ESC 닫기)
+ useServiceInfoPopup 훅(서버 상태 + localStorage 오늘 하루)
+ apis/auth 에 popupStatus 쿼리·hidePopup 뮤테이션, 헬프데스크 연락처 반영,
한국어 단어 잘림 방지(break-keep)
- backend: GET /v1/auth/popup/status, POST /v1/auth/popup/hide
(authenticate 공통 인증 + supplier_users.hide_service_info 영구 저장), 테스트 4건
- db: supplier_users.hide_service_info 컬럼 — 00-init 테이블 정의 갱신,
기존 DB 보정은 alters/2026-07-07-supplier-users-hide-service-info.sql 별도 파일
(기준선 이후 보정 ALTER 는 alters/ 파일로 관리하도록 규칙 변경)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc0e78ec73
commit
3c8923c075
21 files changed
+488
-21
No files matched your search
@@ -29,6 +29,7 @@ class supplier_users(MAIN_BASE):
|
||||
last_accessed_at = Column(DateTime(timezone=True), nullable=False) # 마지막 접속 시각
|
||||
status = Column(SmallInteger, nullable=False, server_default=text("1")) # 상태: 1=active, 2=inactive
|
||||
role = Column(SmallInteger, nullable=False, server_default=text("1")) # 권한: 1=user, 2=manager
|
||||
hide_service_info = Column(Boolean, nullable=False, server_default=text("false")) # 서비스 안내 팝업(협상 유의사항) "안내 보지 않기" 여부
|
||||
created_at = Column(DateTime(timezone=True), nullable=False, server_default=text("(now() AT TIME ZONE 'utc')")) # 생성 시각(UTC)
|
||||
updated_at = Column(DateTime(timezone=True), nullable=False, server_default=text("(now() AT TIME ZONE 'utc')"), onupdate=text("(now() AT TIME ZONE 'utc')")) # 수정 시각(UTC, UPDATE 시 자동 갱신)
|
||||
deleted = Column(Boolean, nullable=False, server_default=text("false")) # 소프트 삭제 여부
|
||||
|
||||
@@ -56,6 +56,14 @@ class IUserCRUD(ABC):
|
||||
async def update_last_accessed(self, cdb: AsyncSession, su_id) -> ErrorType:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_hide_service_info(self, cdb: AsyncSession, su_id) -> Tuple[ErrorType, bool]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def set_hide_service_info(self, cdb: AsyncSession, su_id) -> ErrorType:
|
||||
pass
|
||||
|
||||
|
||||
class UserCRUD(IUserCRUD):
|
||||
async def get_account_by_id(self, cdb: AsyncSession, login_id: str) -> Tuple[ErrorType, supplier_users]:
|
||||
@@ -195,3 +203,34 @@ class UserCRUD(IUserCRUD):
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
|
||||
async def get_hide_service_info(self, cdb: AsyncSession, su_id) -> Tuple[ErrorType, bool]:
|
||||
# 서비스 안내 팝업 "안내 보지 않기" 여부만 조회한다.
|
||||
try:
|
||||
query = (
|
||||
select(supplier_users.hide_service_info)
|
||||
.where(supplier_users.su_id == su_id, supplier_users.deleted == False) # noqa: E712
|
||||
.limit(1)
|
||||
)
|
||||
err_type, row_list = await DB_SESSION_MNG.execute(cdb, query, f"get_hide_service_info(su_id:{su_id}) failed.")
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
return err_type, None
|
||||
if len(row_list) != 1:
|
||||
return ErrorType.DB_INVALID_KEY, None
|
||||
return ErrorType.SUCCESS, bool(row_list[0])
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED, None
|
||||
|
||||
async def set_hide_service_info(self, cdb: AsyncSession, su_id) -> ErrorType:
|
||||
# "안내 보지 않기" 는 켜기만 있다(해제 API 없음).
|
||||
try:
|
||||
query = (
|
||||
update(supplier_users)
|
||||
.where(supplier_users.su_id == su_id, supplier_users.deleted == False) # noqa: E712
|
||||
.values(hide_service_info=True)
|
||||
)
|
||||
return await DB_SESSION_MNG.add(cdb, query)
|
||||
except Exception as ex:
|
||||
LOG.e_no_callstack(ex)
|
||||
return ErrorType.DB_RUN_FAILED
|
||||
@@ -9,7 +9,18 @@ from router.v1.validator.dependencies import (
|
||||
security,
|
||||
)
|
||||
from services.auth_service import AuthService
|
||||
from .protocol import Req_CreateAccount, Req_Login, Res_CreateAccount, Res_Login, Res_Logout, Res_Me, Res_RefreshToken
|
||||
from .protocol import (
|
||||
Req_CreateAccount,
|
||||
Req_HidePopup,
|
||||
Req_Login,
|
||||
Res_CreateAccount,
|
||||
Res_HidePopup,
|
||||
Res_Login,
|
||||
Res_Logout,
|
||||
Res_Me,
|
||||
Res_PopupStatus,
|
||||
Res_RefreshToken,
|
||||
)
|
||||
|
||||
# 라우터(MVC 의 컨트롤러). 요청 검증 -> service 호출 -> RemoveNoneResponse 반환만 담당.
|
||||
router = APIRouter(prefix="/v1/auth", tags=["Auth"], responses={404: {"description": "Not found"}})
|
||||
@@ -54,6 +65,35 @@ async def logout(user_info: UserInfo = Depends(IsValidAccessToken), service: Aut
|
||||
return RemoveNoneResponse(await service.logout(user_info))
|
||||
|
||||
|
||||
@router.get(
|
||||
path="/popup/status",
|
||||
response_model=Res_PopupStatus,
|
||||
summary="팝업 숨김 상태 조회",
|
||||
description="유저별 팝업 '안내 보지 않기' 저장 상태를 반환한다. 현재는 service_info(협상 유의사항 안내) 하나.",
|
||||
)
|
||||
async def popup_status(
|
||||
user_info: UserInfo = Depends(IsValidAccessToken),
|
||||
credentials: HTTPAuthorizationCredentials = Depends(security),
|
||||
service: AuthService = Depends(),
|
||||
):
|
||||
return RemoveNoneResponse(await service.popup_status(user_info, credentials.credentials))
|
||||
|
||||
|
||||
@router.post(
|
||||
path="/popup/hide",
|
||||
response_model=Res_HidePopup,
|
||||
summary="팝업 안내 보지 않기",
|
||||
description="해당 팝업을 다시 표시하지 않도록 유저에 영구 저장한다. popup_type: service_info",
|
||||
)
|
||||
async def hide_popup(
|
||||
req: Req_HidePopup,
|
||||
user_info: UserInfo = Depends(IsValidAccessToken),
|
||||
credentials: HTTPAuthorizationCredentials = Depends(security),
|
||||
service: AuthService = Depends(),
|
||||
):
|
||||
return RemoveNoneResponse(await service.hide_popup(user_info, credentials.credentials, req.popup_type))
|
||||
|
||||
|
||||
@router.get(
|
||||
path="/me",
|
||||
response_model=Res_Me,
|
||||
|
||||
@@ -52,3 +52,15 @@ class Res_Me(Res_WebPacketProtocol):
|
||||
|
||||
class Res_Logout(Res_WebPacketProtocol):
|
||||
pass
|
||||
|
||||
|
||||
class Res_PopupStatus(Res_WebPacketProtocol):
|
||||
service_info: bool = Field(False, description="협상 유의사항(서비스 안내) 팝업 '안내 보지 않기' 여부")
|
||||
|
||||
|
||||
class Req_HidePopup(AuthProtocol):
|
||||
popup_type: str = Field("", description="숨길 팝업 종류: service_info")
|
||||
|
||||
|
||||
class Res_HidePopup(Res_WebPacketProtocol):
|
||||
pass
|
||||
@@ -10,7 +10,15 @@ from common.models.gmodel import UserInfo
|
||||
from common.utils.gtime import GTime
|
||||
from config.server_configs import jwt_token_config
|
||||
from crud.user_crud import IUserCRUD, UserCRUD
|
||||
from router.v1.auth.protocol import Res_CreateAccount, Res_Login, Res_Logout, Res_Me, Res_RefreshToken
|
||||
from router.v1.auth.protocol import (
|
||||
Res_CreateAccount,
|
||||
Res_HidePopup,
|
||||
Res_Login,
|
||||
Res_Logout,
|
||||
Res_Me,
|
||||
Res_PopupStatus,
|
||||
Res_RefreshToken,
|
||||
)
|
||||
from router.v1.validator.dependencies import CreateAccessToken, CreateRefreshToken, GetHashedPW, VerifyPW
|
||||
|
||||
|
||||
@@ -244,6 +252,45 @@ class AuthService:
|
||||
res.role = info.role
|
||||
return res
|
||||
|
||||
async def popup_status(self, user_info: UserInfo, access_token: str) -> Res_PopupStatus:
|
||||
# 유저별 팝업 숨김 상태 조회. 현재는 서비스 안내(service_info) 팝업 하나만 관리한다.
|
||||
res = Res_PopupStatus()
|
||||
err_type, info = await self.authenticate(user_info, access_token)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
err_type, hidden = await DB_SESSION_MNG.execute_lambda(
|
||||
supplier_users.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.user_crud.get_hide_service_info(s, uuid.UUID(info.su_id)),
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
res.service_info = hidden
|
||||
return res
|
||||
|
||||
async def hide_popup(self, user_info: UserInfo, access_token: str, popup_type: str) -> Res_HidePopup:
|
||||
# "안내 보지 않기" 영구 저장. 팝업 종류가 늘면 popup_type 분기를 추가한다.
|
||||
res = Res_HidePopup()
|
||||
if popup_type != "service_info":
|
||||
res.result.SetResult(ErrorType.INVALID_REQUEST_DATA)
|
||||
return res
|
||||
|
||||
err_type, info = await self.authenticate(user_info, access_token)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
err_type = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[supplier_users.DBType()],
|
||||
[lambda s: self.user_crud.set_hide_service_info(s, uuid.UUID(info.su_id))],
|
||||
)
|
||||
if err_type != ErrorType.SUCCESS:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
|
||||
async def logout(self, user_info: UserInfo) -> Res_Logout:
|
||||
# 해당 유저의 저장 토큰(access/refresh)을 모두 삭제 → 이후 보호 요청·재발급이 차단된다.
|
||||
res = Res_Logout()
|
||||
|
||||
@@ -322,3 +322,52 @@ async def test_relogin_invalidates_previous_access(client, account_seed):
|
||||
# 새 access → 정상
|
||||
r_new = await client.get("/v1/auth/me", headers={"Authorization": f"Bearer {second['access_token']}"})
|
||||
assert r_new.json()["result"]["success"] is True
|
||||
|
||||
|
||||
# ---- 팝업 숨김 (popup/status, popup/hide) --------------------------------------
|
||||
async def test_popup_status_default_false(client, account_seed):
|
||||
# 신규 유저는 숨김 상태가 아니다.
|
||||
access = (await _login(client)).json()["access_token"]
|
||||
r = await client.get("/v1/auth/popup/status", headers={"Authorization": f"Bearer {access}"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["result"]["success"] is True
|
||||
assert body["service_info"] is False
|
||||
|
||||
|
||||
async def test_popup_hide_persists(client, account_seed):
|
||||
# hide 후 status 가 True 로 바뀌고, 재로그인해도 유지된다(유저 행에 영구 저장).
|
||||
access = (await _login(client)).json()["access_token"]
|
||||
r = await client.post(
|
||||
"/v1/auth/popup/hide",
|
||||
json={"popup_type": "service_info"},
|
||||
headers={"Authorization": f"Bearer {access}"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json()["result"]["success"] is True
|
||||
|
||||
r2 = await client.get("/v1/auth/popup/status", headers={"Authorization": f"Bearer {access}"})
|
||||
assert r2.json()["service_info"] is True
|
||||
|
||||
# 재로그인(토큰 교체) 후에도 유지
|
||||
new_access = (await _login(client)).json()["access_token"]
|
||||
r3 = await client.get("/v1/auth/popup/status", headers={"Authorization": f"Bearer {new_access}"})
|
||||
assert r3.json()["service_info"] is True
|
||||
|
||||
|
||||
async def test_popup_hide_invalid_type(client, account_seed):
|
||||
access = (await _login(client)).json()["access_token"]
|
||||
r = await client.post(
|
||||
"/v1/auth/popup/hide",
|
||||
json={"popup_type": "unknown_popup"},
|
||||
headers={"Authorization": f"Bearer {access}"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["result"]["success"] is False
|
||||
assert body["result"]["code"] == 101 # INVALID_REQUEST_DATA
|
||||
|
||||
|
||||
async def test_popup_status_without_token(client):
|
||||
r = await client.get("/v1/auth/popup/status")
|
||||
assert r.status_code in (401, 403)
|
||||
Reference in new issue
Block a user