I just started a project with the code generator "Jhipster". I'm trying to make a OneToMany relationship with the "User" relationship. I've looked at a lot of topics already but I can't find any working answers. Do you have any ideas? I even tried to go through an intermediate relationship but nothing works.
Thank you very much.
You can create relationships between your model entities and the special entity User. But you have to take into consideration the restrictions of this entity. As it appears in the JHipster documentation:
Tip: the User entity
Please note that the User entity, which is handled by JHipster, is
specific. You can do:
many-to-one relationships to this entity (a Car can have a many-to-one relationship to a User). This will generate a specific
query in your new entity repository, so you can filter your entity on
the current security user, which is a common requirement. On the
generated Angular/React client UI you will have a dropdown in Car to
select a User.
many-to-many and one-to-one relationships to the User entity, but the other entity must be the owner of the relationship (a Team can
have a many-to-many relationship to User, but only the team can
add/remove users, and a user cannot add/remove a team). On the
Angular/React client UI, you will also be able to select a User in a
multi-select box.
When using the UAA authentication type, you can only create
relationships to the User entity if the related entity is also within
the UAA microservice.
Related
First of all i'm new to Jhipster, i've read the official documentations but i still can't seem to find a solution to my problem (i've been stuck for almost 3 weeks now), that's why i decided to ask here for help.
So, i have an application where i need to create an entity called employee and i need to create a user account with the additional fields taht are specified in the employee entity, so in other words, when i fill the form to create a new employee that will not only create a new one but it will also automatically create a user account for that emplyee.
What i've tried doing up until now, is creating a new employee entity and link it with a OneToOne relashionship to the USER entity (created by Jhipster) but the thing is, in that case i would have to create a new user and then add the additional information for the employee, wheareas i need it to be in the same form, to create an employee and the user linked to it at the same time.
Any help will be really appreciated.
What you want to do is not supported off the shelf by JHipster, you have to code it manually.
In backend, you could do it by defining a DTO that combines both entities, a RestController that exposes it and a service that is responsible for orchestrating persistence.
In frontend, it's the same you have a component that contains the form to update this DTO and call your REST API.
Alternatively, if a User is always an Employee, you could also merge them in a single User entity.
Of course, this depends on which authentication type you selected which defines where users are managed.
I have a bunch of new entities defines but I want have a #OneToMany from User to one of these entities. Do I have to code it manually inside User or can I do it with the JDL studio ?
User entity is an special entity. As you can read in the JHipster documentation, not all types of relationships are allowed with User.
Tip: the User entity
Please note that the User entity, which is handled by JHipster, is
specific. You can do:
many-to-one relationships to this entity (a Car can have a many-to-one relationship to a User). This will generate a specific
query in your new entity repository, so you can filter your entity on
the current security user, which is a common requirement. On the
generated Angular/React client UI you will have a dropdown in Car to
select a User.
many-to-many and one-to-one relationships to the User entity, but the other entity must be the owner of the relationship (a Team can
have a many-to-many relationship to User, but only the team can
add/remove users, and a user cannot add/remove a team). On the
Angular/React client UI, you will also be able to select a User in a
multi-select box.
When using the UAA authentication type, you can only create
relationships to the User entity if the related entity is also within
the UAA microservice.
Other stackoverflow answers and bug reports have discussed setting a one direction relationship with the "user" entity but this won't work in a microservice using UAA authentication because there is no JHI_USER table in the schema.
You just can't because you're crossing service/system boundaries. Imagine you used LDAP or Active Directory to authenticate your users, the only thing you could do is to refer to a user by its login name which is basically an external ID. This is the same with UAA or between 2 microservices.
I'm using mongoose in my nodejs application, I have two Models: an Employee and Organization , I want to attribute some permissions to employees who belong to an organization like inviting or deleting other employees
I've created a mdoel ACL(_id,_empId,_orgId,[permissions]), but I'm not sure if will do the trick
What Models do I have to add in my database, knowing that I need just few permissions
I have an application where a user can be linked to several companies.
The manyToMany relationship with the company is a distinguished entity called Associate.
I'd like to give to this Associate entity the exact same role functionnality as my FOSUserBundle User entity has. Important : if a user has a role_manager for one company, it should not be given the rights to access specific features of another company he belongs to too.
Is there a clean way to do this?
I'd like to check for instance if $this->getUser->getAssociate->hasRole('ROLE_MANAGER') is true.
What if I give a role array to my entity Associate? I've read it's not secure enough? Why? What could someone do to break that security if anyway my users have to pass through FOS security login checks?
I've found an article where using a voter is suggested. But I don't want to filter routes, I really want to check the condition against the link between a user and a company, so if a voter is the solution, how would I use it?
EDIT: if a better solution not involving roles or with different logic exists, I am interested in learning about it!!
So in my case, I actually one user can actually be only linked to a maximum of 4 companies, each of a different kind defined by its category.
The official doc would suggest using ACL, defining a role for every company or store the data in the entity. cf first paragraphs of :
http://symfony.com/doc/current/cookbook/security/acl.html
I used a combination of roles and business logic. I've created roles for every type of company and since one user can only have one company per type, I just had to check for the type and the role-manager associated to the type.
See my voter here:
symfony2 call is_granted in voter : how to avoid an infinite loop?