Reputation: 1217
I have a patient list portlet and a link in the portlet to "add a new patient" .
Question : The link "add a new patient" should be displayed only for users who are having a specific role.
I really appreciate if there are any example or links that could be shared or any ideas on how to achieve this in liferay portal.
Thank you, Sri
Upvotes: 1
Views: 908
Reputation: 31
Get the role Ids of the user from themedisplay and compare with your role Id:
<%
ThemeDisplay td =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long[] roleIds = td.getUser().getRoleIds();
boolean isRoleExist = false;
for(Long roleid:roleIds){
if(roleid == <your roleid here>){ // role id u can get it from liferay ROLE_ table inside db
isRoleExist = true;
}
}
%>
<% if (isRoleExist){ %>
<a href="#">add a new patient</a>
<%}%>
Upvotes: 2
Reputation: 4210
You should create portlet-level permission for adding patient entry(e.g. ADD_PATIENT_ENTRY). Then you can assign this permission to some Roles.
You can verify if current user has permission or not by code
PortletPermission.contains(permissionChecker, PAGELAYOUTID, PORTLETID, "ADD_PATIENT_ENTRY")
Refer to link
Upvotes: 2