From ad01ff846f45bada107cdbef4fdf5302a9fe91e3 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 21 Feb 2006 19:25:01 +0000 Subject: [PATCH] . Fix for AWC-555 - Space Selector now no longer attempts to disable spaces that a user cannot read - Was assuming Company Home was accessable . Label change: "Content Templates" now reads "Presentation Templates" . Fix for DownloadContentServlet to display normal error JSP page if content is deleted before viewing occurs . Removal of erronous character in SystemErrorTag git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2459 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../app/servlet/DownloadContentServlet.java | 34 +-- .../web/bean/repository/Repository.java | 21 +- .../repo/component/AbstractItemSelector.java | 197 ++++++++---------- .../ui/repo/component/UICategorySelector.java | 22 +- .../ui/repo/component/UISpaceSelector.java | 69 ++++-- .../web/ui/repo/tag/SystemErrorTag.java | 2 +- 6 files changed, 190 insertions(+), 155 deletions(-) diff --git a/source/java/org/alfresco/web/app/servlet/DownloadContentServlet.java b/source/java/org/alfresco/web/app/servlet/DownloadContentServlet.java index fcc841e58b..a3356af2c0 100644 --- a/source/java/org/alfresco/web/app/servlet/DownloadContentServlet.java +++ b/source/java/org/alfresco/web/app/servlet/DownloadContentServlet.java @@ -158,25 +158,25 @@ public class DownloadContentServlet extends BaseServlet ContentService contentService = serviceRegistry.getContentService(); PermissionService permissionService = serviceRegistry.getPermissionService(); - // check that the user has at least READ_CONTENT access - else redirect to the login page - if (permissionService.hasPermission(nodeRef, PermissionService.READ_CONTENT) == AccessStatus.DENIED) - { - if (logger.isDebugEnabled()) - logger.debug("User does not have permissions to read content for NodeRef: " + nodeRef.toString()); - redirectToLoginPage(req, res, getServletContext()); - return; - } - - if (attachment == true) - { - // set header based on filename - will force a Save As from the browse if it doesn't recognise it - // this is better than the default response of the browse trying to display the contents! - // TODO: make this configurable - and check it does not prevent streaming of large files - res.setHeader("Content-Disposition", "attachment;filename=\"" + URLDecoder.decode(filename, "UTF-8") + '"'); - } - try { + // check that the user has at least READ_CONTENT access - else redirect to the login page + if (permissionService.hasPermission(nodeRef, PermissionService.READ_CONTENT) == AccessStatus.DENIED) + { + if (logger.isDebugEnabled()) + logger.debug("User does not have permissions to read content for NodeRef: " + nodeRef.toString()); + redirectToLoginPage(req, res, getServletContext()); + return; + } + + if (attachment == true) + { + // set header based on filename - will force a Save As from the browse if it doesn't recognise it + // this is better than the default response of the browse trying to display the contents! + // TODO: make this configurable - and check it does not prevent streaming of large files + res.setHeader("Content-Disposition", "attachment;filename=\"" + URLDecoder.decode(filename, "UTF-8") + '"'); + } + // get the content reader ContentReader reader = contentService.getReader(nodeRef, propertyQName); // ensure that it is safe to use diff --git a/source/java/org/alfresco/web/bean/repository/Repository.java b/source/java/org/alfresco/web/bean/repository/Repository.java index c5ef90bfc3..fa0cc76954 100644 --- a/source/java/org/alfresco/web/bean/repository/Repository.java +++ b/source/java/org/alfresco/web/bean/repository/Repository.java @@ -82,9 +82,12 @@ public final class Repository /** reference to System folder */ private static NodeRef systemRef = null; - /** reference to the namespace service */ + /** reference to the NamespaceService */ private static NamespaceService namespaceService = null; + /** reference to the ServiceRegistry */ + private static ServiceRegistry serviceRegistry = null; + /** * Private constructor */ @@ -411,8 +414,12 @@ public final class Repository */ public static ServiceRegistry getServiceRegistry(FacesContext context) { - return (ServiceRegistry)FacesContextUtils.getRequiredWebApplicationContext( - context).getBean(ServiceRegistry.SERVICE_REGISTRY); + if (serviceRegistry == null) + { + serviceRegistry = (ServiceRegistry)FacesContextUtils.getRequiredWebApplicationContext( + context).getBean(ServiceRegistry.SERVICE_REGISTRY); + } + return serviceRegistry; } /** @@ -423,8 +430,12 @@ public final class Repository */ public static ServiceRegistry getServiceRegistry(ServletContext context) { - return (ServiceRegistry)WebApplicationContextUtils.getRequiredWebApplicationContext( - context).getBean(ServiceRegistry.SERVICE_REGISTRY); + if (serviceRegistry == null) + { + serviceRegistry = (ServiceRegistry)WebApplicationContextUtils.getRequiredWebApplicationContext( + context).getBean(ServiceRegistry.SERVICE_REGISTRY); + } + return serviceRegistry; } /** diff --git a/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java b/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java index 1c64e05a7c..8785283ab7 100644 --- a/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java +++ b/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java @@ -33,7 +33,6 @@ import javax.faces.event.FacesEvent; import javax.transaction.UserTransaction; import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.web.app.Application; @@ -79,6 +78,7 @@ public abstract class AbstractItemSelector extends UIInput /** Flag to show whether the component is disabled */ protected Boolean disabled; + // ------------------------------------------------------------------------------ // Component Impl @@ -117,7 +117,7 @@ public abstract class AbstractItemSelector extends UIInput * @param context The Faces context * @return The children */ - public abstract Collection getChildrenForNode(FacesContext context); + public abstract Collection getChildrenForNode(FacesContext context); /** * Returns a collection of child associations of the root @@ -125,7 +125,7 @@ public abstract class AbstractItemSelector extends UIInput * @param context The Faces context * @return The root options */ - public abstract Collection getRootChildren(FacesContext context); + public abstract Collection getRootChildren(FacesContext context); /** * @return The icon image to display next to the item links, or null for no icon @@ -240,6 +240,8 @@ public abstract class AbstractItemSelector extends UIInput return; } + NodeService service = getNodeService(context); + if (isDisabled()) { // render a read-only view of the selected category (if any) @@ -263,13 +265,12 @@ public abstract class AbstractItemSelector extends UIInput // if there is a value show it's name if (nodeRef != null) { - NodeService service = Repository.getServiceRegistry(context).getNodeService(); out.write(Repository.getNameForNode(service, nodeRef)); } } else { - // render an editable control for selecting categories + // render an editable control for selecting items String clientId = getClientId(context); StringBuilder buf = new StringBuilder(512); @@ -327,7 +328,7 @@ public abstract class AbstractItemSelector extends UIInput } else { - label = Repository.getNameForNode(getNodeService(context), value); + label = Repository.getNameForNode(service, value); showValueInHiddenField = true; } @@ -400,122 +401,95 @@ public abstract class AbstractItemSelector extends UIInput { // show the picker list // get the children of the node ref to show - NodeService service = getNodeService(context); + buf.append(""); + + // if we are setting up the initial selection we need to get the + // parent id of the initial selection so the user can actually see + // the item when the list is rendered + if (this.mode == MODE_INITIAL_SELECTION) + { + this.navigationId = getParentNodeId(context); + } + + // render "Go Up" link if not at the root level + if (this.navigationId != null) + { + // get the id of the parent node of the current navigation node, + // null indicates we are at the root level + String id = getParentNodeId(context); + + buf.append(""); + } + + String okButtonId = clientId + OK_BUTTON; + boolean okButtonEnabled = false; + + // display the children of the specified navigation node ID + Collection childRefs; + if (this.navigationId != null) + { + // get a list of children for the current navigation node + childRefs = getChildrenForNode(context); + } + else + { + // no node set - special case to show the initial root items + childRefs = getRootChildren(context); + } + UserTransaction tx = null; try { tx = Repository.getUserTransaction(context, true); tx.begin(); - buf.append("
"); + + String upImage = Utils.buildImageTag(context, WebResources.IMAGE_GO_UP, null, "absmiddle"); + + // render a link to the parent node + renderNodeLink(context, id, Application.getMessage(context, MSG_GO_UP), upImage, buf); + buf.append("
"); - - // if we are setting up the initial selection we need to get the - // parent id of the initial selection so the user can actually see - // the item when the list is rendered - if (this.mode == MODE_INITIAL_SELECTION) - { - this.navigationId = getParentNodeId(context); - } - - // render "Go Up" link - if (this.navigationId != null) - { - // get the id of the parent node of the current navigation node, - // null indicates we are at the root level - String id = getParentNodeId(context); + // render each child found + String childId = childRef.getId(); + buf.append(""); } - String okButtonId = clientId + OK_BUTTON; - boolean okButtonEnabled = false; - - // display the children of the specified navigation node ID - if (this.navigationId != null) - { - // get a list of children for the current navigation node - Collection childRefs = getChildrenForNode(context); - for (ChildAssociationRef childRef : childRefs) - { - // render each child found - String childId = childRef.getChildRef().getId(); - buf.append(""); - } - } - else - { - // no node set - special case so show the root items - Collection childRefs = getRootChildren(context); - for (ChildAssociationRef childRef : childRefs) - { - // render each root category found - String childId = childRef.getChildRef().getId(); - buf.append(""); - } - } - // render OK button String fieldValue = encodeFieldValues(MODE_CONFIRM_SELECTION, null); buf.append("
"); - buf.append("
"); - - String upImage = Utils.buildImageTag(context, WebResources.IMAGE_GO_UP, null, "absmiddle"); - - // render a link to the parent node - renderNodeLink(context, id, Application.getMessage(context, MSG_GO_UP), upImage, buf); + // get the name for the child and output as link + NodeRef childNodeRef = new NodeRef(Repository.getStoreRef(), childId); + String name = Repository.getNameForNode(service, childNodeRef); + renderNodeLink(context, childId, name, image, buf); buf.append("
"); - - // get the name for the child and output as link - NodeRef childNodeRef = new NodeRef(Repository.getStoreRef(), childId); - String name = Repository.getNameForNode(service, childNodeRef); - renderNodeLink(context, childId, name, image, buf); - buf.append("
"); - - // get the name for the child (rather than association name) - NodeRef childNodeRef = new NodeRef(Repository.getStoreRef(), childId); - String name = Repository.getNameForNode(service, childNodeRef); - renderNodeLink(context, childId, name, image, buf); - buf.append("
") @@ -680,6 +654,7 @@ public abstract class AbstractItemSelector extends UIInput this.disabled = disabled; } + // ------------------------------------------------------------------------------ // Protected helpers diff --git a/source/java/org/alfresco/web/ui/repo/component/UICategorySelector.java b/source/java/org/alfresco/web/ui/repo/component/UICategorySelector.java index e50486a2f4..4082787a69 100644 --- a/source/java/org/alfresco/web/ui/repo/component/UICategorySelector.java +++ b/source/java/org/alfresco/web/ui/repo/component/UICategorySelector.java @@ -16,6 +16,7 @@ */ package org.alfresco.web.ui.repo.component; +import java.util.ArrayList; import java.util.Collection; import javax.faces.context.FacesContext; @@ -107,14 +108,19 @@ public class UICategorySelector extends AbstractItemSelector * * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getChildrenForNode(javax.faces.context.FacesContext) */ - public Collection getChildrenForNode(FacesContext context) + public Collection getChildrenForNode(FacesContext context) { NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId); Collection childRefs = getCategoryService(context).getChildren(nodeRef, CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE); + Collection refs = new ArrayList(childRefs.size()); + for (ChildAssociationRef childRef : childRefs) + { + refs.add(childRef.getChildRef()); + } - return childRefs; + return refs; } /** @@ -122,9 +128,17 @@ public class UICategorySelector extends AbstractItemSelector * * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getRootChildren(javax.faces.context.FacesContext) */ - public Collection getRootChildren(FacesContext context) + public Collection getRootChildren(FacesContext context) { - return getCategoryService(context).getCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE); + Collection childRefs = getCategoryService(context).getCategories( + Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE); + Collection refs = new ArrayList(childRefs.size()); + for (ChildAssociationRef childRef : childRefs) + { + refs.add(childRef.getChildRef()); + } + + return refs; } /** diff --git a/source/java/org/alfresco/web/ui/repo/component/UISpaceSelector.java b/source/java/org/alfresco/web/ui/repo/component/UISpaceSelector.java index 1d8174f0e7..aca038c64f 100644 --- a/source/java/org/alfresco/web/ui/repo/component/UISpaceSelector.java +++ b/source/java/org/alfresco/web/ui/repo/component/UISpaceSelector.java @@ -23,10 +23,13 @@ import java.util.List; import javax.faces.context.FacesContext; import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; @@ -58,7 +61,8 @@ public class UISpaceSelector extends AbstractItemSelector } /** - * Returns the parent id of the current space or null if the parent space is the company home space + * Returns the parent id of the current space or null if the parent space is an immediate child + * of the repository root node or the parent is inaccessable due to permissions. * * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getParentNodeId(javax.faces.context.FacesContext) */ @@ -68,20 +72,47 @@ public class UISpaceSelector extends AbstractItemSelector if (this.navigationId != null && this.navigationId.equals(Application.getCompanyRootId()) == false) { - ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent( - new NodeRef(Repository.getStoreRef(), this.navigationId)); - id = parentRef.getParentRef().getId(); + try + { + ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent( + new NodeRef(Repository.getStoreRef(), this.navigationId)); + id = parentRef.getParentRef().getId(); + } + catch (AccessDeniedException accessErr) + { + // cannot navigate to parent id will be null + } } return id; } + + /** + * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#parentAccessable() + */ + /*public boolean parentAccessable(FacesContext context) + { + boolean accessable = false; + try + { + ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent( + new NodeRef(Repository.getStoreRef(), this.navigationId)); + parentRef.getParentRef().getId(); + accessable = true; + } + catch (AccessDeniedException accessErr) + { + // cannot navigate to parent id - not accessable + } + return accessable; + }*/ /** * Returns the child spaces of the current space * * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getChildrenForNode(javax.faces.context.FacesContext) */ - public Collection getChildrenForNode(FacesContext context) + public Collection getChildrenForNode(FacesContext context) { NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId); List allKids = getNodeService(context).getChildAssocs(nodeRef, @@ -90,13 +121,13 @@ public class UISpaceSelector extends AbstractItemSelector NodeService service = getNodeService(context); // filter out those children that are not spaces - List spaceKids = new ArrayList(); + List spaceKids = new ArrayList(); for (ChildAssociationRef ref : allKids) { if (dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_FOLDER) && dd.isSubClass(service.getType(ref.getChildRef()), ContentModel.TYPE_SYSTEM_FOLDER) == false) { - spaceKids.add(ref); + spaceKids.add(ref.getChildRef()); } } @@ -104,22 +135,26 @@ public class UISpaceSelector extends AbstractItemSelector } /** - * Returns the current users home space + * Returns the children of the initial root space * * @see org.alfresco.web.ui.repo.component.AbstractItemSelector#getRootChildren(javax.faces.context.FacesContext) */ - public Collection getRootChildren(FacesContext context) + public Collection getRootChildren(FacesContext context) { - // get the root space from the current user - //String rootId = Application.getCurrentUser(context).getHomeSpaceId(); NodeRef rootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId()); - - // get a child association reference back to the real repository root to satisfy + + // get a child association reference back from the parent node to satisfy // the generic API we have in the abstract super class - ChildAssociationRef childRefFromRealRoot = getNodeService(context).getPrimaryParent(rootRef); - List roots = new ArrayList(1); - roots.add(childRefFromRealRoot); - + PermissionService ps = Repository.getServiceRegistry(context).getPermissionService(); + if (ps.hasPermission(rootRef, PermissionService.READ) != AccessStatus.ALLOWED) + { + // get the root space from the current user home instead + String homeId = Application.getCurrentUser(context).getHomeSpaceId(); + rootRef = new NodeRef(Repository.getStoreRef(), homeId); + } + List roots = new ArrayList(1); + roots.add(rootRef); + return roots; } diff --git a/source/java/org/alfresco/web/ui/repo/tag/SystemErrorTag.java b/source/java/org/alfresco/web/ui/repo/tag/SystemErrorTag.java index 0d8f42d9ac..0efbc92ed8 100644 --- a/source/java/org/alfresco/web/ui/repo/tag/SystemErrorTag.java +++ b/source/java/org/alfresco/web/ui/repo/tag/SystemErrorTag.java @@ -171,7 +171,7 @@ public class SystemErrorTag extends TagSupport out.write("} else {\n"); out.write("document.getElementById('detailsTitle').innerHTML = '"); out.write(bundle.getString(MSG_SHOW_DETAILS)); - out.write(")';\n"); + out.write("';\n"); out.write("document.getElementById('details').style.display = 'none';\n"); out.write("hidden = true;\n"); out.write("} } \n");