mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 04:38:15 +08:00
feat: add permissions migration
This commit is contained in:
parent
95be672222
commit
1d5c39e0e8
@ -3,9 +3,9 @@ const args = process.argv;
|
||||
|
||||
// @ts-ignore
|
||||
global.sync = {
|
||||
force: true,
|
||||
force: false,
|
||||
alter: {
|
||||
drop: true,
|
||||
drop: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
65
packages/app/src/api/migrations/add-permissions.ts
Normal file
65
packages/app/src/api/migrations/add-permissions.ts
Normal 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,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
@ -311,7 +311,7 @@ export default {
|
||||
interface: 'string',
|
||||
type: 'virtual',
|
||||
name: 'labelField',
|
||||
title: '要关联的字段',
|
||||
title: '要显示的字段',
|
||||
required: true,
|
||||
component: {
|
||||
type: 'remoteSelect',
|
||||
|
@ -162,6 +162,7 @@ export default {
|
||||
name: 'viewName',
|
||||
title: '视图',
|
||||
labelField: 'title',
|
||||
required: true,
|
||||
// valueField: 'name',
|
||||
component: {
|
||||
type: 'remoteSelect',
|
||||
|
@ -131,7 +131,7 @@ export default {
|
||||
{
|
||||
type: 'association',
|
||||
name: 'pages',
|
||||
title: '页面权限',
|
||||
title: '系统菜单权限',
|
||||
association: 'pages',
|
||||
viewName: 'permissionTable',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user