Generator-jhipster: adding relationships to Authority

Created on 31 Dec 2019  路  7Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

It is possible to create relationships from user-generated entities to the built-in User entity, if a user wants to extend the user without modifying the actual user entity. The same thing is not possible to do with the Authority entity, because of:

  1. JDL import is not aware of the Authority exception. So it either complains about that the Authority entity is missing. If we add an entity Authority {}, it completely overwrites the actual authority and breaks the code deeply.
  2. You can add 'authority-relations' manually using jhipster entity without errors. However, the generarator is not aware of the Authority exception either. The generated code is also broken. It seems, that the manual generator does not check if the related entity actually exist
Motivation for or Use Case

Adding a relationship to a built-in entity is one way of extending the entity without changing its generated code. It has been possible to do so for a long time already for the user. But not for its corresponding authority entity.

In a current use-case, I was designing a system, which is capable of handling a bigger amount of permissions which itself can be categorized in groups. In addition to this, there are a few more extensions on the authority itself. With this issue here, it is not possible to realize this scenario without extensively changing the generated code.

Reproduce the error

  1. with JDL

create the following model:


JDL definitions

entity AuthorityGroup {
name String required
description String required
}

relationship ManyToMany {
AuthorityGroup{authority(name)} to Authority
}


jhipster import-jdl will fail to generate an application because Authority is missing. Here is the actual error:


Errorlog of jhipster import-jdl app.jdl

Error: Can't add invalid relationship. Error: In the Many-to-Many relationship from AuthorityGroup to Authority, only bidirectionality is supported. The injected field in the source entity is 'authority(name)' and the injected field in the destination entity is not set.
Error while parsing applications and entities from the JDL Error: Can't add invalid relationship. Error: In the Many-to-Many relationship from AuthorityGroup to Authority, only bidirectionality is supported. The injected field in the source entity is 'authority(name)' and the injected field in the destination entity is not set.
Error: Can't add invalid relationship. Error: In the Many-to-Many relationship from AuthorityGroup to Authority, only bidirectionality is supported. The injected field in the source entity is 'authority(name)' and the injected field in the destination entity is not set.

  1. manually

If you add the AuthorityGroup entity manually by using jhipster entity, the code generation will work without any issues, but the generated code will fail in angular frontend code:


Errorlog when building frontend code

ERROR in ./src/main/webapp/app/entities/authority-group/authority-group-update.component.ts
Module not found: Error: Can't resolve 'app/entities/authority/authority.service' in '/tmp/jtest/src/main/webapp/app/entities/authority-group'

ERROR in /tmp/jtest/src/main/webapp/app/entities/authority-group/authority-group-update.component.ts
ERROR in /tmp/jtest/src/main/webapp/app/entities/authority-group/authority-group-update.component.ts(11,28):
TS2307: Cannot find module 'app/shared/model/authority.model'.

ERROR in /tmp/jtest/src/main/webapp/app/entities/authority-group/authority-group-update.component.ts
ERROR in /tmp/jtest/src/main/webapp/app/entities/authority-group/authority-group-update.component.ts(12,34):
TS2307: Cannot find module 'app/entities/authority/authority.service'.

ERROR in /tmp/jtest/src/main/webapp/app/shared/model/authority-group.model.ts
ERROR in /tmp/jtest/src/main/webapp/app/shared/model/authority-group.model.ts(1,28):
TS2307: Cannot find module 'app/shared/model/authority.model'.


Related issues

Suggest a Fix

Adding similar handling as we do with User today.

JHipster Version(s)


6.6.0

JHipster configuration

default settings

  • [X] Checking this box is mandatory (this is just to show you read everything)

$$ bug-bounty $$ $100 area relationships security

Most helpful comment

I've actually done everything needed in JCore two days ago, I try to push it to a PR tonight, as it worked great. The harder part of this is in the generator, but even here I'm done with the server generator and now I am preparing my self for the frontend part (in particular React, as I've never used React before)

But I'm almost done with it

All 7 comments

It has always been the case since years.
So for me, it's not a bug but a feature.

The implementation could be similar to what we do for User, but it will impact jhipster-core, jdl, etc

Do you plan to take this ticket @xetys ?

Maybe, I'm gonna check how my schedule is

I'm working on this already

Hi @xetys! I'm available if you need any help dealing with the JCore part.

I've actually done everything needed in JCore two days ago, I try to push it to a PR tonight, as it worked great. The harder part of this is in the generator, but even here I'm done with the server generator and now I am preparing my self for the frontend part (in particular React, as I've never used React before)

But I'm almost done with it

Can you add/supply code/examples, so that we can test theis addition.

I'm closing this issue due to inactivity. Please re-open if you have a PR to fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pascalgrimaud picture pascalgrimaud  路  4Comments

frantzynicolas picture frantzynicolas  路  3Comments

kaidohallik picture kaidohallik  路  3Comments

tomj0101 picture tomj0101  路  3Comments

chegola picture chegola  路  4Comments