Author: julien_viet
Date: 2010-06-11 09:13:58 -0400 (Fri, 11 Jun 2010)
New Revision: 3303
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
GTNPORTAL-1272 : Could not modify access-permission on dashboard portlet window
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java 2010-06-11
09:59:48 UTC (rev 3302)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java 2010-06-11
13:13:58 UTC (rev 3303)
@@ -479,6 +479,13 @@
String theme = attrs.getValue(MappedAttributes.THEME, null);
//
+ List<String> a = Collections.singletonList(UserACL.EVERYONE);
+ if (srcContainer.isAdapted(ProtectedResource.class)) {
+ ProtectedResource pr = srcContainer.adapt(ProtectedResource.class);
+ a = pr.getAccessPermissions();
+ }
+
+ //
mo = new ApplicationData<Portlet>(
srcContainer.getObjectId(),
component.getName(),
@@ -495,10 +502,7 @@
null,
null,
Collections.<String, String>emptyMap(),
- Collections.singletonList(UserACL.EVERYONE));
- // Julien : the everyone is not great but having null permission
- // means the same thing cf {@link UIPortalComponent} class
- // we need to solve that somehow
+ a);
}
else
{
@@ -677,17 +681,21 @@
// citizen of the portal
if (srcChild instanceof ApplicationData)
{
- ApplicationData app = (ApplicationData)srcChild;
+ ApplicationData<?> app = (ApplicationData)srcChild;
if (app.getType() == ApplicationType.PORTLET && app.getState()
instanceof TransientApplicationState)
{
TransientApplicationState<?> state =
(TransientApplicationState<?>)app.getState();
String contentId = state.getContentId();
if ("dashboard/DashboardPortlet".equals(contentId))
{
+ DashboardData data;
if (app.getStorageId() != null)
{
UIContainer dstDashboard =
session.findObjectById(ObjectType.CONTAINER, app.getStorageId());
- srcChild = loadDashboard(dstDashboard);
+ data = loadDashboard(dstDashboard);
+
+ // Update those attributes as we have to do it now, they don't
exist in a container
+ // but do exist in a dashboard container
Attributes attrs = dstDashboard.getAttributes();
attrs.setValue(MappedAttributes.SHOW_INFO_BAR,
app.isShowInfoBar());
attrs.setValue(MappedAttributes.SHOW_MODE,
app.isShowApplicationMode());
@@ -696,8 +704,27 @@
}
else
{
- srcChild = DashboardData.INITIAL_DASHBOARD;
+ data = DashboardData.INITIAL_DASHBOARD;
}
+
+ //
+ data = new DashboardData(
+ data.getStorageId(),
+ data.getId(),
+ data.getName(),
+ data.getIcon(),
+ data.getTemplate(),
+ data.getFactoryId(),
+ data.getTitle(),
+ data.getDescription(),
+ data.getWidth(),
+ data.getHeight(),
+ app.getAccessPermissions(),
+ data.getChildren()
+ );
+
+ //
+ srcChild = data;
}
}
}
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-06-11
09:59:48 UTC (rev 3302)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-06-11
13:13:58 UTC (rev 3303)
@@ -35,10 +35,7 @@
import org.exoplatform.services.listener.Listener;
import org.exoplatform.services.listener.ListenerService;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
/**
* Created by The eXo Platform SARL Author : Tung Pham thanhtungty(a)gmail.com Nov
@@ -658,6 +655,7 @@
// Configures the dashboard
Dashboard dashboard = new Dashboard(dashboardId);
+ dashboard.setAccessPermissions(new String[]{"perm1","perm2"});
TransientApplicationState<Portlet> state = new
TransientApplicationState<Portlet>("foo/bar");
Application<Portlet> app = Application.createPortletApplication();
app.setState(state);
@@ -673,6 +671,7 @@
// Now check we have the state on the dashboard
dashboard = storage_.loadDashboard(dashboardId);
+ assertEquals(Arrays.asList("perm1","perm2"),
Arrays.asList(dashboard.getAccessPermissions()));
assertEquals(1, dashboard.getChildren().size());
app = (Application<Portlet>)dashboard.getChildren().get(0);
assertEquals("foo/bar", storage_.getId(app.getState()));
@@ -706,6 +705,32 @@
assertEquals(3, dashboard.getChildren().size());
}
+ public void testDashboardSecurity() throws Exception
+ {
+ Page page = new Page();
+ page.setPageId("portal::test::foo");
+ Application<Portlet> app = Application.createPortletApplication();
+ app.setAccessPermissions(new String[]{"perm1","perm2"});
+ app.setState(new
TransientApplicationState<Portlet>("dashboard/DashboardPortlet"));
+ page.getChildren().add(app);
+ storage_.save(page);
+ page = storage_.getPage("portal::test::foo");
+ String id = page.getChildren().get(0).getStorageId();
+
+ // Load the dashboard itself
+ Dashboard dashboard = storage_.loadDashboard(id);
+ assertEquals(Arrays.asList("perm1","perm2"),
Arrays.asList(dashboard.getAccessPermissions()));
+
+ // Modify the dashboard permission
+ dashboard.setAccessPermissions(new String[]{"perm3"});
+ storage_.saveDashboard(dashboard);
+
+ // Load application and check
+ page = storage_.getPage("portal::test::foo");
+ app = (Application<Portlet>)page.getChildren().get(0);
+ assertEquals(Arrays.asList("perm3"),
Arrays.asList(app.getAccessPermissions()));
+ }
+
public void testDashboardMoveRight() throws Exception
{
Page page = new Page();