diff --git a/generators/base-application/generator.spec.ts b/generators/base-application/generator.spec.ts index 09294ea1e900..55c8b9dcdd6c 100644 --- a/generators/base-application/generator.spec.ts +++ b/generators/base-application/generator.spec.ts @@ -268,11 +268,11 @@ describe(`generator - ${generator}`, () => { expect(preparingEachEntityField).toHaveBeenNthCalledWith(28, { ...fieldArg, description: 'Two#name' }); expect(preparingEachEntityField).toHaveBeenNthCalledWith(29, { ...fieldArg, description: 'Three#id' }); - expect(preparingEachEntityRelationship).toBeCalledTimes(5); + expect(preparingEachEntityRelationship).toBeCalledTimes(4); // Ommit UserManagement relationships - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(3, { ...relationshipArg, description: 'One#two' }); - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(4, { ...relationshipArg, description: 'Two#one' }); - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(5, { ...relationshipArg, description: 'Two#three' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(2, { ...relationshipArg, description: 'One#two' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(3, { ...relationshipArg, description: 'Two#one' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(4, { ...relationshipArg, description: 'Two#three' }); expect(postPreparingEachEntity).toBeCalledTimes(6); expect(postPreparingEachEntity).toHaveBeenNthCalledWith(1, { ...entityArg, entityName: 'User' }); @@ -519,11 +519,11 @@ describe(`generator - ${generator}`, () => { expect(preparingEachEntityField).toHaveBeenNthCalledWith(28, { ...fieldArg, description: 'Two#name' }); expect(preparingEachEntityField).toHaveBeenNthCalledWith(29, { ...fieldArg, description: 'Three#id' }); - expect(preparingEachEntityRelationship).toBeCalledTimes(5); + expect(preparingEachEntityRelationship).toBeCalledTimes(4); // Ommit UserManagement relationships - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(3, { ...relationshipArg, description: 'One#two' }); - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(4, { ...relationshipArg, description: 'Two#one' }); - expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(5, { ...relationshipArg, description: 'Two#three' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(2, { ...relationshipArg, description: 'One#two' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(3, { ...relationshipArg, description: 'Two#one' }); + expect(preparingEachEntityRelationship).toHaveBeenNthCalledWith(4, { ...relationshipArg, description: 'Two#three' }); expect(postPreparingEachEntity).toBeCalledTimes(6); expect(postPreparingEachEntity).toHaveBeenNthCalledWith(1, { ...entityArg, entityName: 'User' }); diff --git a/generators/bootstrap-application-base/utils.js b/generators/bootstrap-application-base/utils.js index b9c5518cc955..8ec8b9ad1892 100644 --- a/generators/bootstrap-application-base/utils.js +++ b/generators/bootstrap-application-base/utils.js @@ -177,17 +177,6 @@ export function createUserEntity(customUserData = {}, application) { ...(user.auditableEntity ? auditableEntityFields() : []), ]); - if (application.generateBuiltInAuthorityEntity) { - addOrExtendRelationships(user.relationships, [ - { - otherEntityName: 'Authority', - relationshipName: 'authority', - relationshipType: 'many-to-many', - relationshipIgnoreBackReference: true, - }, - ]); - } - return user; } @@ -204,7 +193,8 @@ export function createUserManagementEntity(customUserManagementData = {}, applic field.fieldType = field.fieldType ?? getDatabaseTypeData(application.databaseType).defaultPrimaryKeyType; } } - return { + + const userManagement = { ...user, skipClient: true, skipServer: true, @@ -218,6 +208,19 @@ export function createUserManagementEntity(customUserManagementData = {}, applic builtInUser: false, builtInUserManagement: true, }; + + if (application.generateBuiltInAuthorityEntity) { + addOrExtendRelationships(userManagement.relationships, [ + { + otherEntityName: 'Authority', + relationshipName: 'authority', + relationshipType: 'many-to-many', + relationshipIgnoreBackReference: true, + }, + ]); + } + + return userManagement; } export function createAuthorityEntity(customAuthorityData = {}, application) {