Author: hoang_to
Date: 2010-01-12 05:25:00 -0500 (Tue, 12 Jan 2010)
New Revision: 1233
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java
portal/trunk/portlet/exoadmin/src/main/webapp/groovy/admintoolbar/webui/component/UIAdminToolbarPortlet.gtmpl
Log:
GTNPORTAL-466: The site editor menu needs to provide contextual display of its items
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java 2010-01-12
10:11:08 UTC (rev 1232)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserACL.java 2010-01-12
10:25:00 UTC (rev 1233)
@@ -59,7 +59,7 @@
private String navigationCreatorMembershipType_;
private List<String> mandatoryGroups_;
-
+
private List<String> mandatoryMSTypes_;
private PortalACLPlugin portalACLPlugin;
@@ -101,7 +101,7 @@
{
mandatoryGroups_ = new ArrayList<String>();
}
-
+
ValuesParam mandatoryMSTypesParam =
params.getValuesParam("mandatory.mstypes");
if (mandatoryMSTypesParam != null)
mandatoryMSTypes_ = mandatoryMSTypesParam.getValues();
@@ -213,7 +213,7 @@
{
return mandatoryGroups_;
}
-
+
public List<String> getMandatoryMSTypes()
{
return mandatoryMSTypes_;
@@ -269,6 +269,30 @@
return hasEditPermission(getIdentity(), page);
}
+ /**
+ *
+ * Minh Hoang TO - This method is equivalent to
+ * <code>hasEditPermission(Page)</code>. It allows us to check edit
+ * permission with a UIPage, without converting UIPage into Page via
+ * PortalDataMapper
+ *
+ */
+ public boolean hasEditPermissionOnPage(String ownerType, String ownerId, String
editPermExpression)
+ {
+ Identity identity = this.getIdentity();
+
+ if (PortalConfig.USER_TYPE.equals(ownerType))
+ {
+ if (ownerId.equals(identity.getUserId()))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ return hasPermission(identity, editPermExpression);
+ }
+
public boolean hasPermission(String expPerm)
{
return hasPermission(getIdentity(), expPerm);
@@ -367,8 +391,9 @@
String expAdminGroup = getAdminGroups();
String expPerm = null;
- //Check to see whether current user is member of admin group or not, if so grant
- //edit permission for group navigation for that user.
+ // Check to see whether current user is member of admin group or not,
+ // if so grant
+ // edit permission for group navigation for that user.
if (expAdminGroup != null)
{
expAdminGroup = expAdminGroup.startsWith("/") ? expAdminGroup :
"/" + expAdminGroup;
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java 2010-01-12
10:11:08 UTC (rev 1232)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/toolbar/webui/component/UIAdminToolbarPortlet.java 2010-01-12
10:25:00 UTC (rev 1233)
@@ -19,8 +19,15 @@
package org.exoplatform.toolbar.webui.component;
+import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.model.PageNavigation;
+import org.exoplatform.portal.webui.page.UIPage;
+import org.exoplatform.portal.webui.page.UIPageBody;
import org.exoplatform.portal.webui.util.Util;
+import org.exoplatform.portal.webui.workspace.UIPortalApplication;
+import org.exoplatform.portal.webui.workspace.UIWorkingWorkspace;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.core.UIPortletApplication;
import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
@@ -28,6 +35,9 @@
@ComponentConfig(lifecycle = UIApplicationLifecycle.class, template =
"app:/groovy/admintoolbar/webui/component/UIAdminToolbarPortlet.gtmpl")
public class UIAdminToolbarPortlet extends UIPortletApplication
{
+ // Minh Hoang TO
+ // TODO: Add a ThreadLocal cache to avoid double invocation of editPermission
+ // check ( one in processRender method, and one in Groovy template )
public UIAdminToolbarPortlet() throws Exception
{
@@ -42,4 +52,50 @@
return null;
return Util.getUIPortal().getNavigations().get(0);
}
+
+ @Override
+ public void processRender(WebuiApplication app, WebuiRequestContext context) throws
Exception
+ {
+ // A user could view the toolbar portlet iff he/she has edit permission
+ // either on
+ // 'active' page or 'active' portal
+ if (hasEditPermissionOnNavigation() || hasEditPermissionOnPage())
+ {
+ super.processRender(app, context);
+ }
+ }
+
+ private boolean hasEditPermissionOnNavigation() throws Exception
+ {
+ PageNavigation selectedNavigation = getSelectedNavigation();
+ UIPortalApplication portalApp = Util.getUIPortalApplication();
+ UserACL userACL = portalApp.getApplicationComponent(UserACL.class);
+ if (selectedNavigation == null || userACL == null)
+ {
+ return false;
+ }
+ else
+ {
+ return userACL.hasEditPermission(selectedNavigation);
+ }
+ }
+
+ private boolean hasEditPermissionOnPage() throws Exception
+ {
+ UIPortalApplication portalApp = Util.getUIPortalApplication();
+ UIWorkingWorkspace uiWorkingWS =
portalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
+ UIPageBody pageBody = uiWorkingWS.findFirstComponentOfType(UIPageBody.class);
+ UIPage uiPage = (UIPage)pageBody.getUIComponent();
+
+ if (uiPage == null)
+ {
+ return false;
+ }
+ else
+ {
+ UserACL userACL = portalApp.getApplicationComponent(UserACL.class);
+ return userACL.hasEditPermissionOnPage(uiPage.getOwnerType(),
uiPage.getOwnerId(), uiPage.getEditPermission());
+ }
+ }
+
}
Modified:
portal/trunk/portlet/exoadmin/src/main/webapp/groovy/admintoolbar/webui/component/UIAdminToolbarPortlet.gtmpl
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/webapp/groovy/admintoolbar/webui/component/UIAdminToolbarPortlet.gtmpl 2010-01-12
10:11:08 UTC (rev 1232)
+++
portal/trunk/portlet/exoadmin/src/main/webapp/groovy/admintoolbar/webui/component/UIAdminToolbarPortlet.gtmpl 2010-01-12
10:25:00 UTC (rev 1233)
@@ -20,6 +20,9 @@
String editSiteLayout =
_ctx.appRes("UIAdminToolbarPortlet.action.EditSiteLayout");
String editorLabel = _ctx.appRes("UIAdminToolbarPortlet.action.Editor");
+ boolean userCouldEditNavigation = uicomponent.hasEditPermissionOnNavigation();
+ boolean userCouldEditPage = uicomponent.hasEditPermissionOnPage();
+
PageNavigation selectedNav = uicomponent.getSelectedNavigation();
if (selectedNav != null) {
editorLabel = _ctx.appRes("UIAdminToolbarPortlet.action." +
selectedNav.getOwnerType() + ".Editor");
@@ -35,15 +38,23 @@
</div>
<div class="MenuItemContainer" style="position: absolute;
display:none;">
<div class="SubBlock">
- <div class="MenuItem">
- <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'PageCreationWizard', true))" title="" class="ItemIcon
AddPageIcon">$addPageLabel</a>
- </div>
- <div class="MenuItem">
- <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'EditCurrentPage', true))" title="" class="ItemIcon
EditPageIcon">$editPageLabel</a>
- </div>
- <div class="MenuItem">
- <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'EditInline', true))" title="" class="ItemIcon
EditSiteIcon">$editSiteLayout</a>
- </div>
+ <% if(userCouldEditNavigation){ %>
+ <div class="MenuItem">
+ <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'PageCreationWizard', true))" title="" class="ItemIcon
AddPageIcon">$addPageLabel</a>
+ </div>
+ <% } %>
+
+ <% if(userCouldEditPage){ %>
+ <div class="MenuItem">
+ <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'EditCurrentPage', true))" title="" class="ItemIcon
EditPageIcon">$editPageLabel</a>
+ </div>
+ <% } %>
+
+ <% if(userCouldEditNavigation){ %>
+ <div class="MenuItem">
+ <a
href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace',
'EditInline', true))" title="" class="ItemIcon
EditSiteIcon">$editSiteLayout</a>
+ </div>
+ <% } %>
</div>
</div>
</div>