Skip to main content

Jhipster AngularJs2 Show Entities Based On ROLE_USER

How To Hide The Jhipster Entities Based On User roles ,For example some entities are not required to show normal users .That means we want to hide that particular entity when ever user logged in and his role is normal user ( ROLE_USER ) .


Follow the below steps to display or hide the entities based on user roles .

open navbar.component.html page which is present at the below path

\src\main\webapp\app\layouts\navbar\navbar.component.html


add the below condition for example

<ul class="dropdown-menu" ngbDropdownMenu>
<li *jhiHasAnyAuthority="'ROLE_ADMIN'" uiSrefActive="active">
<a class="dropdown-item" routerLink="admin" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Admin</span>
</a>
</li>
<li *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_USER']" uiSrefActive="active">
<a class="dropdown-item" routerLink="camp" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Camp</span>
</a>
</li>
<li *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_DONAR']" uiSrefActive="active">
<a class="dropdown-item" routerLink="donar" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Donar</span>
</a>
</li>
<li *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_RECIPIENT']" uiSrefActive="active">
<a class="dropdown-item" routerLink="recipient" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Recipient</span>
</a>
</li>
<li *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_USER']" uiSrefActive="active">
<a class="dropdown-item" routerLink="request" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Request</span>
</a>
</li>
<li *jhiHasAnyAuthority="'ROLE_ADMIN'" uiSrefActive="active">
<a class="dropdown-item" routerLink="staff" (click)="collapseNavbar()">
<i class="fa fa-fw fa-asterisk" aria-hidden="true"></i>
<span >Staff</span>
</a>
</li>
<!-- jhipster-needle-add-entity-to-menu - JHipster will add entities to the menu here -->
</ul>


Comments

Popular posts from this blog

Angular cli ng command is not working

Problem : angular cli command  ng is not working

C:\Windows\System32>ng
'ng' is not recognized as an internal or external command,
operable program or batch file.

Solution :

update .npmrc file at C:\Users\{USERNAME}
with the below line

prefix=${APPDATA}\npm

warning: LF will be replaced by CRLF in

Problem :

The file will have its original line endings in your working directory







Solution:

step1) open .gitconfig file

step2) paste the below code


[core]
autocrlf = false
[filter "lfs"]
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process


Download file with extension for internet explorer and chrome using javascript

SOLVED Problem Statement :
Internet explorer download file does not shows file extension

Solution : java script code that append file type extension

function save() { var fileUrl = "${fileUrl}"; var fileName = "${fileName}"; var mimeType = "${mimeType}"; var ie = navigator.userAgent.match(/MSIE\s([\d.]+)/), ie11 = navigator.userAgent .match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/), ieEDGE = navigator.userAgent .match(/Edge/g), ieVer = (ie ? ie[1] : (ie11 ? 11 : (ieEDGE ? 12 : -1))); if (ie && ieVer < 10) { console.log("No blobs on IE ver<10"); return; } if (ieVer > -1) { console.log(" blobs on IE ver>10"); //window.open(fileUrl,"_self");        var xhr = new XMLHttpRequest(); xhr.open('GET', fileUrl, true); xhr.responseType = 'blob'; xhr.onload = function(e) { if (this.status == 200) { var myBlob = this.response; downloadFileForIE(myBlob, fileName, mimeType); } }; xh…