Organization Administrator and Organization Owner


In Liferay, we can assign the users to the Organization and can assign the Organization role to the users.

There are 3 types of organization roles .



After assigning the role ,  If we want to fetch the users who has the Organization administartor.

Below is the code.

long orgId = ParamUtil.getLong(request, "organizationId");
List<User> users = OrganizationUtil.getUsers(orgId);
Group organizationGroup = OrganizationLocalServiceUtil.getOrganization(orgId).getGroup();
for(User user: users){
  long organizationGroupId = organizationGroup.getGroupId();
  if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
  user.getUserId(), organizationGroupId,
RoleConstants.ORGANIZATION_ADMINISTRATOR)) {
                  System.out.println("User is: "+ user);
                 
                }
}

First, we are fetching the users with Organizationid,

Using that Organization, we are fetching the "Group" , Whenever we create a Organization an entry will created in the "Group" table. (3rd line)

In 4th line we are iterating the users of the Organization
and the other lines we are checking weather user has role "Organization Admin" or not.




Comments

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate