From dc1ba628227b4b72376ba05830382f1e5ff16586 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Wed, 28 Mar 2007 12:35:25 +0000 Subject: [PATCH] Added getPermissions() missing API for JavaScript Node. Returns all permissions set on a node - helps to solve requirements such as http://forums.alfresco.com/viewtopic.php?p=18928#18928 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5429 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/Node.java | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/Node.java b/source/java/org/alfresco/repo/jscript/Node.java index 6bdbf8553c..ad5e08e2ec 100644 --- a/source/java/org/alfresco/repo/jscript/Node.java +++ b/source/java/org/alfresco/repo/jscript/Node.java @@ -58,6 +58,7 @@ import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.search.QueryParameterDefinition; +import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.version.Version; @@ -549,30 +550,6 @@ public class Node implements Serializable, Scopeable 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) - { - ParameterCheck.mandatory("Permission Name", permission); - - boolean allowed = false; - - if (permission != null && permission.length() != 0) - { - AccessStatus status = this.services.getPermissionService().hasPermission(this.nodeRef, permission); - allowed = (AccessStatus.ALLOWED == status); - } - - return allowed; - } - /** * @return Display path to this node */ @@ -829,6 +806,54 @@ public class Node implements Serializable, Scopeable // ------------------------------------------------------------------------------ // Security API + /** + * 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) + { + ParameterCheck.mandatory("Permission Name", permission); + + boolean allowed = false; + + if (permission != null && permission.length() != 0) + { + AccessStatus status = this.services.getPermissionService().hasPermission(this.nodeRef, permission); + allowed = (AccessStatus.ALLOWED == status); + } + + return allowed; + } + + /** + * @return Array of permissions applied to this Node. + * Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example + * ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character. + */ + public String[] getPermissions() + { + String userName = this.services.getAuthenticationService().getCurrentUserName(); + Set acls = this.services.getPermissionService().getAllSetPermissions(getNodeRef()); + String[] permissions = new String[acls.size()]; + int count = 0; + for (AccessPermission permission : acls) + { + StringBuilder buf = new StringBuilder(64); + buf.append(permission.getAccessStatus()) + .append(';') + .append(permission.getAuthority()) + .append(';') + .append(permission.getPermission()); + permissions[count++] = buf.toString(); + } + return permissions; + } + /** * @return true if the node inherits permissions from the parent node, false otherwise */