I have a requirement that the site owner has permission to create the users and able to view the list of users only created by him.
To achieve the same I have created a portlet which has the form with basic user details. While submitting the form in my action class, I am inserting the user details in USER_ table by calling the following method:
try{
UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1, password2,
autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName,
prefixId, suffixId, male, birthdayMonth,birthdayDay, birthdayYear, jobTitle, groupIds,
organizationsIds, roleIds, userGroupIds, sendEmail, serviceContext);
}
catch(Exception e)
{
}
int userCount = UserLocalServiceUtil.getUsersCount();
Now the users are creating in USER_ table. But while displaying the list of users I need to display only the users created by that site owner only.
So I want to insert one more column like siteId
along with the users table and while fetching based on the siteId
I want to optimize the list and display on UI.
So I have gone through the Expando concept but I didn't get proper idea how can I use it based on my requirement.
So any one please suggest me how can I insert 'siteId' while calling the addUser
method and while fetching the based on this siteID
need to get the users list.
Thanks in advance.
The only (and strongly unrecommended) way to phisically add a column is to modify Liferay core by EXT environment.
Excluding this, the first oprion to achieve what you need is to don't use liferay "site", but Liferay "portal instances"... it is a bit like to have different Liferay installations: all of them will share the same software infrastructure, but they are logically as different Liferay installation. See here for more information.
If this way is not appliable, the second one is to use Expando bridge. By using that, you can add a "virtual" field to "User_" table containing the related groupId.
Instead using common get() method of serviceutil, you can access to expando value. You have two different way to access to Expando values.
The first one is to perform a user.getExpandoBridge().get... but it needs for a user object... so in this way you should iterate over any user before returning the list.
The latter is to use directly ExpandoTableLocalService, ExpandoColumnLocalService and ExpandoValueLocalService to directly get all expando rows containing your groupId value...
...
...but at this point, why you don't directly use a custom mapping table?
You just need to create a table containing userId and groupId pairs... get all userId filtered by groupId, then perform a DynamicQuery on User_ table. This isn't the best form of a database, but you can achieve your goals.
You just need to add a service layer to your portlet: read here to know more over one of the most powerful feature of Liferay.
It is a clean way to reach your requirement... but keep in mind that sites aren't conceived for this purpose... and the entire LR permission system will ignore the abstraction you are forcing in this way.