Checking weather the user has the role Organization Administrator.
Whenever we are creating the Organization we can assign the user to the Organization also we can assign the Organization role to the User.
As of now we have 2 roles.
1.Organization Owner.
2. Organization Administrator.
User who created the Organization will have the role "Organization Owner". But we need to manually assign the "Organization Administrator" to the user.
In programmatically to check weather user has roles or not here is the code.
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
try {
Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(),RoleConstants.ORGANIZATION_ADMINISTRATOR); //Get the Role
List<UserGroupRole> userGroupList = UserGroupRoleLocalServiceUtil.getUserGroupRoles(themeDisplay.getUserId()); //Getting the Roles of the User
for(UserGroupRole userGroupRole :userGroupList) { //Iterating the loop
if(role.getRoleId() == userGroupRole.getRoleId()) { //If roles are equal then user has the Organization Admin
System.out.println("roleId is"+role.getRoleId()+"role Name"+role.getName());
}
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
Comments
Post a Comment