Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

has-any-authorithy directive in jhipster application

I have created a new role ROLE_SUPERUSER in my jhipster application. I want a specific navbar menu to be visible to only admin and my new user. I tried using has-any-authorithy as given in authority.directive.js but its not working.

I am using it in HTML like

has-any-authorithy="['ROLE_ADMIN','ROLE_SUPERUSER']"

Am I missing anything?

like image 210
Mudit bhaintwal Avatar asked Nov 29 '25 00:11

Mudit bhaintwal


2 Answers

Code says:

authorities = attrs.hasAnyAuthority.replace(/\s+/g, '').split(',');

So it seems that the directive expects one string and not an array.

Try this:

has-any-authority="ROLE_ADMIN, ROLE_SUPERUSER"
like image 119
Gaël Marziou Avatar answered Dec 01 '25 00:12

Gaël Marziou


There is a better way to do this. You can create a service only for this directive and return a "joined" array like this :

code in your service :

this.feature_1 = {
    access: [ROLES.ROLE_ADMIN, ROLES.ROLE_SUPERUSER].join()
};

ROLES is a constant and an array of app roles defined in app.constants.js.

And in your template :

has-any-roles="{{accessService.feature_1.access}}"

By doing this, if you want to change the access rights, you have only to modify the accessService

like image 27
slim Avatar answered Dec 01 '25 01:12

slim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!