Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding relationships to Authority #11062

Closed
1 task done
xetys opened this issue Dec 31, 2019 · 8 comments
Closed
1 task done

adding relationships to Authority #11062

xetys opened this issue Dec 31, 2019 · 8 comments
Assignees
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: relationships theme: security $100 https://www.jhipster.tech/bug-bounties/
Milestone

Comments

@xetys
Copy link
Member

xetys commented Dec 31, 2019

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

  • Checking this box is mandatory (this is just to show you read everything)
@pascalgrimaud
Copy link
Member

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 ?

@xetys
Copy link
Member Author

xetys commented Jan 2, 2020

Maybe, I'm gonna check how my schedule is

@pascalgrimaud pascalgrimaud added $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $100 https://www.jhipster.tech/bug-bounties/ labels Jan 10, 2020
@xetys xetys self-assigned this Jan 14, 2020
@xetys
Copy link
Member Author

xetys commented Jan 14, 2020

I'm working on this already

@MathieuAA
Copy link
Member

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

@xetys
Copy link
Member Author

xetys commented Jan 16, 2020

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

xetys added a commit to xetys/jhipster-core that referenced this issue Jan 21, 2020
xetys added a commit to xetys/generator-jhipster that referenced this issue Jan 21, 2020
and ensures using the correct fields in generated files

fix jhipster#11062
@xetys xetys mentioned this issue Jan 21, 2020
4 tasks
@kurtwilbies
Copy link

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

xetys added a commit to xetys/generator-jhipster that referenced this issue Feb 24, 2020
and ensures using the correct fields in generated files

fix jhipster#11062
xetys added a commit to xetys/generator-jhipster that referenced this issue May 18, 2020
and ensures using the correct fields in generated files

fix jhipster#11062
@mraible
Copy link
Contributor

mraible commented Oct 8, 2020

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

@yacosta738
Copy link
Contributor

I need help with this issue #14873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: feature request 💡 $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ theme: relationships theme: security $100 https://www.jhipster.tech/bug-bounties/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants