I'm able to get the organizationId of regular organizations using the following code:
ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
long liferayOrganizationId = themeDisplay.getScopeGroup().getOrganizationId();
But this code does not work for top-level orgs. How would I get the organizationId for a top-level organization?
This works for top-level organizations as well. However, when you're using this in a site that is not associated to any organization, it will naturally not reveal a valid organization id.
Note that Liferay 6.1 now has sites, which contain all the pages. Organizations can have sites, but don't need to. Sites can well exist without any organization being associated with them. And that's when you get 0 as the organizationId result from the code in your question
Related
I have a single site in Liferay DXP 7.2, and I would like to know what is the best way to add permissions/roles of viewing different pages to an organization.
Requirements:
This site will be owned/shared by 2 organizations.
Each organization has a number of site roles.
Each site role consists of permissions for viewing different sets of pages. For example, Role 1 can view page A and page B, whereas Role 2 can view page C and page D.
Desired Outcome:
Roles:
Role 1: view public page only.
Role 2: view public and admin pages only.
Role 3: view private page only.
Organizations:
Organization 1 has Role 1 and Role 2, which can be assigned to members within Organization 1.
Organization 2 has Role 1 and Role 3, which can be assigned to members within Organization 2.
Encountered Problems:
Permissions of viewing different pages are categorized as site roles. Site roles can only be applied to a particular site, and cannot be assigned to an organization.
Organizations are required to simplify user management within the site.
I prefer not to separate it into 2 different sites.
What is the best way to achieve the desired outcome? Also, do correct me if I made wrong assumptions about how roles work in Liferay. Thank you.
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.
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);
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)
There are organizations, users, roles and groups in Liferay. But there are many methods in liferay API that returns company or need company id as argument. E.g. UserLocalServiceUtil.getUserByEmailAddress(long companyId, String emailAddress) or com.liferay.portal.model.User getCompanyId().
For what purpose the company is provided in Liferay? Why I have to provide company id to find user by email address?
Documentation does not say too much.
In short - you can have more than one portal instance in the same server (in the same database) and you need "companyId" to avoid db data conflicts between those instances. A single instance itself is a full portal with users,groups,roles and everything else. Having "companyId" you can save, for example, two users with same emailAddress for different instances.
I would like to find out all of the user which are associated in some roles. I have seen the UserLocalService that provides the method to find the users in a particular role. But I want a method to which I can pass an array of roleIds and it shall return me the list of users in those roles.
One way is to write custom SQL, but I would like to get it done by using the API only.
Is that possible with Liferay API??
Call the API multiple times? Create a new service that does this for you so that you only have a single call to (your) API?
I know, this is probably not the answer that you expected. Note that roles in Liferay can be scoped globally (to the whole portal, called 'regular') or to an individual site or organization. Thus just giving a roleId would limit you to the global roles (as the others would require the site's or organization's groupId).
Stepping back and looking at what you want to achieve, my first guess is that you have some semantics in being associated with a specific role - kind of like... a usergroup? A role is designed to give permissions to users, while a usergroup is designed to group users. UserLocalService also has getUserGroupUsers - this also only takes a single usergroup id, but at least it's a single (global) scope by definition and not ambiguous like roles.
Is this possible? I tried looking at the organization's member list, but it only is showing public members. I have the user oauth'd with their token and metadata, but their current organizations don't seem to be included. Can I increase the scope to allow this kind of information to pass through?
An example using the github API or node.js github library would be fantastic. Either one works!
Should be possible.
From the API docs:
Org Members list - List all users who are members of an organization. A member is a user that belongs to at least 1 team in the organization. If the authenticated user is also an owner of this organization then both concealed and public members will be returned. If the requester is not an owner of the organization the query will be redirected to the public members list.
Therefore, in order to list private members for an org, you have to be an owner of that org.
If you want to check if the authenticated user (e.g. yourself or someone else who's OAuth token you have) is a member of an org, get the list of the orgs for an authenticated user of via: GET /user/orgs. Not sure which scope the OAuth token needs to have in case the org is private, but I'd guess you need repo scope since that mentions private orgs.