« Back

5.1 Overhaul of Personal Communities

Company Blogs July 11, 2008 By Ivan Cheung Staff

One of the most widely used features of Liferay is the Personal Community, aka My Community, aka Personal Space. It's a feature that allows users to have their own set of web pages, both private and public, to manage and update as they please. It's also a feature that has been challenging for developers to deal with. For example, you would like to grant certain users a Personal Community, but you want to be able to customize how it looks and what it does before you give it to them. These are the issues that were taken into consideration when version 5.1 was created!

One major update has to do with who gets a Personal Community. 5.1 jump kicks the Power User role out the window, so by default ALL users get a Personal Community. What if I want to be restrictive about who gets a Personal Space? I'm a control freak, how do I regain control over who gets a Personal Community!

Here is one quick way to do it in ServicePreAction.java.
First I have decided to overwrite the ServicePreAction class, so I've put this in my portal-ext.properties:

servlet.service.events.pre=com.ext.portal.events.CustomServicePreAction

I basically copied over the original ServicePreAction to my EXT environment and renamed it. Search for "// Layouts" inside ServicePreAction. Notice how the portal checks if you are signed in first, if you are then it checks to see whether layout.user.private.layouts.enabled is true. If layout.user.private.layouts.enabled=true, then it executes addDefaultUserPrivateLayouts(). Let's try putting in some logic that will also check if the user has the Power User role:

if (signedIn) {
               if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED && 
               /* check if user has Power User role */
               UserLocalServiceUtil.hasRoleUser(RoleLocalServiceUtil.getRole(companyId, "Power User").getRoleId(),        user.getUserId()))  

                { 
                                   addDefaultUserPrivateLayouts(user);
                }
                else {
                                   deleteDefaultUserPrivateLayouts(user, companyId);
                }
               if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
                                   addDefaultUserPublicLayouts(user);
               }
              else {
                                   deleteDefaultUserPublicLayouts(user);
               }
}

Also make sure to modify the logic for deleteDefaultUserPrivateLayouts() to be consistent with the portal's default behavior!


protected void deleteDefaultUserPrivateLayouts(User user, long companyId)
     throws PortalException, SystemException {
         if (!PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED && user.hasPrivateLayouts() ||
         /* if user does not have Power User role, and has a Private Community with private pages, delete the private pages */
        !UserLocalServiceUtil.hasRoleUser(RoleLocalServiceUtil.getRole(companyId, "Power User").getRoleId(), user.getUserId())&& user.hasPrivateLayouts()*/)

        {
                 Group userGroup = user.getGroup();
                 LayoutLocalServiceUtil.deleteLayouts(userGroup.getGroupId(), true);
         }
    }


Please refer here for more information on Personal Communities: http://wiki.liferay.com/index.php/Personal_Community

Threaded Replies Author Date
When will 5.1 be available for download? Glenn Powell July 11, 2008 4:07 AM
My guess is anytime now :P Ivan Cheung July 11, 2008 4:33 AM
Great Ivan! Not just for the power users... Jerry Niu July 11, 2008 10:51 AM
I think instead of simply throwing away the... Darshak Thakore July 11, 2008 12:56 PM
I hope that it doesn't take coding to disable... Christopher Donald Sharp July 14, 2008 3:50 PM
Made it a property now. See LEP-6700. Brian Chan July 14, 2008 10:24 PM
Awesome Brian! :D Ivan Cheung July 14, 2008 10:32 PM
Great! Christopher Donald Sharp July 20, 2008 6:01 AM
Thank you! It helps a lot! Nacho A S September 18, 2008 9:33 AM

When will 5.1 be available for download?
Posted on 7/11/08 4:07 AM.
My guess is anytime now emoticon
Posted on 7/11/08 4:33 AM in reply to Glenn Powell.
Great Ivan! Not just for the power users anymore! Liferay.com has been in this state since May around the time WOL was introduced.
Posted on 7/11/08 10:51 AM.
I think instead of simply throwing away the Power User, this should have been a configurable setting in the properties file. If you consider enterprise scenarios where the portal is being used for publishing and distributing content, a lot of times there will be no need to give each user a private space. Of course, as you specified, it is not very difficult to change this but then the overall out-of-the-box experience is broken.
Just my 2 cents.
Posted on 7/11/08 12:56 PM.
I hope that it doesn't take coding to disable personal community pages in version 5.1!! Did Liferay servey thier customer base about this? My guess is that most of the commercial customers will want to have a means of easily disabling personal pages.
Posted on 7/14/08 3:50 PM.
Made it a property now. See LEP-6700.
Posted on 7/14/08 10:24 PM in reply to Christopher Donald Sharp.
Awesome Brian! emoticon
Posted on 7/14/08 10:32 PM in reply to Brian Chan.
Posted on 7/20/08 6:01 AM in reply to Brian Chan.
Thank you! It helps a lot!
Posted on 9/18/08 9:33 AM.