WMS_MAIN/database/migrations/20260801120000-add-apiApp-permissions.js
liufumingren 76e25db7da feat(apiApp): 新增仓库 API 应用管理模块
- 新增 systems/apiApp.js 业务层:CRUD + AppKey/Secret 自动生成 + 仓库隔离
- 新增 systemMethods/apiApp.js 入口层:list/detail/create/update/delete/regenerateSecret
- 注册 methods/system.json API 文档 + changes 变更记录
- 新增迁移脚本:wms_permission 固定 ID 464-470 + 客服组主管及以上角色授权
2026-08-01 03:39:41 +08:00

81 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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'
);
},
};