mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:46:00 +00:00
fix(backup-restore): snippet name (#4700)
This commit is contained in:
parent
ed89dd04c8
commit
6522720a96
@ -19,7 +19,7 @@ export class PluginBackupRestoreClient extends Plugin {
|
|||||||
title: this.t('Backup & Restore'),
|
title: this.t('Backup & Restore'),
|
||||||
icon: 'CloudServerOutlined',
|
icon: 'CloudServerOutlined',
|
||||||
Component: BackupAndRestoreList,
|
Component: BackupAndRestoreList,
|
||||||
aclSnippet: 'pm.backup.restore',
|
aclSnippet: 'pm.backup-restore',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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']);
|
||||||
|
});
|
||||||
|
});
|
@ -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)),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user