feat: add permissions migration

This commit is contained in:
chenos 2021-01-18 19:06:31 +08:00
parent 95be672222
commit 1d5c39e0e8
5 changed files with 70 additions and 4 deletions

View File

@ -3,9 +3,9 @@ const args = process.argv;
// @ts-ignore
global.sync = {
force: true,
force: false,
alter: {
drop: true,
drop: false,
},
};

View File

@ -0,0 +1,65 @@
import api from '../app';
import Database from '@nocobase/database';
(async () => {
await api.loadPlugins();
const database: Database = api.database;
await api.database.sync();
const [Collection, Page, Role] = database.getModels(['collections', 'pages', 'roles']);
const tables = database.getTables();
for (let table of tables) {
console.log(table.getName());
await Collection.import(table.getOptions(), { update: true, migrate: false });
}
const parent = await Page.findOne({
where: {
path: '/settings',
}
});
const roles = await Role.bulkCreate([
{ title: '系统开发组' },
{ title: '数据管理组' },
{ title: '普通用户组' },
{ title: '未登录用户组' },
]);
await Page.create({
title: '权限组配置',
type: 'collection',
collection: 'roles',
path: '/settings/roles',
icon: 'TableOutlined',
sort: 120,
showInMenu: true,
parent_id: parent.id,
});
const Scope = database.getModel('actions_scopes');
const collections = await Collection.findAll();
for (const collection of collections) {
const count = await collection.countScopes();
if (count === 0) {
await Scope.bulkCreate([
{
title: '全部数据',
filter: {},
collection_name: collection.name,
},
{
title: '用户自己的数据',
filter: {
"created_by_id.$currentUser": true,
},
collection_name: collection.name,
},
]);
}
}
})();

View File

@ -311,7 +311,7 @@ export default {
interface: 'string',
type: 'virtual',
name: 'labelField',
title: '要关联的字段',
title: '要显示的字段',
required: true,
component: {
type: 'remoteSelect',

View File

@ -162,6 +162,7 @@ export default {
name: 'viewName',
title: '视图',
labelField: 'title',
required: true,
// valueField: 'name',
component: {
type: 'remoteSelect',

View File

@ -131,7 +131,7 @@ export default {
{
type: 'association',
name: 'pages',
title: '页面权限',
title: '系统菜单权限',
association: 'pages',
viewName: 'permissionTable',
},