| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- /**
- * 请求参数资源归属校验配置
- *
- * 配合 App\Http\Middleware\CheckCompany 使用:
- * 校验请求参数中的资源 ID 是否属于当前登录用户所在公司(cpid),防止跨公司访问。
- * 同一公司内不同用户默认视为共享,因此这里只校验公司维度(cpid),不校验 user_id。
- *
- * 说明:在 config 文件中使用 env() 是安全的(config:cache 时会被固化);
- * 业务代码中请勿直接使用 env()。
- */
- // 分镜归属:mp_episode_segments 无 cpid,靠 anime_id 推导;
- // 注意 segment_id 是字符串业务键(形如 202601011200001234001),不能按整数解析。
- $segmentDefine = [
- 'table' => 'mp_episode_segments',
- 'key' => 'segment_id',
- 'type' => 'string',
- 'via' => ['local' => 'anime_id', 'table' => 'mp_animes', 'key' => 'id'],
- ];
- // 片段归属:片段同样存放在 mp_episode_segments,但以自增主键 id 定位
- $actDefine = [
- 'table' => 'mp_episode_segments',
- 'key' => 'id',
- 'via' => ['local' => 'anime_id', 'table' => 'mp_animes', 'key' => 'id'],
- ];
- return [
- // 总开关(对应 .env 中的 CHECK_COMPANY)
- 'enabled' => (bool)env('CHECK_COMPANY', false),
- // 跳过校验的角色:平台运营角色本身需要跨公司操作
- 'skip_roles' => ['superadmin'],
- /*
- | 跳过校验的公司ID(内部公司白名单)
- | 用于灰度上线或线上异常时先放过内部公司,避免误拦影响自己人。
- | 多个用逗号分隔,例如 .env 中 CHECK_COMPANY_SKIP_CPIDS=1,2;
- | 留空表示不跳过任何公司(全部校验)。
- */
- 'skip_cpids' => array_values(array_filter(array_map('intval', explode(',', (string)env('CHECK_COMPANY_SKIP_CPIDS', '1'))))),
- // 资源归属列(公司维度)
- 'owner_column' => 'cpid',
- /*
- |--------------------------------------------------------------------------
- | 全局参数映射
- |--------------------------------------------------------------------------
- | 格式:参数名 => ['table' => 表名, 'key' => 主键列(可选,默认 id)]
- | 仅当该参数名在全项目范围内语义唯一时才放在这里;
- | 参数名有歧义(例如 id、task_id)时请放到下方 routes 中按路由指定。
- */
- 'params' => [
- // 原有校验项,保持行为不变
- 'script_id' => ['table' => 'mp_scripts'],
- 'anime_id' => ['table' => 'mp_animes'],
- 'episode_id' => ['table' => 'mp_anime_episodes'],
- // 画布
- 'canvas_id' => ['table' => 'mp_canvases'],
- // 资产库(个人库 user_id=自身,公共库 user_id=0,归属列均为 cpid)
- 'product_id' => ['table' => 'mp_products'],
- 'parent_id' => ['table' => 'mp_products'],
- 'target_parent_id' => ['table' => 'mp_products'],
- 'source_product_id' => ['table' => 'mp_products'],
- 'source_anime_id' => ['table' => 'mp_animes'],
- 'source_episode_id' => ['table' => 'mp_anime_episodes'],
- // 提示词模板
- 'template_id' => ['table' => 'mp_prompt_templates'],
- ],
- /*
- |--------------------------------------------------------------------------
- | 批量参数
- |--------------------------------------------------------------------------
- | 值可能是数组、逗号分隔字符串或 JSON 数组,会逐项校验。
- */
- 'array_params' => [
- 'script_ids' => ['table' => 'mp_scripts'],
- ],
- /*
- |--------------------------------------------------------------------------
- | 链式校验参数(目标表没有 cpid 列,需要沿父级推导归属)
- |--------------------------------------------------------------------------
- | 格式:参数名 => [
- | 'table' => 目标表,
- | 'key' => 目标表主键列(默认 id),
- | 'type' => 主键类型 int|string(默认 int),
- | 'via' => ['local' => 目标表中的外键列, 'table' => 父表, 'key' => 父表主键列],
- | ]
- |
- | 校验方式:按主键取出记录 → 用记录中的外键查父表 → 校验父表记录的 cpid。
- | 记录不存在时按无权限处理(fail-closed)。
- */
- 'linked_params' => [
- // 剧本分集组:mp_script_episode_group.script_id -> mp_scripts
- 'group_id' => [
- 'table' => 'mp_script_episode_group',
- 'via' => ['local' => 'script_id', 'table' => 'mp_scripts', 'key' => 'id'],
- ],
- // 剧本对话记录:mp_script_records.script_id -> mp_scripts
- 'rid' => [
- 'table' => 'mp_script_records',
- 'via' => ['local' => 'script_id', 'table' => 'mp_scripts', 'key' => 'id'],
- ],
- // 分镜 / 相邻分镜:mp_episode_segments.anime_id -> mp_animes
- 'segment_id' => $segmentDefine,
- 'prev_segment_id' => $segmentDefine,
- 'target_segment_id' => $segmentDefine,
- // 片段 / 相邻片段:mp_episode_segments.anime_id -> mp_animes
- 'act_id' => $actDefine,
- 'prev_act_id' => $actDefine,
- 'target_act_id' => $actDefine,
- // 画布节点:mp_canvas_nodes.canvas_id -> mp_canvases
- 'node_id' => [
- 'table' => 'mp_canvas_nodes',
- 'via' => ['local' => 'canvas_id', 'table' => 'mp_canvases', 'key' => 'id'],
- ],
- ],
- // 链式校验的批量参数(值可能是数组 / 逗号分隔 / JSON 数组)
- 'linked_array_params' => [
- // 节点关联:mp_canvas_nodes.canvas_id -> mp_canvases
- 'related_ids' => [
- 'table' => 'mp_canvas_nodes',
- 'via' => ['local' => 'canvas_id', 'table' => 'mp_canvases', 'key' => 'id'],
- ],
- ],
- /*
- |--------------------------------------------------------------------------
- | 按路由覆盖(参数名有歧义时使用)
- |--------------------------------------------------------------------------
- | 键为 $request->path() 的返回值(不含前导斜杠),例如 api/anime/deleteProduct
- */
- 'routes' => [
- 'api/anime/deleteProduct' => ['id' => ['table' => 'mp_products']],
- 'api/anime/editProduct' => ['id' => ['table' => 'mp_products']],
- 'api/anime/getFolderPath' => ['id' => ['table' => 'mp_products']],
- 'api/anime/renameFolder' => ['id' => ['table' => 'mp_products']],
- 'api/anime/moveRoleOrFolder' => ['id' => ['table' => 'mp_products']],
- 'api/anime/generateThreeView' => ['id' => ['table' => 'mp_products']],
- 'api/anime/globalProducts' => ['id' => ['table' => 'mp_products']],
- 'api/anime/taskCenter/detail' => ['task_id' => ['table' => 'mp_task_center']],
- 'api/anime/taskCenter/list' => ['task_id' => ['table' => 'mp_task_center']],
- ],
- ];
|