fix scope
This commit is contained in:
@@ -266,6 +266,7 @@ class DataScopeController extends AbstractController
|
||||
'company' => $company_ids[] = $scope['scope_id'],
|
||||
'platform' => $platform_ids[] = $scope['scope_id'],
|
||||
'store' => $store_ids[] = $scope['scope_id'],
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -286,6 +287,7 @@ class DataScopeController extends AbstractController
|
||||
'company' => $company_names[$scope['scope_id']] ?? null,
|
||||
'platform' => isset($platform_names[$scope['scope_id']]) ? "Platform #{$scope['scope_id']}" : null,
|
||||
'store' => $store_names[$scope['scope_id']] ?? null,
|
||||
default => null,
|
||||
};
|
||||
|
||||
return [
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Middleware\PermissionMiddleware;
|
||||
use App\Model\Role;
|
||||
use App\Model\RoleRouteOverride;
|
||||
use App\Model\Route;
|
||||
use App\Model\RouteGroup;
|
||||
use App\Model\User;
|
||||
use App\Service\ScopeTableManager;
|
||||
use Hyperf\DbConnection\Db;
|
||||
@@ -313,6 +314,17 @@ class RoleController extends AbstractController
|
||||
$group_ids = array_map('intval', $group_ids);
|
||||
$group_ids = array_unique($group_ids);
|
||||
|
||||
// 校验 group_ids 都存在
|
||||
if (!empty($group_ids)) {
|
||||
$existing_count = RouteGroup::query()->whereIn('id', $group_ids)->count();
|
||||
if ($existing_count !== count($group_ids)) {
|
||||
return $this->response->json([
|
||||
'code' => 400,
|
||||
'message' => '包含不存在的 group_id',
|
||||
])->withStatus(400);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 sync 全量替换
|
||||
$role->routeGroups()->sync($group_ids);
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ class RouteGroupController extends AbstractController
|
||||
new OA\Property(property: 'sort_order', type: 'integer', example: 0),
|
||||
new OA\Property(property: 'routes_count', type: 'integer', example: 5),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
])),
|
||||
])
|
||||
),
|
||||
@@ -104,7 +103,6 @@ class RouteGroupController extends AbstractController
|
||||
new OA\Property(property: 'description', type: 'string', nullable: true),
|
||||
new OA\Property(property: 'sort_order', type: 'integer', example: 0),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
], type: 'object'),
|
||||
])
|
||||
),
|
||||
@@ -227,7 +225,6 @@ class RouteGroupController extends AbstractController
|
||||
new OA\Property(property: 'description', type: 'string', nullable: true),
|
||||
new OA\Property(property: 'sort_order', type: 'integer', example: 0),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
], type: 'object'),
|
||||
])
|
||||
),
|
||||
@@ -401,8 +398,6 @@ class RouteGroupController extends AbstractController
|
||||
new OA\Property(property: 'method', type: 'string', example: 'GET'),
|
||||
new OA\Property(property: 'path', type: 'string', example: '/api/v1/users'),
|
||||
new OA\Property(property: 'group_id', type: 'integer', nullable: true, example: 1),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'group', nullable: true, properties: [
|
||||
new OA\Property(property: 'id', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'name', type: 'string', example: 'user-management'),
|
||||
@@ -490,8 +485,6 @@ class RouteGroupController extends AbstractController
|
||||
new OA\Property(property: 'method', type: 'string', example: 'GET'),
|
||||
new OA\Property(property: 'path', type: 'string', example: '/api/v1/users'),
|
||||
new OA\Property(property: 'group_id', type: 'integer', nullable: true, example: 1),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'group', nullable: true, properties: [
|
||||
new OA\Property(property: 'id', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'name', type: 'string', example: 'user-management'),
|
||||
|
||||
Reference in New Issue
Block a user