From c29f0fd4f1e8f00a933662e590dc9c5ee532055d Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 5 May 2006 12:09:15 +0000 Subject: [PATCH] . Rhino JavaScript integration: - APIs for testing of Permissions and checking that an Aspect exists on a node . Added new command processor to config for Command Servlet - new command processor to allow execution of Alfresco JavaScript files via URLs - Wiki docs: http://wiki.alfresco.com/wiki/URL_Addressability#Script_Command_Processor . Fixed issue where a deleted/missing NodeRef on the end of a Link object would cause errors in the web-client - Still needs cleanup/change to assoc mechanism as per AWC-647 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2774 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/Node.java | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/Node.java b/source/java/org/alfresco/repo/jscript/Node.java index 9e26f3a787..de3c1d38b4 100644 --- a/source/java/org/alfresco/repo/jscript/Node.java +++ b/source/java/org/alfresco/repo/jscript/Node.java @@ -45,6 +45,7 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.TemplateImageResolver; +import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; @@ -305,7 +306,7 @@ public final class Node implements Serializable * * The Map returned implements the Scriptable interface to allow access to the assoc arrays via * JavaScript associative array access. This means associations of this node can be access thus: - * node.getAssocs()["translations"][0] + * node.assocs["translations"][0] * * @return associations as a Map of assoc name to an Array of Nodes. */ @@ -351,7 +352,7 @@ public final class Node implements Serializable * * The Map returned implements the Scriptable interface to allow access to the properties via * JavaScript associative array access. This means properties of a node can be access thus: - * node.getProperties()["name"] + * node.properties["name"] * * @return Map of properties for this Node. */ @@ -454,28 +455,30 @@ public final class Node implements Serializable */ public boolean hasAspect(String aspect) { - if (this.aspects == null) + return getAspects().contains(createQName(aspect)); + } + + /** + * Return true if the user has the specified permission on the node. + *

+ * The default permissions are found in org.alfresco.service.cmr.security.PermissionService. + * Most commonly used are "Write", "Delete" and "AddChildren". + * + * @param permission as found in org.alfresco.service.cmr.security.PermissionService + * + * @return true if the user has the specified permission on the node. + */ + public boolean hasPermission(String permission) + { + boolean allowed = false; + + if (permission != null && permission.length() != 0) { - this.aspects = this.nodeService.getAspects(this.nodeRef); + AccessStatus status = this.services.getPermissionService().hasPermission(this.nodeRef, permission); + allowed = (AccessStatus.ALLOWED == status); } - if (aspect.startsWith(NAMESPACE_BEGIN)) - { - return aspects.contains((createQName(aspect))); - } - else - { - boolean found = false; - for (QName qname : this.aspects) - { - if (qname.toPrefixString(this.services.getNamespaceService()).equals(aspect)) - { - found = true; - break; - } - } - return found; - } + return allowed; } /** @@ -996,6 +999,19 @@ public final class Node implements Serializable return success; } + /** + * Add an aspect to the Node. As no properties are provided in this call, it can only be + * used to add aspects that do not require any mandatory properties. + * + * @param type Type name of the aspect to add + * + * @return true if the aspect was added successfully, false if an error occured. + */ + public boolean addAspect(String type) + { + return addAspect(type, null); + } + /** * Add an aspect to the Node. * @@ -1059,6 +1075,13 @@ public final class Node implements Serializable return success; } + /** + * Helper to create a QName from either a fully qualified or short-name QName string + * + * @param s Fully qualified or short-name QName string + * + * @return QName + */ private QName createQName(String s) { QName qname;