From 18e7d5ba7776d10845b574bcf45553929957e082 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 27 Jan 2021 14:02:46 +0800 Subject: [PATCH] fix: reload users collection options on initialization --- packages/app/src/api/index.ts | 3 +++ .../migrations/add-lock-to-actions-scopes.ts | 19 +++++++++++++++++++ packages/plugin-pages/src/actions/getView.ts | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/app/src/api/migrations/add-lock-to-actions-scopes.ts diff --git a/packages/app/src/api/index.ts b/packages/app/src/api/index.ts index be05ef986..44923e15f 100644 --- a/packages/app/src/api/index.ts +++ b/packages/app/src/api/index.ts @@ -77,6 +77,9 @@ api.resourcer.use(async (ctx: actions.Context, next) => { }); await api.database.getModel('collections').load({skipExisting: true}); + await api.database.getModel('collections').load({where: { + name: 'users', + }}); api.listen(process.env.HTTP_PORT, () => { console.log(`http://localhost:${process.env.HTTP_PORT}/`); }); diff --git a/packages/app/src/api/migrations/add-lock-to-actions-scopes.ts b/packages/app/src/api/migrations/add-lock-to-actions-scopes.ts new file mode 100644 index 000000000..0e8ffc48e --- /dev/null +++ b/packages/app/src/api/migrations/add-lock-to-actions-scopes.ts @@ -0,0 +1,19 @@ +import api from '../app'; +import Database from '@nocobase/database'; + +(async () => { + await api.loadPlugins(); + const database: Database = api.database; + await api.database.sync({ + tables: ['actions_scopes'], + }); + + const [Collection, User, Role] = database.getModels(['collections', 'users', 'roles']); + + const tables = database.getTables(['actions_scopes']); + + for (let table of tables) { + console.log(table.getName()); + await Collection.import(table.getOptions(), { update: true, migrate: false }); + } +})(); diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 6232326b0..58acca9a3 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -211,7 +211,7 @@ export default async (ctx, next) => { let throughName; const { resourceKey: resourceKey2, associatedName, resourceFieldName, associatedKey } = values; // TODO: 暂时不处理 developerMode 和 internal 的情况 - const permissions = (ctx.ac.isRoot() || collection.developerMode || collection.internal) + const permissions = (await ctx.ac.isRoot() || collection.developerMode || collection.internal) ? await ctx.ac.getRootPermissions() : await ctx.ac.can(resourceName).permissions(); ctx.listFields = []; @@ -235,6 +235,7 @@ export default async (ctx, next) => { } } // console.log({ + // a: (await ctx.ac.isRoot() || collection.developerMode || collection.internal), // listFields: ctx.listFields, // createFields: ctx.createFields, // updateFields: ctx.updateFields,