위임 관리자(부관리자)가 권한·역할·표현식·비밀 콘텐츠 경계를 우회하던 결함군을 계층 대칭성 원칙으로 전건 차단한다. 약한 경로가 정상 응답을 내보내는 것이 유일한 증상이라, 게이트를 생산 지점 한 곳(SSoT)에 두고 같은 데이터를 내보내는 소비 경로 전부가 그 게이트를 경유하도록 맞췄다. - 등급 상한(rank ceiling): 슈퍼관리자 보호·역할/사용자 역할 배정(추가·제거 대칭)·일괄 상태변경·순서변경을 상세 경로와 동일 강도로 재적용. 가드는 DB 쓰기에 선행하여 거부 시 상태 불변. - 레이아웃 표현식: new Function/with 실행을 AST 화이트리스트 평가기로 교체. 비-문자열 computed 키 정규화(normalizeKey)·Object facade(리플렉션 static 제거)·legacy 접근자 차단. 저장측 검증·정적 검사와 3계층 동형. - secret 게이트: 비밀글의 댓글·첨부·문의 독립 경로 재적용, hash 파일서빙 소유권·비밀·발행 상태 검사 통일. - 신뢰 스크립트 호스트: 확장 선언 기반 + same-origin 브라우저 정규화를 런타임·저장측·정적검사 3층 동형화. - 회귀 감지: 단위·Feature·E2E·시나리오 매니페스트 전축 + audit 룰 4종 신설.
122 lines
4.4 KiB
PHP
122 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Http\Resources\Traits\HasAbilityCheck;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class UserCollection extends BaseApiCollection
|
|
{
|
|
use HasAbilityCheck;
|
|
|
|
/**
|
|
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
|
|
*
|
|
* @return array<string, string> 능력 키 => 권한 식별자 매핑
|
|
*/
|
|
protected function abilityMap(): array
|
|
{
|
|
return [
|
|
'can_create' => 'core.users.create',
|
|
'can_update' => 'core.users.update',
|
|
'can_delete' => 'core.users.delete',
|
|
// 역할 부여는 "사용자 관리"(core.users.update)의 일부다 — "역할 정의 수정"
|
|
// (core.permissions.update)이 아니다. 부여 가능한 개별 역할의 범위는 서버
|
|
// 상한(PermissionEscalationGuard)이 역할별로 강제한다.
|
|
'can_assign_roles' => 'core.users.update',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 사용자 컬렉션을 배열로 변환합니다.
|
|
*
|
|
* @param Request $request HTTP 요청 객체
|
|
* @return array<int|string, mixed> 변환된 사용자 컬렉션 배열
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'data' => $this->mapWithRowNumber(function ($user) {
|
|
return (new UserResource($user))->toListArray(request());
|
|
}),
|
|
'pagination' => $this->when($this->resource instanceof LengthAwarePaginator, [
|
|
'current_page' => $this->resource->currentPage(),
|
|
'last_page' => $this->resource->lastPage(),
|
|
'per_page' => $this->resource->perPage(),
|
|
'total' => $this->resource->total(),
|
|
'from' => $this->resource->firstItem(),
|
|
'to' => $this->resource->lastItem(),
|
|
'has_more_pages' => $this->resource->hasMorePages(),
|
|
]),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 통계가 포함된 형태의 배열을 반환합니다.
|
|
*
|
|
* @param array $statistics 통계 데이터 배열
|
|
* @return array<string, mixed> 통계 정보가 포함된 사용자 컬렉션
|
|
*/
|
|
public function withStatistics(array $statistics = []): array
|
|
{
|
|
$isPaginator = $this->resource instanceof LengthAwarePaginator;
|
|
|
|
return [
|
|
'data' => $this->mapWithRowNumber(function ($user) {
|
|
return (new UserResource($user))->toListArray(request());
|
|
}),
|
|
'statistics' => $statistics,
|
|
'abilities' => $this->resolveAbilitiesFromMap($this->abilityMap(), request()->user()),
|
|
'pagination' => $isPaginator ? [
|
|
'current_page' => $this->resource->currentPage(),
|
|
'last_page' => $this->resource->lastPage(),
|
|
'per_page' => $this->resource->perPage(),
|
|
'total' => $this->resource->total(),
|
|
'from' => $this->resource->firstItem(),
|
|
'to' => $this->resource->lastItem(),
|
|
'has_more_pages' => $this->resource->hasMorePages(),
|
|
] : null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 관리자용 상세 정보가 포함된 형태의 배열을 반환합니다.
|
|
*
|
|
* @return array<string, mixed> 관리자 정보가 포함된 사용자 컬렉션
|
|
*/
|
|
public function withAdminInfo(): array
|
|
{
|
|
return [
|
|
'data' => $this->mapWithRowNumber(function ($user) {
|
|
return (new UserResource($user))->withAdminInfo();
|
|
}),
|
|
'pagination' => $this->when($this->resource instanceof LengthAwarePaginator, [
|
|
'current_page' => $this->resource->currentPage(),
|
|
'last_page' => $this->resource->lastPage(),
|
|
'per_page' => $this->resource->perPage(),
|
|
'total' => $this->resource->total(),
|
|
'from' => $this->resource->firstItem(),
|
|
'to' => $this->resource->lastItem(),
|
|
'has_more_pages' => $this->resource->hasMorePages(),
|
|
]),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 간단한 목록 형태의 배열을 반환합니다.
|
|
*
|
|
* @return array<int, array<string, mixed>> 간략한 사용자 정보 배열
|
|
*/
|
|
public function toSimpleArray(): array
|
|
{
|
|
return $this->collection->map(function ($user) {
|
|
return [
|
|
'uuid' => $user->uuid,
|
|
'name' => $user->name,
|
|
'email' => $user->email,
|
|
];
|
|
})->toArray();
|
|
}
|
|
}
|