59 lines
2.1 KiB
JavaScript
59 lines
2.1 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 为 storage.stockout.updateInfo 添加 API 权限并授权。
|
||
*
|
||
* 权限 ID(固定):563 — storage.stockout.updateInfo 修改出库单信息
|
||
* 授权角色:经理(8)、仓库组-主管(26)、客服组-主管(28)、生产组-主管(29)、客服组-员工(30)
|
||
*/
|
||
module.exports = {
|
||
up: async queryInterface => {
|
||
// ===== 第一步:写入权限行 =====
|
||
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 (563, 'storage.stockout.updateInfo', NULL, 'storage.stockout.updateInfo', NULL, 'API:修改出库单信息', NULL, 0, 0, NULL, 'api', 0, 1, NOW(), NOW())
|
||
ON DUPLICATE KEY UPDATE path='storage.stockout.updateInfo', meta_title='API:修改出库单信息', type='api'
|
||
`);
|
||
|
||
// ===== 第二步:授权给经理及各主管/客服员工角色 =====
|
||
const roleIds = [ 8, 26, 28, 29, 30 ];
|
||
|
||
for (const roleId of roleIds) {
|
||
await queryInterface.sequelize.query(`
|
||
UPDATE wms_role
|
||
SET permissions = JSON_ARRAY_APPEND(permissions, '$', CAST(563 AS UNSIGNED)),
|
||
updated_at = NOW()
|
||
WHERE id = ${roleId}
|
||
AND permissions IS NOT NULL
|
||
AND permissions != '*'
|
||
AND permissions != '[]'
|
||
AND JSON_VALID(permissions) = 1
|
||
AND JSON_CONTAINS(permissions, '563', '$') = 0
|
||
`);
|
||
}
|
||
},
|
||
|
||
down: async queryInterface => {
|
||
const roleIds = [ 8, 26, 28, 29, 30 ];
|
||
|
||
for (const roleId of roleIds) {
|
||
await queryInterface.sequelize.query(`
|
||
UPDATE wms_role
|
||
SET permissions = JSON_REMOVE(
|
||
permissions,
|
||
JSON_UNQUOTE(JSON_SEARCH(permissions, 'one', '563'))
|
||
),
|
||
updated_at = NOW()
|
||
WHERE id = ${roleId}
|
||
AND permissions IS NOT NULL
|
||
AND permissions != '*'
|
||
AND permissions != '[]'
|
||
`);
|
||
}
|
||
|
||
await queryInterface.sequelize.query(`
|
||
DELETE FROM wms_permission WHERE id = 563
|
||
`);
|
||
},
|
||
};
|