has-any-authorithy directive in jhipster application

别说谁变了你拦得住时间么 提交于 2019-12-21 23:02:13

问题


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?


回答1:


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"



回答2:


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




回答3:


In .html you can use this:

has-any-role="ROLE_ADMIN,ROLE_USER"



回答4:


And now in 2017 it is:

 <a *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_USER']">Test</a>



回答5:


In 2016 version it should be:

has-any-authority="ROLE_ADMIN,ROLE_USER"



回答6:


One more thing to add on that there should not space between the comma separated authorities, It did not work for me with a space after ",". As it considers space also part of authority string :

> has-any-authority="ROLE_ADMIN, ROLE_USER"
> has-any-authority="ROLE_ADMIN,ROLE_USER"

1st one will not work but second one will.



来源:https://stackoverflow.com/questions/36020206/has-any-authorithy-directive-in-jhipster-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!