Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sandeep Nair
[Resolved]Retrieve community pages on which user has Permission
January 7, 2009 10:26 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1697

Join Date: November 5, 2008

Recent Posts

How can i get whether a user has permission to view a page or not?
Juan Gonzalez
RE: Permission of a page
January 7, 2009 8:06 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2350

Join Date: October 28, 2008

Recent Posts

Better to read all the documentation first (this is for 5.1 version). Here you have videos to see how this can be done:

http://www.liferay.com/web/guest/community/documentation/5_1http://www.liferay.com/web/guest/community/documentation/5_1
Sandeep Nair
RE: Permission of a page
January 7, 2009 7:22 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1697

Join Date: November 5, 2008

Recent Posts

Hi Juan,

I am talking about getting permission of a page while coding. Actually we had a requirement to get all the Community private pages of a user.
I achieved this by getting all the groups of a user and then getting the Layouts of a group. But while retrieving the layouts of a group i get all the layouts even though a user doesnt have permission on it. I want to filter only those layouts on which uses has permission.

Regards,
Sandeep.
Sandeep Nair
RE: Permission of a page
January 7, 2009 10:25 PM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1697

Join Date: November 5, 2008

Recent Posts

Hi,
I have solved my problem. My requirement was to retrieve all the community private page of the user on which user has permission.

I have achieved it the following way

List<Layout> communitylayouts = new ArrayList<Layout>();
//retrieve permission checker
PermissionChecker permissionChecker = PermissionCheckerFactory.create(
user, true);
//retrieve all groups of a user
List<Group> userGroups = GroupLocalServiceUtil.getUserGroups(userId);
for(Group group: userGroups){
//Iterate the groups check whether the group is a community
if(group.isCommunity()){
List<Layout> groupLayouts = LayoutLocalServiceUtil.getLayouts(
group.getGroupId(), true);
List<Layout> templayouts = new ArrayList<Layout>();
for(Layout tempLayout: groupLayouts){
//Retrieve all the layouts that user have permission to
boolean isViewable = LayoutPermissionUtil.contains(permissionChecker,tempLayout,ActionKeys.VIEW);
if(isViewable){
templayouts.add(tempLayout);
}
}
communitylayouts.addAll(templayouts);
System.out.println("Groupt layouts size: "+groupLayouts.size()+" User Layouts size: "+templayouts.size());
}
}

Thanks,
Sandeep