User personalization on public page

User personalization on public page: Page level customization – Liferay 6.2

This post is to demonstrate user personalization in liferay where user can personalize accessible page resource by his wish.

Use case: When user logs in into portal it will land to custom page (say dashboard) which will be user’s post login default landing page where user can perform these operations:

1)      Able to do page level customization on this page and not on rest of the pages of portal.

2)      Able to drag & drop portlets on dashboard page.

3)      Able to drag portlets in defined layout.

4)      Able to configure applications/portlets.

5)      Only specific category portlets (say “Manage Dashboard”) should be visible to normal user however administrator can view all category portlets.

6)      Actual portlets should only be invocable from glance portlet/tiles.

7)      Actual portlets should reside on other pages of portal which are not directly accessible.

8)      Glance portlet/tiles visibility is permission based.

9)      One who has not view permission on portlet, portlet should disappear from user’s dashboard page and add application dockbar menu and other layout resources (portlets) should be auto vertical rearranged.

10)   All newly created user should get permission to view these glance portlet.

Implementation: Above use case is mostly achievable with default Liferay 6.2 OOB features with a small hook and custom portlet.

All we need to do

1)      Login with portal admin.

2)      Create a page say “dashboard” on site ‘’portal’’ and add its friendly URL entry in control panel > portal setting > main configuration against default landing page field “/web/portal/dashboard”. So that dashboard becomes default landing page for all authenticated users in portal.

3)      Create a hidden page say “template page.” and add all glance portlets/tiles on to page in 2 columns (50/50) layout. (Will describe in detail about glance portlet from point 16 onwards)

4)      Go to portal site > site administration > site pages > dashboard page

a.       Apply  2 Columns(50/50) layout to page

b.      Click on customization settings from right hand side panel.

c.       Check marks both columns as customizable section.

d.      Click on Copy Application icon > Select “template page” from dropdown > click copy button.

e.      Click on permission icon and remove guest view permission from page

5)      Create a regular role “user accessibility” which facilitates in customization of dockbar portlet which control rendering of categories of portlet in add application & other tabs of dockbar menu. (Will describe in detail about dockbar portlet customization/hook from point 11 onwards)

6)      Create couple more regular role per portlet as follows to control visibility of portlets per user.

7)      Let’s create 3 regular role “tiles1portletrole, tiles2portletrole, tiles3portletrole”.

8)      Edit tiles1portletrole > define permission > add VIEW and ADDTOPAGE permission of tiles1portlet. Similarly do for tiles2portletrole, tiles3portletrole.

9)      Go to control panel > portal settings > users> default user association > under Roles field, add roles user accessibility, tiles1portletrole, tiles2portletrole, tiles3portletrole and remove power user role.

10)   Go to control panel > server administration > Execute “Clean Up Permissions” action.

11)   Create a JSP hook on dockbar portlet and override add_application JSP.

12)   Add below entry

<%

                                boolean restrict = false;

                                List<Role> roles = user.getRoles();

                                for(Role role:roles){

                                                if(role.getName().equalsIgnoreCase("useraccessibility")){

                                                                restrict = true;

                                                }

                                }

                               

%>

 

before this line in JSP

<liferay-ui:panel-container id="<%= panelContainerId %>">

                                                <c:if test="<%= portlets.size() > 0 %>">

13)   Bound <div class="lfr-add-content"> with check

<%

if(!restrict){

%>

                …….

                …….

                …….

<%

                }

                portletCategoryIndex++;

%>         

14)   Finally update category for loop with this code

if(restrict){

if(curPortletCategory.getName().equalsIgnoreCase("Manage Dashboard")){

request.setAttribute(WebKeys.PORTLET_CATEGORY, curPortletCategory);

request.setAttribute(WebKeys.PORTLET_CATEGORY_INDEX, String.valueOf(portletCategoryIndex));

%>

<liferay-util:include page="/html/portlet/dockbar/view_category.jsp">

<liferay-util:param name="panelContainerId" value="<%= panelContainerId %>" />

</liferay-util:include>

<%

break ;

}                             

}else{

request.setAttribute(WebKeys.PORTLET_CATEGORY, curPortletCategory);

request.setAttribute(WebKeys.PORTLET_CATEGORY_INDEX, String.valueOf(portletCategoryIndex));

}

15)   At the end at this code

<%

restrict = false;

%>

16)   Create a glance portlets of all actual portlets which will be available for use on user’s dashboard page to play.

17)   All glance portlets will be fall in category as we have defined in hook i.e. “Manage Dashboard”

<category name="Manage Dashboard">

<portlet id="tiles1"></portlet>

<portlet id="tiles2"></portlet>

<portlet id="tiles3"></portlet>

<portlet id="tiles4"></portlet>

</category>

18)   Each individual glance portlet (say tiles1, tiles2)  view.jsp have clickable image which redirect to actual portlet page

19)   That clickable image is bound with permission which facilitates visibility of glance portlet to user based on defined accessibility in associated role(tiles1portletrole, tiles2portletrole, tiles3portletrole).

20)   Add this code snippet in view.jsp

<div id="tile1">

<%

String name = PortalUtil.getPortletId(request);

if (PortletPermissionUtil.contains(permissionChecker,plid.longValue(), name,ActionKeys.ADD_TO_PAGE)) {

%>

 

  <a href="<%=themeDisplay.getURLCurrent()%>/../tile1" title="Tile1 Portlet">

    <img class="picture" src="<%=renderRequest.getContextPath()%>/images/tile1thumbnail.jpg" />

  </a>

 

  <aui:script>

                                AUI().ready('node', function(A) {

                                                var name = '<%=name %>';

                                                A.one('#portlet_'+name).setStyle('display', 'block');

                                })    

                </aui:script>

   

 

<%         

}else{

%>                         

                <aui:script>

                                AUI().ready('node', function(A) {

                                                var name = '<%=name %>';

                                                A.one('#portlet_'+name).setStyle('display', 'none');

                                })    

                </aui:script>

               

<%         

}

%>

</div>

21)   This is relative url of page  <a href="<%=themeDisplay.getURLCurrent()%>/../tilefeature1" title="Tile1 Portlet"> where actual portlet resides.

22)   And this url is bound with permission If user has permission to access this portlet than only clickable image is visible to him and user can able to click and navigate to actual portlet landed page.

23)   Otherwise this aui script automatically vanish tiles portlet from dashboard page.

<aui:script>

                                AUI().ready('node', function(A) {

                                                var name = '<%=name %>';

                                                A.one('#portlet_'+name).setStyle('display', 'none');

                                })    

</aui:script>

24)   Repeat the steps 20 to 23 to link all glance tiles portlets with actual portlet page.

25)   Last step is to apply permission on pages (tilefeature1, tilefeature2…) where actual portlet resides. It is require to prevent illegal access of page because these pages are public pages.

26)   Goto siteadministration >pages> tilesfeature1>permissions

a.       Remove all permissions from all types of roles.

b.      Apply view permission to tiles1portletrole & siteowner.

c.       Similarly done of other pages like tilesfeatures.

27)   Now we all set with user personalization.

28)   Create few normal user and test flow.

 

 

0 Anexos
16148 Visualizações
Média (1 Votar)
A média da avaliação é 5.0 estrelas de 5.
Comentários
Respostas do tópico Autor Data
I feel some where the concept is disconnected... Srikanth komma 5 de Junho de 2015 03:24

I feel some where the concept is disconnected and confusing, because tilesfeature1,tilesfeature2 pages how it come in to this as we created 2 pages dashboard and template page .
Please review it and correct it.
Postado em 05/06/15 03:24.