이슈 본연: API 레퍼런스의 미채움 마커 5종(실측 제외/TODO/필드 없음/대표 에러 없음)
1,194건을 코드에서 읽어 전수 채우고(0건), api:docgen 재생성이 사람이 채운 내용을
손실·열화시키던 멱등성 결함 4종(CRLF, 표 파이프 이스케이프, 에러 서술 보존, 중복
라우트명 키)을 근본 수정. --check 를 실측 제외와 드리프트가 구분되도록 재정의.
ParameterDescriber/ResourceFieldDescriber 에 leaf 폴백·SEO 스코프·공통 사전 확장.
파생 결함(문서 실측 중 발견): ResponseHelper 기본 메시지 키 6종이 존재하지 않는
messages.* 를 가리켜 응답 message 가 번역문 대신 키 문자열로 노출되던 문제를 common.*
으로 정정하고, 코어 7 + gdpr/marketing/pay_kginicis/verification/ecommerce 확장의
호출부와 누락 lang 키(게시판 10키 + 이커머스 category_images 4키 포함)를 ko/en/ja
전수 정정. 중복 그룹 키 2건은 기존 키로 호출부 통합.
보안: GET /api/identity/challenges/{id} 는 권한 가드 없는 공개 폴링 엔드포인트인데
Service::getStatus 가 attempts/max_attempts 를 응답에 담아 남은 시도 횟수를 추론할 수
있었다. 두 필드를 제거하고, 챌린지 화면(admin_basic/basic)의 서버 attempts 참조를
제거(남은 횟수 UI 는 query fallback + verify 실패 시 로컬 증가로 유지).
부수 정리(변경셋에 들어온 board 컨트롤러의 audit 사전 결함): FormRequest 4개 신설로
base Request 주입 제거, CommentController 의 Board 직접 호출을 BoardService 위임으로
전환, PHPDoc @return 보강. board 스위트에서 발견한 stale test 3건(seed SSoT 불일치,
admin 계정 user 역할 누락)도 같은 세션에서 정정.
버전 정렬(공개 release 기준): 코어 7.0.3→7.0.4, sirsoft-board 1.0.1→1.0.2,
verification_kginicis 1.0.0→1.0.1, admin_basic 1.0.1→1.0.4.
190 lines
7.2 KiB
PHP
190 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Admin\Identity;
|
|
|
|
use App\Enums\IdentityPolicySourceType;
|
|
use App\Http\Controllers\Api\Base\AdminBaseController;
|
|
use App\Http\Requests\Identity\AdminIdentityPolicyDestroyRequest;
|
|
use App\Http\Requests\Identity\AdminIdentityPolicyIndexRequest;
|
|
use App\Http\Requests\Identity\AdminIdentityPolicyResetFieldRequest;
|
|
use App\Http\Requests\Identity\AdminIdentityPolicyStoreRequest;
|
|
use App\Http\Requests\Identity\AdminIdentityPolicyUpdateRequest;
|
|
use App\Http\Resources\Identity\PolicyCollection;
|
|
use App\Http\Resources\Identity\PolicyResource;
|
|
use App\Services\IdentityPolicyService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* 관리자 — IDV 정책 CRUD 컨트롤러.
|
|
*
|
|
* S1d 서브섹션(DataGrid + 편집 모달)을 위한 API.
|
|
* 선언형 정책(source_type != 'admin')은 키(key)/시점(scope)/위치(target) 만 readonly 이며,
|
|
* 그 외 필드(purpose/provider_id/grace_minutes/applies_to/priority/fail_mode/enabled/conditions)는
|
|
* 운영자가 자유로이 편집할 수 있습니다. 편집 시 user_overrides JSON 에 필드명이 append 되어
|
|
* Seeder 재실행 시 보존됩니다.
|
|
*/
|
|
class AdminIdentityPolicyController extends AdminBaseController
|
|
{
|
|
/**
|
|
* source_type = core/module/plugin 정책이 수정 가능한 필드 화이트리스트.
|
|
*
|
|
* key/scope/target 은 확장이 발행하는 훅/라우트 지점 식별자라 변경 시 정책이 실제 지점과
|
|
* 어긋나므로 제외한다. 나머지("어떻게 인증할지")는 운영자 자유 편집 대상이다.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected const LIMITED_EDITABLE_FIELDS = ['enabled', 'grace_minutes', 'provider_id', 'fail_mode', 'conditions', 'purpose', 'applies_to', 'priority'];
|
|
|
|
/**
|
|
* @param IdentityPolicyService $policyService 정책 유스케이스 Service
|
|
*/
|
|
public function __construct(
|
|
protected IdentityPolicyService $policyService,
|
|
) {}
|
|
|
|
/**
|
|
* 정책 목록을 조회합니다.
|
|
*
|
|
* @param AdminIdentityPolicyIndexRequest $request 검증된 요청 (필터: scope/purpose/source_type/enabled/search)
|
|
* @return JsonResponse 정책 컬렉션 (페이지네이션 포함)
|
|
*/
|
|
public function index(AdminIdentityPolicyIndexRequest $request): JsonResponse
|
|
{
|
|
$validated = $request->validated();
|
|
$filters = array_filter(
|
|
array_intersect_key($validated, array_flip(['scope', 'purpose', 'source_type', 'source_identifier', 'applies_to', 'fail_mode', 'enabled', 'search'])),
|
|
fn ($v) => $v !== null,
|
|
);
|
|
$perPage = (int) ($validated['per_page'] ?? 20);
|
|
|
|
$paginated = $this->policyService->search($filters, $perPage);
|
|
$collection = (new PolicyCollection($paginated))->toArray($request);
|
|
|
|
return $this->success('common.success', [
|
|
'data' => $collection['data'],
|
|
'abilities' => $collection['abilities'] ?? [],
|
|
'meta' => [
|
|
'current_page' => $paginated->currentPage(),
|
|
'per_page' => $paginated->perPage(),
|
|
'total' => $paginated->total(),
|
|
'last_page' => $paginated->lastPage(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 정책을 신규 생성합니다 (source_type='admin' 고정).
|
|
*
|
|
* @param AdminIdentityPolicyStoreRequest $request 검증된 요청
|
|
* @return JsonResponse 생성된 정책 리소스
|
|
*/
|
|
public function store(AdminIdentityPolicyStoreRequest $request): JsonResponse
|
|
{
|
|
$policy = $this->policyService->createAdminPolicy($request->validated());
|
|
|
|
return $this->success(
|
|
'common.created',
|
|
(new PolicyResource($policy))->toArray($request),
|
|
201,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 정책을 수정합니다. source_type != 'admin' 일 경우 제한 필드만 허용됩니다.
|
|
*
|
|
* @param AdminIdentityPolicyUpdateRequest $request 검증된 요청
|
|
* @param int $id 정책 ID
|
|
* @return JsonResponse 수정된 정책 리소스
|
|
*/
|
|
public function update(AdminIdentityPolicyUpdateRequest $request, int $id): JsonResponse
|
|
{
|
|
$policy = $this->policyService->findById($id);
|
|
|
|
if (! $policy) {
|
|
return $this->error('common.not_found', 404);
|
|
}
|
|
|
|
$validated = $request->validated();
|
|
|
|
// source_type != 'admin' 이면 제한 필드만 허용
|
|
if ($policy->source_type !== IdentityPolicySourceType::Admin) {
|
|
$validated = array_intersect_key(
|
|
$validated,
|
|
array_flip(self::LIMITED_EDITABLE_FIELDS),
|
|
);
|
|
}
|
|
|
|
if (empty($validated)) {
|
|
return $this->error('validation.nothing_to_update', 422);
|
|
}
|
|
|
|
if (! $this->policyService->updatePolicy($policy, $validated)) {
|
|
return $this->error('common.failed', 500);
|
|
}
|
|
|
|
$policy->refresh();
|
|
|
|
return $this->success(
|
|
'common.updated',
|
|
(new PolicyResource($policy))->toArray($request),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 정책을 삭제합니다 (source_type='admin' 정책만 가능, 선언형 정책은 비활성화로 대체).
|
|
*
|
|
* @param AdminIdentityPolicyDestroyRequest $request 검증된 요청
|
|
* @param int $id 정책 ID
|
|
* @return JsonResponse 삭제 결과 응답
|
|
*/
|
|
public function destroy(AdminIdentityPolicyDestroyRequest $request, int $id): JsonResponse
|
|
{
|
|
$policy = $this->policyService->findById($id);
|
|
|
|
if (! $policy) {
|
|
return $this->error('common.not_found', 404);
|
|
}
|
|
|
|
if ($policy->source_type !== IdentityPolicySourceType::Admin) {
|
|
return $this->forbidden('identity.errors.cannot_delete_system_policy');
|
|
}
|
|
|
|
return $this->policyService->deleteAdminPolicy($policy)
|
|
? $this->success('common.deleted')
|
|
: $this->error('common.failed', 500);
|
|
}
|
|
|
|
/**
|
|
* 특정 필드의 user_overrides 를 해제하고 선언 기본값으로 즉시 복원합니다.
|
|
*
|
|
* S1d "↺ 기본값으로 되돌리기" 버튼이 호출하는 엔드포인트입니다.
|
|
* `source_type='admin'` 정책은 선언 기본값이 없어 false 를 반환하며,
|
|
* 선언형 정책(core/module/plugin) 에 대해서만 의미가 있습니다.
|
|
*
|
|
* @param AdminIdentityPolicyResetFieldRequest $request 검증된 요청 (field 필수)
|
|
* @param int $id 정책 ID
|
|
* @return JsonResponse 복원된 최신 정책 리소스 또는 오류
|
|
*/
|
|
public function resetField(AdminIdentityPolicyResetFieldRequest $request, int $id): JsonResponse
|
|
{
|
|
$policy = $this->policyService->findById($id);
|
|
|
|
if (! $policy) {
|
|
return $this->error('common.not_found', 404);
|
|
}
|
|
|
|
if ($policy->source_type === IdentityPolicySourceType::Admin) {
|
|
return $this->forbidden('identity.errors.admin_policy_has_no_default');
|
|
}
|
|
|
|
$field = (string) $request->validated()['field'];
|
|
$ok = $this->policyService->resetFieldOverride($policy, $field);
|
|
|
|
if (! $ok) {
|
|
return $this->error('identity.errors.reset_field_failed', 422);
|
|
}
|
|
|
|
return $this->successWithResource('common.success', new PolicyResource($policy->fresh()));
|
|
}
|
|
}
|