From e7853c724e1c574baa57186b4f180d8bf049a78f Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 29 Oct 2022 14:07:51 +0800 Subject: [PATCH] fix: add sample plugins (#986) --- .../app/client/src/plugins/sample-command.ts | 1 + .../client/src/plugins/sample-custom-block.ts | 1 + .../client/src/plugins/sample-custom-page.ts | 1 + .../src/plugins/sample-custom-signup-page.ts | 1 + .../app/client/src/plugins/sample-hello.ts | 1 + .../client/src/plugins/sample-ratelimit.ts | 1 + .../client/src/plugins/sample-shop-actions.ts | 1 + .../client/src/plugins/sample-shop-events.ts | 1 + .../client/src/plugins/sample-shop-i18n.ts | 1 + .../src/plugins/sample-shop-modeling.ts | 1 + .../core/client/src/pm/PluginManagerLink.tsx | 2 +- packages/core/client/src/pm/index.tsx | 4 +- .../plugin-manager/PluginManagerRepository.ts | 1 + packages/plugins/acl/src/server.ts | 46 ++++++++++--------- packages/presets/nocobase/package.json | 10 ++++ packages/presets/nocobase/src/index.ts | 13 ++++++ packages/samples/shop-events/package.json | 2 +- 17 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 packages/app/client/src/plugins/sample-command.ts create mode 100644 packages/app/client/src/plugins/sample-custom-block.ts create mode 100644 packages/app/client/src/plugins/sample-custom-page.ts create mode 100644 packages/app/client/src/plugins/sample-custom-signup-page.ts create mode 100644 packages/app/client/src/plugins/sample-hello.ts create mode 100644 packages/app/client/src/plugins/sample-ratelimit.ts create mode 100644 packages/app/client/src/plugins/sample-shop-actions.ts create mode 100644 packages/app/client/src/plugins/sample-shop-events.ts create mode 100644 packages/app/client/src/plugins/sample-shop-i18n.ts create mode 100644 packages/app/client/src/plugins/sample-shop-modeling.ts diff --git a/packages/app/client/src/plugins/sample-command.ts b/packages/app/client/src/plugins/sample-command.ts new file mode 100644 index 000000000..d43b18ee7 --- /dev/null +++ b/packages/app/client/src/plugins/sample-command.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-command/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-custom-block.ts b/packages/app/client/src/plugins/sample-custom-block.ts new file mode 100644 index 000000000..affa4dda1 --- /dev/null +++ b/packages/app/client/src/plugins/sample-custom-block.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-custom-block/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-custom-page.ts b/packages/app/client/src/plugins/sample-custom-page.ts new file mode 100644 index 000000000..c76849a92 --- /dev/null +++ b/packages/app/client/src/plugins/sample-custom-page.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-custom-page/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-custom-signup-page.ts b/packages/app/client/src/plugins/sample-custom-signup-page.ts new file mode 100644 index 000000000..cee372da4 --- /dev/null +++ b/packages/app/client/src/plugins/sample-custom-signup-page.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-custom-signup-page/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-hello.ts b/packages/app/client/src/plugins/sample-hello.ts new file mode 100644 index 000000000..73f714dc4 --- /dev/null +++ b/packages/app/client/src/plugins/sample-hello.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-hello/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-ratelimit.ts b/packages/app/client/src/plugins/sample-ratelimit.ts new file mode 100644 index 000000000..7b138685d --- /dev/null +++ b/packages/app/client/src/plugins/sample-ratelimit.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-ratelimit/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-shop-actions.ts b/packages/app/client/src/plugins/sample-shop-actions.ts new file mode 100644 index 000000000..e4454a609 --- /dev/null +++ b/packages/app/client/src/plugins/sample-shop-actions.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-shop-actions/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-shop-events.ts b/packages/app/client/src/plugins/sample-shop-events.ts new file mode 100644 index 000000000..274df32cb --- /dev/null +++ b/packages/app/client/src/plugins/sample-shop-events.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-shop-events/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-shop-i18n.ts b/packages/app/client/src/plugins/sample-shop-i18n.ts new file mode 100644 index 000000000..01dddf816 --- /dev/null +++ b/packages/app/client/src/plugins/sample-shop-i18n.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-shop-i18n/client'; \ No newline at end of file diff --git a/packages/app/client/src/plugins/sample-shop-modeling.ts b/packages/app/client/src/plugins/sample-shop-modeling.ts new file mode 100644 index 000000000..ae46fd550 --- /dev/null +++ b/packages/app/client/src/plugins/sample-shop-modeling.ts @@ -0,0 +1 @@ +export { default } from '@nocobase/plugin-sample-shop-modeling/client'; \ No newline at end of file diff --git a/packages/core/client/src/pm/PluginManagerLink.tsx b/packages/core/client/src/pm/PluginManagerLink.tsx index d2ed7fe44..5d2aa70be 100644 --- a/packages/core/client/src/pm/PluginManagerLink.tsx +++ b/packages/core/client/src/pm/PluginManagerLink.tsx @@ -34,7 +34,7 @@ export const PluginManagerLink = () => { icon={} title={t('Plugin manager')} onClick={() => { - history.push('/admin/plugins'); + history.push('/admin/pm/list'); }} /> diff --git a/packages/core/client/src/pm/index.tsx b/packages/core/client/src/pm/index.tsx index 5c7d869f0..f9384afdc 100644 --- a/packages/core/client/src/pm/index.tsx +++ b/packages/core/client/src/pm/index.tsx @@ -198,7 +198,7 @@ const PluginList = (props) => { { - history.push(`/admin/plugins/${activeKey}`); + history.push(`/admin/pm/list/${activeKey}`); }} > @@ -348,7 +348,7 @@ export const PMProvider = (props) => { routes[1].routes.unshift( { type: 'route', - path: '/admin/plugins/:tabName?', + path: '/admin/pm/list/:tabName?', component: PluginList, }, { diff --git a/packages/core/server/src/plugin-manager/PluginManagerRepository.ts b/packages/core/server/src/plugin-manager/PluginManagerRepository.ts index dde22197c..6c25cabcb 100644 --- a/packages/core/server/src/plugin-manager/PluginManagerRepository.ts +++ b/packages/core/server/src/plugin-manager/PluginManagerRepository.ts @@ -52,6 +52,7 @@ export class PluginManagerRepository extends Repository { name: item.get('name'), version: item.get('version'), enabled: item.get('enabled'), + async: true, }); } } diff --git a/packages/plugins/acl/src/server.ts b/packages/plugins/acl/src/server.ts index a6a1aea0f..09f9ed20b 100644 --- a/packages/plugins/acl/src/server.ts +++ b/packages/plugins/acl/src/server.ts @@ -285,8 +285,32 @@ export class PluginACL extends Plugin { } }); + this.app.on('afterInstallPlugin', async (plugin) => { + if (plugin.getName() !== 'users') { + return; + } + const User = this.db.getCollection('users'); + await User.repository.update({ + values: { + roles: ['root', 'admin', 'member'], + }, + forceUpdate: true, + }); + + const RolesUsers = this.db.getCollection('rolesUsers'); + await RolesUsers.repository.update({ + filter: { + userId: 1, + roleName: 'root', + }, + values: { + default: true, + }, + }); + }); + this.app.on('beforeInstallPlugin', async (plugin) => { - if (plugin.constructor.name !== 'UsersPlugin') { + if (plugin.getName() !== 'users') { return; } const roles = this.app.db.getRepository('roles'); @@ -427,26 +451,6 @@ export class PluginACL extends Plugin { if (repo) { await repo.db2cm('roles'); } - - const User = this.db.getCollection('users'); - - await User.repository.update({ - values: { - roles: ['root', 'admin', 'member'], - }, - forceUpdate: true, - }); - - const RolesUsers = this.db.getCollection('rolesUsers'); - await RolesUsers.repository.update({ - filter: { - userId: 1, - roleName: 'root', - }, - values: { - default: true, - }, - }); } async load() { diff --git a/packages/presets/nocobase/package.json b/packages/presets/nocobase/package.json index 65bea5c39..2eede5ca2 100644 --- a/packages/presets/nocobase/package.json +++ b/packages/presets/nocobase/package.json @@ -25,6 +25,16 @@ "@nocobase/plugin-users": "0.8.0-alpha.1", "@nocobase/plugin-verification": "0.8.0-alpha.1", "@nocobase/plugin-workflow": "0.8.0-alpha.1", + "@nocobase/plugin-sample-command": "0.8.0-alpha.1", + "@nocobase/plugin-sample-custom-block": "0.8.0-alpha.1", + "@nocobase/plugin-sample-custom-page": "0.8.0-alpha.1", + "@nocobase/plugin-sample-custom-signup-page": "0.8.0-alpha.1", + "@nocobase/plugin-sample-hello": "0.8.0-alpha.1", + "@nocobase/plugin-sample-ratelimit": "0.8.0-alpha.1", + "@nocobase/plugin-sample-shop-actions": "0.8.0-alpha.1", + "@nocobase/plugin-sample-shop-events": "0.8.0-alpha.1", + "@nocobase/plugin-sample-shop-i18n": "0.8.0-alpha.1", + "@nocobase/plugin-sample-shop-modeling": "0.8.0-alpha.1", "@nocobase/server": "0.8.0-alpha.1" }, "repository": { diff --git a/packages/presets/nocobase/src/index.ts b/packages/presets/nocobase/src/index.ts index 4451ec94e..9762f0f8a 100644 --- a/packages/presets/nocobase/src/index.ts +++ b/packages/presets/nocobase/src/index.ts @@ -23,6 +23,19 @@ export class PresetNocoBase extends Plugin { builtIn: true, installed: true, }); + const samples = [ + 'sample-command', + 'sample-custom-block', + 'sample-custom-page', + 'sample-custom-signup-page', + 'sample-hello', + 'sample-ratelimit', + 'sample-shop-actions', + 'sample-shop-events', + 'sample-shop-i18n', + 'sample-shop-modeling', + ]; + await this.app.pm.add(samples, {}); await this.app.reload(); } diff --git a/packages/samples/shop-events/package.json b/packages/samples/shop-events/package.json index 48ff7b4ac..69675c3c2 100644 --- a/packages/samples/shop-events/package.json +++ b/packages/samples/shop-events/package.json @@ -1,5 +1,5 @@ { - "name": "@nocobase/plugin-sample-shop-hooks", + "name": "@nocobase/plugin-sample-shop-events", "version": "0.8.0-alpha.1", "main": "lib/server/index.js", "devDependencies": {