0

I am trying to get a list of users for a Liferay 6.2 site, but I can't seem to find a way to do so. I have the groupId, which I know is correct, since I can get the documents, but the query only gets directly added users, not inherited ones (e.g. from the organisation).

I just use the method UserLocalService.getGroupUsers(groupId), then loop through them. How can I get all users (i.e. the same as Site Memberships in Site Administration, but without the paging)?

update

I have a Liferay portal instance, it has several organisations with associated sites. Org A has User 1, 2, 3 etc. Org B has User 4, 5, 6. They have the same company id's (since they are part of the same portal), but different group id's. I only want those who are in Org A (directly added, part of any user groups or organisations which have been assigned). The site could also be a non organisation site (i.e. Org A and B assigned, but not any others, e.g. a new Org C), for document sharing between organisations. From my understanding, all sites are internally known as groups, from doing work with document libraries.

SamWM
  • 5,196
  • 12
  • 56
  • 85
  • disabling paging is done by using the value -1 as start and end .. or better the queryutil.ALL_POS (https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portal/kernel/dao/orm/QueryUtil.html) – André Oct 20 '19 at 10:11

2 Answers2

1

You could do two calls to get the site and the organization users, then one call to get the assigned organizations, iterate through them and get their users. Then combine all the results:

HashSet<User> groupAndOrganizationUsersSet = new LinkedHashSet<>();

groupAndOrganizationUsersSet.addAll(UserLocalServiceUtil.getGroupUsers(groupId));
groupAndOrganizationUsersSet.addAll(UserLocalServiceUtil.getOrganizationUsers(
        GroupLocalServiceUtil.getGroup(groupId).getOrganizationId()));

for (Organization organization : 
        OrganizationLocalServiceUtil.getGroupOrganizations(groupId)) {

    groupAndOrganizationUsersSet.addAll(UserLocalServiceUtil.getOrganizationUsers(
            organization.getOrganizationId()));
}

List<User> groupAndOrganizationUsers = new ArrayList<>(groupAndOrganizationUsersSet);
mirrom
  • 140
  • 1
  • 9
  • Works if I replace the empty <> with , but only works for sites with one organisation – SamWM Oct 24 '19 at 17:13
  • AFAIK an organization can only have one specific site connected to it. So I don't get what you mean with _The site could also be a non organisation site (i.e. Org A and B assigned, but not any others, e.g. a new Org C)_. How do you assign multiple organizations to a site? I think an organization can link to one specific site, but a site is not linked and cannot be linked afterwards to an organization. But I may be wrong here! Could you please specify what exactly your setup looks like and what you want to achieve? – mirrom Oct 25 '19 at 09:59
  • On the Site Memberships page, I add organisations via the Organizations tab, which then allows all those users access. I don't currently add User Groups, but may in the futute. – SamWM Oct 25 '19 at 10:40
  • Thanks, I learned something new today :) I will edit my answer. – mirrom Oct 25 '19 at 13:00
0

Maybe this

UserLocalServiceUtil.getCompanyUsers(long companyId, int start, int end)

for a standard non pagination result (you know the risk) use

UserLocalServiceUtil.getCompanyUsers(PortalUtil.getDefaultCompanyId(), -1, -1)
Daniele Baggio
  • 2,157
  • 1
  • 14
  • 21
  • When I try that, it gets all users on the portal instance. There are several sites, each have different sets of users. – SamWM Oct 19 '19 at 10:36
  • I am looking at querying sites that don't have all portal users, e.g. a governance site, or a board members only subsite. I have updated the question, so hopefully that clarifies things. – SamWM Oct 20 '19 at 10:53