mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:56:00 +00:00
fix: call root server hook after insertNewSchema (#282)
This commit is contained in:
parent
8b5ddf4501
commit
571b077840
@ -264,6 +264,38 @@ describe('server hooks', () => {
|
||||
expect(jsonTree['properties']['child2']).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should bind menu to role when insert new menu using insertAdjacent', async () => {
|
||||
await db.getRepository('roles').create({
|
||||
values: {
|
||||
name: 'role1',
|
||||
allowConfigure: true,
|
||||
allowNewMenu: true,
|
||||
},
|
||||
});
|
||||
|
||||
const schema = {
|
||||
'x-uid': 'root',
|
||||
name: 'root',
|
||||
properties: {},
|
||||
};
|
||||
|
||||
await uiSchemaRepository.insert(schema);
|
||||
|
||||
await uiSchemaRepository.insertAdjacent('afterBegin', 'root', {
|
||||
'x-uid': 'child2',
|
||||
name: 'child2',
|
||||
'x-server-hooks': [
|
||||
{
|
||||
type: 'onSelfCreate',
|
||||
method: 'bindMenuToRole',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const role1Menus = await db.getRepository<BelongsToManyRepository>('roles.menuUiSchemas', 'role1').find();
|
||||
expect(role1Menus.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should bind menu to role when create new menu', async () => {
|
||||
await db.getRepository('roles').create({
|
||||
values: {
|
||||
|
@ -594,6 +594,7 @@ export class UiSchemaRepository extends Repository {
|
||||
options.removeParentsIfNoChildren = false;
|
||||
} else {
|
||||
const schemaExists = await this.schemaExists(schema, { transaction });
|
||||
|
||||
if (schemaExists) {
|
||||
schema = lodash.isString(schema) ? schema : schema['x-uid'];
|
||||
} else {
|
||||
@ -711,6 +712,12 @@ export class UiSchemaRepository extends Repository {
|
||||
},
|
||||
);
|
||||
|
||||
const rootNode = nodes[0];
|
||||
if (rootNode['x-server-hooks']) {
|
||||
const rootModel = await this.findOne({ filter: { 'x-uid': rootNode['x-uid'] }, transaction });
|
||||
await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, rootModel, options);
|
||||
}
|
||||
|
||||
if (options?.returnNode) {
|
||||
return nodes;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user