'use strict'; /** * 为 apiApp 仓库 API 应用管理模块创建权限并授权给客服组-主管及以上角色。 * * 固定 ID(开发库 & 生产库 wms_permission 当前 max_id 均为 463): * 464 — 父级菜单 "API应用管理" * 465 — apiApp.list * 466 — apiApp.detail * 467 — apiApp.create * 468 — apiApp.update * 469 — apiApp.delete * 470 — apiApp.regenerateSecret * * 授权角色(permissions 不为 "*" 的 主管/经理 级角色): * 8 — 经理 * 26 — 仓库组-主管 * 28 — 客服组-主管 * 29 — 生产组-主管 */ module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { // ── 1. 插入父级权限 (type=web_pages, sort=1, status=1) ── await queryInterface.sequelize.query(` INSERT INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at) VALUES (464, 'apiApp', NULL, 'API应用管理', NULL, 'API应用管理', NULL, 0, 0, NULL, 'web_pages', 1, 1, NOW(), NOW()) `); // ── 2. 插入 6 个接口权限 ── const methods = [ [ 465, 'apiApp.list' ], [ 466, 'apiApp.detail' ], [ 467, 'apiApp.create' ], [ 468, 'apiApp.update' ], [ 469, 'apiApp.delete' ], [ 470, 'apiApp.regenerateSecret' ], ]; for (const [ id, method ] of methods) { await queryInterface.sequelize.query(` INSERT INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at) VALUES (${id}, '${method}', NULL, '${method}', NULL, 'API:${method}', NULL, 0, 0, 464, 'api', 0, 1, NOW(), NOW()) `); } // ── 3. 给 客服组-主管及以上角色 追加新权限 ID ── // 只更新 permissions 为显式列表(非 "*")的角色 const newIdSuffix = ', 465, 466, 467, 468, 469, 470'; await queryInterface.sequelize.query(` UPDATE wms_role SET permissions = CONCAT(LEFT(permissions, LENGTH(permissions) - 1), '${newIdSuffix}]') WHERE id IN (8, 26, 28, 29) AND permissions != '*' AND permissions IS NOT NULL AND LENGTH(permissions) > 2 `); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { // ── 1. 从角色权限中移除新增的 ID ── await queryInterface.sequelize.query(` UPDATE wms_role SET permissions = REPLACE(permissions, ', 465, 466, 467, 468, 469, 470', '') WHERE id IN (8, 26, 28, 29) `); // ── 2. 删除 6 个接口权限 ── await queryInterface.sequelize.query( 'DELETE FROM wms_permission WHERE id IN (465, 466, 467, 468, 469, 470)' ); // ── 3. 删除父级权限 ── await queryInterface.sequelize.query( 'DELETE FROM wms_permission WHERE id = 464' ); }, };