fix(core,board,ecommerce,page,kginicis): 정책값 하드코딩·계약 분리 결함 일괄 수정
관리자 환경설정이 값을 저장은 하지만 실제 동작에는 닿지 않던 결함군을 정리했다. 설정 화면(min/max)·저장 검증(FormRequest)·런타임 적용(Service) 세 계층이 각자 리터럴을 들고 있어 서로 조용히 갈라지던 것이 공통 원인이다. 경계값 SSoT 도입: - config/core.php `settings_limits` 를 단일 출처로 두고, FormRequest 는 이 값으로 규칙을 만들고 화면은 설정 응답의 `_meta.limits` 로 같은 값을 받아 바인딩한다. - 게시판·이커머스도 각 모듈 config 의 limits 를 동일 구조로 노출한다. 적용되지 않던 정책을 실제로 적용: - 비밀번호 최소 길이·특수문자 필수(신규 지정 7개 경로. 로그인은 제외 — 정책을 올렸을 때 기존 회원이 자기 계정에 접근조차 못 하는 데드락을 막기 위함) - 계정 잠금 시간 0 = 무한대(전용 컬럼 분리. timestamp 상한과 NULL 규약 때문에 기존 컬럼 재사용이 불가능하다) + 관리자 수동 해제 경로 - 업로드 최대 크기·허용 확장자, 게시판 첨부 개수·댓글 깊이, 페이지 첨부 정책, 장바구니 수량·구매 한도, 마일리지 사용 한도, 주문 부가세 파생 결함: - 큐 Job(sync 드라이버)이 진행 중인 요청의 Request 바인딩을 덮어써, 뒤이어 실행되는 훅 리스너가 헤더를 잃고 조용히 건너뛰었다. Job 이 원 바인딩을 복원하도록 고치고, 전송 헤더가 필요한 리스너는 동기 실행으로 선언한다. - 확장 업데이트 실패 시 상태만 되돌리고 상태 캐시를 비우지 않아, 그 확장의 관리자 화면만 캐시 TTL(기본 하루) 동안 404 로 남았다. 실패 경로에도 무효화를 대칭으로 두고, 빈 목록 자체를 캐시하지 않는다. - 글 작성 시 첨부 파일이 Service 로 전달되지 않아 검증·권한은 통과하고 첨부만 사라졌다. - 환경설정 저장 실패 안내가 내부 설정 키를 그대로 노출했다(105개 항목에 라벨 부여). 재발 방지: - audit 룰 3종(레이아웃 경계 리터럴 / FormRequest 경계 불일치 / Service 재클램프) - 테스트 실행 범위 강제 훅(check-test-scope) - 트러블슈팅 사례 2건(큐 Job 요청 오염 / 확장 상태 캐시 고착) 공개 이슈: gnuboard/g7
This commit is contained in:
1 parent
5d140dfbe6
commit
d17ea28da5
272 files changed
+12431
-1006
No files matched your search
+4
@@ -57,6 +57,10 @@ class EcommerceSettingsController extends AdminBaseController
|
||||
'can_update' => PermissionHelper::check('sirsoft-ecommerce.settings.update', request()->user()),
|
||||
];
|
||||
|
||||
// 화면의 숫자 입력 경계값 — 저장 규칙과 같은 출처를 내려준다.
|
||||
// 화면이 리터럴을 들면 규칙이 바뀔 때 따라오지 못해 "화면은 받는데 저장은 422" 가 된다.
|
||||
$settings['_meta'] = ['limits' => config('sirsoft-ecommerce.limits', [])];
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
'messages.settings.fetch_success',
|
||||
|
||||
+19
-45
@@ -5,20 +5,21 @@ namespace Modules\Sirsoft\Ecommerce\Http\Controllers\Admin;
|
||||
use App\Helpers\ResponseHelper;
|
||||
use App\Http\Controllers\Api\Base\AdminBaseController;
|
||||
use App\Http\Resources\ActivityLogResource;
|
||||
use App\Models\ActivityLog;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\ProductHasOrderHistoryException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\ProductImageUploadLimitException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\ProductPriceRelationException;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\BulkUpdatePriceRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\BulkUpdateProductsRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\BulkUpdateStatusRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\BulkUpdateStockRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\ProductListRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\ProductLogsRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\ReorderProductImagesRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\ShowProductForCopyRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\StoreProductRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\UpdateProductRequest;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Admin\UploadProductImageRequest;
|
||||
@@ -26,7 +27,6 @@ use Modules\Sirsoft\Ecommerce\Http\Resources\ProductCollection;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Resources\ProductOptionResource;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Resources\ProductResource;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Product;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ProductOption;
|
||||
use Modules\Sirsoft\Ecommerce\Services\ProductImageService;
|
||||
use Modules\Sirsoft\Ecommerce\Services\ProductService;
|
||||
|
||||
@@ -407,6 +407,15 @@ class ProductController extends AdminBaseController
|
||||
200,
|
||||
['count' => ($result['products_updated'] ?? 0) + ($result['options_updated'] ?? 0)]
|
||||
);
|
||||
} catch (ProductPriceRelationException $e) {
|
||||
// 판매가 > 정가 조합은 도메인 검증 실패 → generic 500 이 아닌 422
|
||||
return ResponseHelper::error(
|
||||
'validation.product.selling_price_lte_list',
|
||||
422,
|
||||
null,
|
||||
[],
|
||||
'sirsoft-ecommerce'
|
||||
);
|
||||
} catch (ValidationException $e) {
|
||||
return ResponseHelper::moduleError(
|
||||
'sirsoft-ecommerce',
|
||||
@@ -557,28 +566,14 @@ class ProductController extends AdminBaseController
|
||||
/**
|
||||
* 상품 복사용 데이터를 조회합니다.
|
||||
*
|
||||
* @param Request $request HTTP 요청 (복사 옵션 포함)
|
||||
* @param ShowProductForCopyRequest $request 복사 옵션 요청 데이터
|
||||
* @param Product $product 복사할 상품 모델
|
||||
* @return JsonResponse 복사용 데이터 JSON 응답
|
||||
*/
|
||||
public function showForCopy(Request $request, Product $product): JsonResponse
|
||||
public function showForCopy(ShowProductForCopyRequest $request, Product $product): JsonResponse
|
||||
{
|
||||
try {
|
||||
$copyOptions = [
|
||||
'images' => $request->boolean('copy_images', true),
|
||||
'options' => $request->boolean('copy_options', true),
|
||||
'categories' => $request->boolean('copy_categories', true),
|
||||
'sales_info' => $request->boolean('copy_sales_info', true),
|
||||
'description' => $request->boolean('copy_description', true),
|
||||
'notice' => $request->boolean('copy_notice', true),
|
||||
'common_info' => $request->boolean('copy_common_info', true),
|
||||
'other_info' => $request->boolean('copy_other_info', true),
|
||||
'shipping' => $request->boolean('copy_shipping', true),
|
||||
'seo' => $request->boolean('copy_seo', false),
|
||||
'identification' => $request->boolean('copy_identification', true),
|
||||
];
|
||||
|
||||
$copyData = $this->productService->getDetailForCopy($product->id, $copyOptions);
|
||||
$copyData = $this->productService->getDetailForCopy($product->id, $request->getCopyOptions());
|
||||
|
||||
if (! $copyData) {
|
||||
return ResponseHelper::notFound(
|
||||
@@ -802,36 +797,15 @@ class ProductController extends AdminBaseController
|
||||
/**
|
||||
* 상품 처리로그(활동 로그) 목록을 조회합니다.
|
||||
*
|
||||
* @param Request $request 요청
|
||||
* @param ProductLogsRequest $request 활동 로그 조회 요청 데이터
|
||||
* @param Product $product 상품
|
||||
* @return JsonResponse 활동 로그 목록
|
||||
*/
|
||||
public function logs(Request $request, Product $product): JsonResponse
|
||||
public function logs(ProductLogsRequest $request, Product $product): JsonResponse
|
||||
{
|
||||
try {
|
||||
$perPage = (int) ($request->query('per_page', 10));
|
||||
$sortOrder = $request->query('sort_order', 'desc');
|
||||
|
||||
// 상품 + 상품옵션 로그를 합쳐서 조회
|
||||
$optionIds = $product->options()->pluck('id')->toArray();
|
||||
|
||||
$query = ActivityLog::where(function ($q) use ($product, $optionIds) {
|
||||
// 상품 자체 로그
|
||||
$q->where(function ($sub) use ($product) {
|
||||
$sub->where('loggable_type', $product->getMorphClass())
|
||||
->where('loggable_id', $product->getKey());
|
||||
});
|
||||
|
||||
// 해당 상품의 옵션 로그
|
||||
if (! empty($optionIds)) {
|
||||
$q->orWhere(function ($sub) use ($optionIds) {
|
||||
$sub->where('loggable_type', (new ProductOption)->getMorphClass())
|
||||
->whereIn('loggable_id', $optionIds);
|
||||
});
|
||||
}
|
||||
})->orderBy('created_at', $sortOrder);
|
||||
|
||||
$logs = $query->paginate($perPage);
|
||||
// 상품 + 상품옵션 로그 합산 조회는 Repository 위임 (Service 경유)
|
||||
$logs = $this->productService->getActivityLogs($product, $request->getFilters());
|
||||
|
||||
return ResponseHelper::moduleSuccess(
|
||||
'sirsoft-ecommerce',
|
||||
|
||||
@@ -10,6 +10,7 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\CartOperationException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\CartQuantityLimitException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\CartUnavailableException;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Middleware\ResolveShippingCountry;
|
||||
use Modules\Sirsoft\Ecommerce\Http\Requests\Public\BulkAddToCartRequest;
|
||||
@@ -153,6 +154,14 @@ class CartController extends PublicBaseController
|
||||
} catch (CartUnavailableException $e) {
|
||||
// 판매불가/재고/구매수량 한도 위반 — generic 500 이 아닌 사유별 422 매핑
|
||||
return $this->cartUnavailableResponse($e);
|
||||
} catch (CartQuantityLimitException $e) {
|
||||
// 장바구니 수량 상한 초과 — generic 500 이 아닌 422 명시 차단
|
||||
return ResponseHelper::error(
|
||||
'sirsoft-ecommerce::validation.cart.quantity_limit_exceeded',
|
||||
422,
|
||||
['code' => 'cart_quantity_limit_exceeded', 'detail' => $e->getMessage()],
|
||||
['limit' => $e->getLimit(), 'attempted' => $e->getAttempted()]
|
||||
);
|
||||
} catch (CartOperationException $e) {
|
||||
// 항목없음/권한없음/옵션없음 — 사유별 404/403/422 매핑
|
||||
return $this->cartOperationResponse($e);
|
||||
@@ -214,6 +223,14 @@ class CartController extends PublicBaseController
|
||||
} catch (CartUnavailableException $e) {
|
||||
// 판매불가/재고/구매수량 한도 위반 — generic 500 이 아닌 사유별 422 매핑
|
||||
return $this->cartUnavailableResponse($e);
|
||||
} catch (CartQuantityLimitException $e) {
|
||||
// 장바구니 수량 상한 초과 — generic 500 이 아닌 422 명시 차단
|
||||
return ResponseHelper::error(
|
||||
'sirsoft-ecommerce::validation.cart.quantity_limit_exceeded',
|
||||
422,
|
||||
['code' => 'cart_quantity_limit_exceeded', 'detail' => $e->getMessage()],
|
||||
['limit' => $e->getLimit(), 'attempted' => $e->getAttempted()]
|
||||
);
|
||||
} catch (CartOperationException $e) {
|
||||
// 항목없음/권한없음/옵션없음 — 사유별 404/403/422 매핑
|
||||
return $this->cartOperationResponse($e);
|
||||
@@ -259,6 +276,14 @@ class CartController extends PublicBaseController
|
||||
} catch (CartUnavailableException $e) {
|
||||
// 판매불가/재고/구매수량 한도 위반 — generic 500 이 아닌 사유별 422 매핑
|
||||
return $this->cartUnavailableResponse($e);
|
||||
} catch (CartQuantityLimitException $e) {
|
||||
// 장바구니 수량 상한 초과 — generic 500 이 아닌 422 명시 차단
|
||||
return ResponseHelper::error(
|
||||
'sirsoft-ecommerce::validation.cart.quantity_limit_exceeded',
|
||||
422,
|
||||
['code' => 'cart_quantity_limit_exceeded', 'detail' => $e->getMessage()],
|
||||
['limit' => $e->getLimit(), 'attempted' => $e->getAttempted()]
|
||||
);
|
||||
} catch (CartOperationException $e) {
|
||||
// 항목없음/권한없음/옵션없음/타상품옵션 — 사유별 404/403/422 매핑
|
||||
return $this->cartOperationResponse($e);
|
||||
@@ -291,6 +316,14 @@ class CartController extends PublicBaseController
|
||||
$this->cartService->deleteItem($id, $userId, $cartKey);
|
||||
|
||||
return ResponseHelper::moduleSuccess('sirsoft-ecommerce', 'messages.cart.deleted');
|
||||
} catch (CartQuantityLimitException $e) {
|
||||
// 장바구니 수량 상한 초과 — generic 500 이 아닌 422 명시 차단
|
||||
return ResponseHelper::error(
|
||||
'sirsoft-ecommerce::validation.cart.quantity_limit_exceeded',
|
||||
422,
|
||||
['code' => 'cart_quantity_limit_exceeded', 'detail' => $e->getMessage()],
|
||||
['limit' => $e->getLimit(), 'attempted' => $e->getAttempted()]
|
||||
);
|
||||
} catch (CartOperationException $e) {
|
||||
// 없는 항목(404)/타인 항목(403) 삭제 시도 — generic 500 이 아닌 사유별 4xx
|
||||
return $this->cartOperationResponse($e);
|
||||
@@ -393,8 +426,11 @@ class CartController extends PublicBaseController
|
||||
|
||||
$mergedCount = $this->cartService->mergeGuestCartToUser($cartKey, $userId);
|
||||
|
||||
// 병합은 수량을 상한까지 줄일 수 있다. 줄인 사실을 응답에 담지 않으면 사용자는
|
||||
// 자기가 담아 둔 수량이 조용히 바뀐 것을 알 방법이 없다.
|
||||
return ResponseHelper::moduleSuccess('sirsoft-ecommerce', 'messages.cart.merged', [
|
||||
'merged_count' => $mergedCount,
|
||||
'adjustments' => $this->cartService->getLastMergeAdjustments(),
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error('cart.merge failed', ['error' => $e->getMessage()]);
|
||||
|
||||
+14
@@ -10,6 +10,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\CartUnavailableException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\InsufficientStockException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\MileageValidationException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\OrderProcessingException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\PaymentAmountMismatchException;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\UnsupportedPaymentCurrencyException;
|
||||
@@ -164,6 +165,19 @@ trait HandlesOrderCreation
|
||||
'has_restriction_issue' => $e->hasRestrictionIssue(),
|
||||
]);
|
||||
|
||||
} catch (MileageValidationException $e) {
|
||||
// 마일리지 사용 정책 위반(한도/단위/최소사용액/잔액) — generic 500 이 아닌 422 명시 차단.
|
||||
// 임시주문 생성 이후 설정이 바뀌었거나 임시주문이 조작된 경우 여기로 떨어진다.
|
||||
Log::warning('Order create: mileage usage policy violation', [
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return ResponseHelper::error(
|
||||
'sirsoft-ecommerce::exceptions.order_create_failed',
|
||||
422,
|
||||
['code' => 'mileage_usage_not_allowed', 'detail' => $e->getMessage()]
|
||||
);
|
||||
|
||||
} catch (OrderProcessingException $e) {
|
||||
// 주문 확정 재계산 검증 실패(쿠폰 만료/min_amount/per_user_limit/not_combinable 등)
|
||||
// generic 500 이 아닌 422 로 하드 차단 — 서버 우회 방지 (U14/MP06)
|
||||
|
||||
Reference in new issue
Block a user