Message Boards

« Back to 2.- Usage ( From Xml file to CRUD Portlet)

Portlet support for restrictBy group

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Portlet support for restrictBy group
Answer
8/13/12 10:00 PM
I tried creating a table that would be restricted to members of a group. For example

 1            <classDef>
 2                <name>Scorecard</name>
 3                <title>Scorecard</title>
 4                <restrictBy>
 5                    <companyId>true</companyId>
 6                    <groupId>true</groupId>
 7                    <userId>false</userId>
 8                </restrictBy>
 9            </classDef>


I was able to create a Scorecard entry using the management portlet, but once created it wouldn't show up in the view.

Looking at the ScorecardPortlet, I could see that no database query was being done.

In Portlet_XXXXXXPortlet_java.vm the variable restricciones can be set to "ninguna", "user", "group", or "usergroup"

 1#set ($restricciones = "ninguna")
 2#if ($application.getClassDef().getRestrictBy().getUserId() == "true")
 3#set ($restricciones = "user")
 4#end
 5#if ($application.getClassDef().getRestrictBy().getGroupId() == "true")
 6#set ($restricciones = "group")
 7#end
 8#if ($application.getClassDef().getRestrictBy().getGroupId() == "true")
 9#if ($application.getClassDef().getRestrictBy().getUserId() == "true")
10#set ($restricciones = "usergroup")
11#end
12#end


However in the showViewDefault method there is no code to handle the "group" case. The $restricciones == "ninguna" (no restrictions) case is calling findAllInGroup(). I think the correct case would be for "ninguna" to get all Company entries and "group" to get all in group, as follows:

1#if ($restricciones == "group")
2                tempResults = ${classDef_name}LocalServiceUtil.findAllInGroup(groupId, containerStart, containerEnd, comparator);
3                total = ${classDef_name}LocalServiceUtil.countAllInGroup(groupId);
4#end
5#if ($restricciones == "ninguna")
6                tempResults = ${classDef_name}LocalServiceUtil.getCompanyEntries(companyId, containerStart, containerEnd, comparator);
7                total = ${classDef_name}LocalServiceUtil.getCompanyEntriesCount(companyId);
8#end

This also requires adding companyId to the method:
 1    @SuppressWarnings("unchecked")
 2    public void showViewDefault(RenderRequest renderRequest,
 3            RenderResponse renderResponse) throws IOException, PortletException {
 4
 5        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
 6                .getAttribute(WebKeys.THEME_DISPLAY);
 7
 8        long groupId = themeDisplay.getScopeGroupId();
 9        long companyId = themeDisplay.getCompanyId();   // <-- Added


Finally, is the restrictBy companyId element ever used? I don't see it having any effect in the Portlet code. Is there permissions checking elsewhere that the restrictBy elements control?

I hope this is helpful and please let me know if I have misunderstood anything as I am trying to learn how to use the factory properly. It is a great tool!

Thanks,
Deb

RE: Portlet support for restrictBy group
Answer
8/16/12 7:41 AM as a reply to Deb Troxel.
Hola Deb,

Correct again, I have not spend much time lately checking "restrictBy" emoticon clause because I thing it will be deprecated by the permissions upgrade in the project. Any way I will update with your suggestions today, and changes will be included on next version.

With permissions you are supposed to be more flexible on with users/groups/etc access the data, also you are able to select more than one group, or a couple of users, etc. things that are impossible with the "restrictBy" approach


Thanks very much for your help, Jack. emoticon

Pd.: which version are you using?

RE: Portlet support for restrictBy group
Answer
8/16/12 3:28 PM as a reply to Jack A. Rider.
Hola Jack,

Having full "permissions" support will be a good addition. I'll look forward to that.

Jack A. Rider:

Pd.: which version are you using?


I am using Liferay 6.1.1 CE GA2 and XMLPortletFactory 2.1

- Deb