WMS_MAIN/database/migrations/20260805150000-add-group-api-permissions.js

54 lines
1.8 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';
/**
* 为 inbox.group.* 方法创建 API 权限记录。
*
* 固定 ID(当前 max_id=494):
* 495 — inbox.group.list
* 496 — inbox.group.disable
* 497 — inbox.group.update
* 498 — inbox.group.messages
*/
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const methods = [
[ 495, 'inbox.group.list' ],
[ 496, 'inbox.group.disable' ],
[ 497, 'inbox.group.update' ],
[ 498, 'inbox.group.messages' ],
];
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, NULL, 'api', 0, 1, NOW(), NOW())
ON DUPLICATE KEY UPDATE path='${method}', meta_title='API:${method}', type='api'
`);
}
// 授权给客服组-主管及以上角色
const newIdSuffix = ', 495, 496, 497, 498';
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) {
await queryInterface.sequelize.query(
'DELETE FROM wms_permission WHERE id IN (495, 496, 497, 498)'
);
await queryInterface.sequelize.query(`
UPDATE wms_role
SET permissions = REPLACE(permissions, ', 495, 496, 497, 498', '')
WHERE id IN (8, 26, 28, 29)
`);
},
};