[feat] solution/backend,frontend: 관리자가 모든 사업장을 열고 관리 — 사이트관리 검색·업종 필터·삭제, 사장님 더보기 정리

사업장 API 가 전부 "요청자 = 소유자" 로 걸러져서 관리자가 남의 빌더·미니블로그를 열면
PLACE_NOT_FOUND 였다. 운영 중 사업장 정리도 사장님 계정으로 들어가야 했다.

- validator/dependencies: DEVELOPER 가 place_id 경로를 부르면 그 사업장 소유자 신원으로 처리 — [admin-access] 로그
- ops/sites: search(상호·소유자 이메일·이름·아이디) · category 필터, 건수도 같은 조건
- OpsSitesPage: 검색창 · 업종 칩 · 행마다 빌더·미니블로그·삭제(공개 중이면 발행 내린 뒤 삭제)
- SitesPage: 더보기에서 미니블로그 관리 · 예약요청 관리 제거

테스트 4건 추가(test_admin_access). 전체 900 passed · 145 failed(변경 전과 같은 파일: agent_runtime·gemini 등)
frontend tsc·eslint 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-09-30 15:34:20 +09:00
1 parent 87343c791b
commit 14b6e95f9d
8 files changed
+259 -58

No files matched your search

@@ -6,6 +6,14 @@
*/
export type ListSitesParams = {
/**
* 상호·소유자 이메일·이름·로그인 아이디 부분 일치
*/
search?: string | null;
/**
* PlaceCategory
*/
category?: number | null;
/**
* @minimum 1
*/
+129 -20
View File
@@ -1,13 +1,16 @@
import {useState} from 'react';
import {Navigate} from 'react-router';
import {Link, Navigate} from 'react-router';
import {keepPreviousData} from '@tanstack/react-query';
import {Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2} from 'lucide-react';
import {Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2, Newspaper, Pencil, Search, Trash2, X} from 'lucide-react';
import {PlaceCategory, publishUrlString, SiteStatus} from '@o2o/shared';
import {UserRole, useListSites, type OpsSiteData} from '@/api';
import {changeStatus, deletePlace, PublishAction, UserRole, useListSites, type OpsSiteData} from '@/api';
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
import {Badge} from '@/components/ui/badge';
import {Button} from '@/components/ui/button';
import {Input} from '@/components/ui/input';
import {notify, notifyApiError} from '@/lib/notify';
import {PUBLISH_HOST} from '@/lib/site';
import {cn} from '@/lib/utils';
import {useAuthStore} from '@/stores/auth';
const CATEGORY_LABEL: Record<number, string> = {
@@ -39,14 +42,46 @@ export function OpsSitesPage() {
const isRestoring = useAuthStore((s) => s.isRestoring);
const role = useAuthStore((s) => s.user?.role);
const [page, setPage] = useState(1);
const [search, setSearch] = useState('');
const [category, setCategory] = useState<number | null>(null);
const [busyId, setBusyId] = useState<string | null>(null);
const size = 20;
// enabled: role 이 확정되기 전엔 요청하지 않는다 — 어차피 백엔드가 403 으로 막지만, 사장님 화면에서 실패 토스트가 먼저 뜨는 것과 새로고침 때 잠깐의 오탐 리다이렉트를 막는다.
const {data, isLoading, isError, error} = useListSites(
{page, size},
const {data, isLoading, isError, error, refetch} = useListSites(
{page, size, search: search || undefined, category: category ?? undefined},
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER}},
);
// RequireAuth 와 같은 이유 — 복구가 끝나기 전에 판단하면 새로고침마다 리다이렉트가 한 번 번쩍인다.
const handleDelete = async (row: OpsSiteData) => {
const published = row.status === SiteStatus.PUBLISHED;
const message = published
? `'${row.name}' 사업장을 삭제할까요?\n발행된 사이트를 먼저 내리고 삭제합니다.`
: `'${row.name}' 사업장을 삭제할까요?`;
if (!window.confirm(message)) return;
setBusyId(row.place_id);
try {
if (published) {
const down = await changeStatus(row.place_id, {action: PublishAction.UNPUBLISH});
if (!down.result?.success) {
notifyApiError({data: down}, '사이트를 내리지 못해 삭제하지 않았습니다.');
return;
}
}
const res = await deletePlace(row.place_id);
if (!res.result?.success) {
notifyApiError({data: res}, '사업장을 삭제하지 못했습니다.');
return;
}
notify.success(`'${row.name}' 을(를) 삭제했습니다.`);
await refetch();
} catch (deleteError) {
notifyApiError(deleteError, '사업장을 삭제하지 못했습니다.');
} finally {
setBusyId(null);
}
};
if (isRestoring) return null;
if (role !== UserRole.DEVELOPER) return <Navigate to="/sites" replace />;
@@ -56,7 +91,55 @@ export function OpsSitesPage() {
return (
<AppShell>
<PageContainer title="사이트관리" description="전 계정 사이트 발행 현황입니다. 회사 스코프 없이 전부 보입니다.">
<PageContainer
title="사이트관리"
description="전 계정 사이트 발행 현황입니다. 회사 스코프 없이 전부 보입니다."
actions={
<div className="relative w-64">
<Search className="pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground" />
<Input
type="search"
value={search}
onChange={(event) => {
setPage(1);
setSearch(event.target.value);
}}
placeholder="상호 · 이메일 · 이름 · 아이디 검색"
aria-label="상호 · 이메일 · 이름 · 아이디 검색"
className="h-9 pr-8 pl-8"
/>
{search && (
<button
type="button"
aria-label="검색어 지우기"
onClick={() => setSearch('')}
className="absolute top-1/2 right-2 -translate-y-1/2 cursor-pointer text-muted-foreground transition-colors hover:text-foreground"
>
<X className="size-3.5" />
</button>
)}
</div>
}
>
<div className="mb-3 flex flex-wrap gap-1.5">
{[null, ...Object.keys(CATEGORY_LABEL).map(Number)].map((value) => (
<button
key={value ?? 'all'}
type="button"
onClick={() => {
setPage(1);
setCategory(value);
}}
className={cn(
'h-8 cursor-pointer rounded-md border px-3 text-xs font-medium transition-colors',
category === value ? 'border-foreground bg-foreground text-background' : 'border-border hover:bg-muted',
)}
>
{value === null ? '전체' : CATEGORY_LABEL[value]}
</button>
))}
</div>
{isLoading && (
<div className="flex items-center justify-center py-20 text-muted-foreground">
<Loader2 className="size-5 animate-spin" />
@@ -95,21 +178,47 @@ export function OpsSitesPage() {
</p>
</div>
{url ? (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
<div className="flex shrink-0 items-center gap-1.5">
<Link
to={`/builder?placeId=${row.place_id}`}
className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
>
<ExternalLink className="size-3.5" />
열기
</a>
) : (
<span className="shrink-0 text-xs text-muted-foreground">
{row.domain ? `주소 예약됨 · ${row.domain}` : '주소 미정'}
</span>
)}
<Pencil className="size-3.5" />
빌더
</Link>
<Link
to={`/blog?placeId=${row.place_id}`}
className="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
>
<Newspaper className="size-3.5" />
미니블로그
</Link>
{url ? (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
>
<ExternalLink className="size-3.5" />
열기
</a>
) : (
<span className="shrink-0 text-xs text-muted-foreground">
{row.domain ? `주소 예약됨 · ${row.domain}` : '주소 미정'}
</span>
)}
<Button
size="icon"
variant="ghost"
aria-label={`${row.name} 삭제`}
disabled={busyId === row.place_id}
onClick={() => handleDelete(row)}
className="text-destructive"
>
{busyId === row.place_id ? <Loader2 className="animate-spin" /> : <Trash2 />}
</Button>
</div>
</li>
);
})}
-28
View File
@@ -6,12 +6,10 @@ import {useMemo, useState} from 'react';
import {Link, useNavigate} from 'react-router';
import {
Building2,
CalendarClock,
Coffee,
ExternalLink,
Loader2,
MoreHorizontal,
Newspaper,
Pencil,
Plus,
Search,
@@ -394,32 +392,6 @@ export function SitesPage() {
<Pencil className="size-3.5" />
디자인·컨텐츠 관리
</button>
<button
type="button"
onClick={() => {
setMenuId(null);
navigate(`/blog?placeId=${row.place_id}`);
}}
className="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted"
>
<Newspaper className="size-3.5" />
미니블로그 관리
</button>
<button
type="button"
onClick={() => {
setMenuId(null);
// 예약 요청은 DB 에 안 남는다 — 메일로만 가고 우리 쪽엔 로그 한 줄만 남는다.
notify.info(
'예약 요청은 메일로만 전달됩니다',
'연락처를 따로 저장하지 않기로 했습니다(2026-09-16). 목록이 필요하면 먼저 이 방침을 바꿔야 합니다.',
);
}}
className="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-muted"
>
<CalendarClock className="size-3.5" />
예약요청 관리
</button>
<div className="my-1 border-t border-border" />
<button
type="button"