diff --git a/packages/plugins/@nocobase/plugin-backup-restore/src/client/index.tsx b/packages/plugins/@nocobase/plugin-backup-restore/src/client/index.tsx index e0515ff7f1..08ad4595f5 100644 --- a/packages/plugins/@nocobase/plugin-backup-restore/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-backup-restore/src/client/index.tsx @@ -19,7 +19,7 @@ export class PluginBackupRestoreClient extends Plugin { title: this.t('Backup & Restore'), icon: 'CloudServerOutlined', Component: BackupAndRestoreList, - aclSnippet: 'pm.backup.restore', + aclSnippet: 'pm.backup-restore', }); } } diff --git a/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/migrations/update-snippets.test.ts b/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/migrations/update-snippets.test.ts new file mode 100644 index 0000000000..0bab452bd0 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/migrations/update-snippets.test.ts @@ -0,0 +1,50 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Database, MigrationContext } from '@nocobase/database'; +import updateSnippetName from '../../migrations/20240618103927-update-snippet-name'; + +import { createMockServer, MockServer } from '@nocobase/test'; + +describe('migration snippet name test', () => { + let app: MockServer; + let db: Database; + + beforeEach(async () => { + app = await createMockServer({ + plugins: ['nocobase'], + }); + db = app.db; + }); + + afterEach(async () => { + await app.destroy(); + }); + + it('should change snippet name', async () => { + await db.getRepository('roles').create({ + values: { + name: 'test', + snippets: ['pm.backup.restore'], + }, + }); + + const migration = new updateSnippetName({ db } as MigrationContext); + migration.context.app = app; + await migration.up(); + + const role = await db.getRepository('roles').findOne({ + filter: { + name: 'test', + }, + }); + + expect(role.get('snippets')).toEqual(['pm.backup-restore']); + }); +}); diff --git a/packages/plugins/@nocobase/plugin-backup-restore/src/server/migrations/20240618103927-update-snippet-name.ts b/packages/plugins/@nocobase/plugin-backup-restore/src/server/migrations/20240618103927-update-snippet-name.ts new file mode 100644 index 0000000000..f98720ad98 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-backup-restore/src/server/migrations/20240618103927-update-snippet-name.ts @@ -0,0 +1,40 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Migration } from '@nocobase/server'; + +export default class extends Migration { + on = 'afterLoad'; // 'beforeLoad' or 'afterLoad' + appVersion = '<1.2.4-alpha'; + + async up() { + const roles = await this.db.getRepository('roles').find(); + for (const role of roles) { + const snippets = await role.get('snippets'); + let roleNeedsUpdate = false; + for (let i = 0; i < snippets.length; i++) { + if (snippets[i].includes('pm.backup.restore')) { + snippets[i] = snippets[i].replace('pm.backup.restore', 'pm.backup-restore'); + roleNeedsUpdate = true; + } + } + + if (roleNeedsUpdate) { + await this.db.getRepository('roles').update({ + filter: { + name: role.get('name'), + }, + values: { + snippets: JSON.parse(JSON.stringify(snippets)), + }, + }); + } + } + } +}