style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Models\Role as SpatieRole;
|
||||
use App\Models\Members\User;
|
||||
use App\Models\Tenants\Department;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\Permission\Models\Role as SpatieRole;
|
||||
|
||||
class PermissionService extends Service
|
||||
{
|
||||
@@ -20,29 +20,29 @@ public function getMenuMatrix(int $id, string $scope, array $params = []): array
|
||||
|
||||
// 1) 대상 유효성 & model_type 결정
|
||||
$modelType = $this->resolveModelType($id, $scope);
|
||||
if (!$modelType) {
|
||||
return ['success'=>false,'message'=>'대상 리소스를 찾을 수 없습니다.','data'=>null];
|
||||
if (! $modelType) {
|
||||
return ['success' => false, 'message' => '대상 리소스를 찾을 수 없습니다.', 'data' => null];
|
||||
}
|
||||
|
||||
// 2) 메뉴 목록
|
||||
$menus = DB::table('menus')
|
||||
->select('id','parent_id','name','url','sort_order')
|
||||
->select('id', 'parent_id', 'name', 'url', 'sort_order')
|
||||
->orderBy('sort_order')->orderBy('id')
|
||||
->get();
|
||||
|
||||
// 3) 권한 정의 (permissions.name = "menu:{menuId}.{action}")
|
||||
$perms = DB::table('permissions')
|
||||
->select('id','name','guard_name')
|
||||
->select('id', 'name', 'guard_name')
|
||||
->where('guard_name', 'api')
|
||||
->where('name','like','menu:%')
|
||||
->where('name', 'like', 'menu:%')
|
||||
->get();
|
||||
|
||||
$permMap = []; // [menuId][action] => ['id','guard','code']
|
||||
foreach ($perms as $p) {
|
||||
if (preg_match('/^menu:(\d+)\.([a-z_]+)$/', $p->name, $m)) {
|
||||
$permMap[(int)$m[1]][$m[2]] = [
|
||||
'id' => (int)$p->id,
|
||||
'guard'=> $p->guard_name,
|
||||
$permMap[(int) $m[1]][$m[2]] = [
|
||||
'id' => (int) $p->id,
|
||||
'guard' => $p->guard_name,
|
||||
'code' => $p->name,
|
||||
];
|
||||
}
|
||||
@@ -65,30 +65,30 @@ public function getMenuMatrix(int $id, string $scope, array $params = []): array
|
||||
$denySet = array_fill_keys($denies, true);
|
||||
|
||||
// 5) 트리 + 액션 상태 구성
|
||||
$actions = ['view','create','update','delete','approve'];
|
||||
$actions = ['view', 'create', 'update', 'delete', 'approve'];
|
||||
$byId = [];
|
||||
foreach ($menus as $m) {
|
||||
$node = [
|
||||
'menu_id' => (int)$m->id,
|
||||
'parent_id' => $m->parent_id ? (int)$m->parent_id : null,
|
||||
'name' => $m->name,
|
||||
'url' => $m->url,
|
||||
'type' => 'system',
|
||||
'children' => [],
|
||||
'actions' => [],
|
||||
'menu_id' => (int) $m->id,
|
||||
'parent_id' => $m->parent_id ? (int) $m->parent_id : null,
|
||||
'name' => $m->name,
|
||||
'url' => $m->url,
|
||||
'type' => 'system',
|
||||
'children' => [],
|
||||
'actions' => [],
|
||||
];
|
||||
foreach ($actions as $a) {
|
||||
$perm = $permMap[$m->id][$a] ?? null;
|
||||
if ($perm) {
|
||||
$pid = $perm['id'];
|
||||
$pid = $perm['id'];
|
||||
$state = isset($denySet[$pid]) ? 'deny'
|
||||
: (isset($allowSet[$pid]) ? 'allow' : 'none');
|
||||
$node['actions'][$a] = [
|
||||
'permission_id' => $pid,
|
||||
'permission_id' => $pid,
|
||||
'permission_code' => $perm['code'],
|
||||
'guard_name' => $perm['guard'],
|
||||
'state' => $state,
|
||||
'is_allowed' => $state === 'allow' ? 1 : 0,
|
||||
'guard_name' => $perm['guard'],
|
||||
'state' => $state,
|
||||
'is_allowed' => $state === 'allow' ? 1 : 0,
|
||||
];
|
||||
} else {
|
||||
$node['actions'][$a] = null;
|
||||
@@ -110,10 +110,10 @@ public function getMenuMatrix(int $id, string $scope, array $params = []): array
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => $this->titleByScope($scope) . ' 성공',
|
||||
'data' => [
|
||||
'message' => $this->titleByScope($scope).' 성공',
|
||||
'data' => [
|
||||
'actions' => $actions,
|
||||
'tree' => $roots,
|
||||
'tree' => $roots,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -123,9 +123,9 @@ private function resolveModelType(int $id, string $scope): ?string
|
||||
{
|
||||
return match ($scope) {
|
||||
'department' => Department::query()->find($id) ? Department::class : null,
|
||||
'role' => SpatieRole::query()->find($id) ? SpatieRole::class : null,
|
||||
'user' => User::query()->find($id) ? User::class : null,
|
||||
default => null,
|
||||
'role' => SpatieRole::query()->find($id) ? SpatieRole::class : null,
|
||||
'user' => User::query()->find($id) ? User::class : null,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -133,9 +133,9 @@ private function titleByScope(string $scope): string
|
||||
{
|
||||
return match ($scope) {
|
||||
'department' => '부서 메뉴 권한 매트릭스 조회',
|
||||
'role' => '역할 메뉴 권한 매트릭스 조회',
|
||||
'user' => '유저 메뉴 권한 매트릭스 조회',
|
||||
default => '메뉴 권한 매트릭스 조회',
|
||||
'role' => '역할 메뉴 권한 매트릭스 조회',
|
||||
'user' => '유저 메뉴 권한 매트릭스 조회',
|
||||
default => '메뉴 권한 매트릭스 조회',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user