diff --git a/packages/app/src/api/migrate.ts b/packages/app/src/api/migrate.ts index 19a55a998..0d63500ad 100644 --- a/packages/app/src/api/migrate.ts +++ b/packages/app/src/api/migrate.ts @@ -3,9 +3,9 @@ const args = process.argv; // @ts-ignore global.sync = { - force: true, + force: false, alter: { - drop: true, + drop: false, }, }; diff --git a/packages/app/src/api/migrations/add-permissions.ts b/packages/app/src/api/migrations/add-permissions.ts new file mode 100644 index 000000000..5e5ab5c87 --- /dev/null +++ b/packages/app/src/api/migrations/add-permissions.ts @@ -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, + }, + ]); + } + } + +})(); diff --git a/packages/plugin-collections/src/collections/fields.ts b/packages/plugin-collections/src/collections/fields.ts index 62e3ab084..597716938 100644 --- a/packages/plugin-collections/src/collections/fields.ts +++ b/packages/plugin-collections/src/collections/fields.ts @@ -311,7 +311,7 @@ export default { interface: 'string', type: 'virtual', name: 'labelField', - title: '要关联的字段', + title: '要显示的字段', required: true, component: { type: 'remoteSelect', diff --git a/packages/plugin-collections/src/collections/tabs.ts b/packages/plugin-collections/src/collections/tabs.ts index 85a78c845..ef3a51859 100644 --- a/packages/plugin-collections/src/collections/tabs.ts +++ b/packages/plugin-collections/src/collections/tabs.ts @@ -162,6 +162,7 @@ export default { name: 'viewName', title: '视图', labelField: 'title', + required: true, // valueField: 'name', component: { type: 'remoteSelect', diff --git a/packages/plugin-permissions/src/collections/roles.ts b/packages/plugin-permissions/src/collections/roles.ts index 40230ba9e..7241f0f94 100644 --- a/packages/plugin-permissions/src/collections/roles.ts +++ b/packages/plugin-permissions/src/collections/roles.ts @@ -131,7 +131,7 @@ export default { { type: 'association', name: 'pages', - title: '页面权限', + title: '系统菜单权限', association: 'pages', viewName: 'permissionTable', },