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