1

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.

VC1
  • 1,660
  • 4
  • 25
  • 42
Prasad
  • 1,164
  • 1
  • 10
  • 27

1 Answers1

2

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.

Pierpaolo Cira
  • 1,457
  • 17
  • 23
  • Thank you for your suggestion. I wanted to use Expando Bridge. So How can I insert the site ID along with UserLocalServiceUtil.addUser(). – Prasad Mar 30 '15 at 09:19
  • You need the user object returned by addUser, to get the expando bridge as shown in my comment. In this case you can directly get the bridge on the object, then add the value you need an a specific "(expando) column". – Pierpaolo Cira Mar 30 '15 at 09:50
  • I'm really sorry. I'm new to life ray. Can you please explain more. Or If possible give me some reference. Thanks in advance – Prasad Mar 30 '15 at 10:07
  • 1
    Google search is the best starting point: it can suggest links like https://www.liferay.com/it/community/wiki/-/wiki/Main/Developing+with+Expando or http://www.liferay.com/it/community/wiki/-/wiki/Main/Adding+an+custom+attribute+to+a+Community or http://www.abcseo.com/tech/liferay/expando It is very easy to find good example on the new (just be aware because the method to access expandoBridge has changed signature in different LR versions, but the behaviour for you is the same). By the way, my mind "Liferay in action" book is one of the most useful resources available. – Pierpaolo Cira Mar 30 '15 at 12:34