diff --git a/.gitignore b/.gitignore index 6e7b0a3..190e4e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target -/alf_data_dev +/alf_data_dev** .idea/** alfresco.log share.log @@ -7,3 +7,6 @@ solr.log alfresco.log.* share.log.* solr.log.* +@@ALFRESCO_SOLR4_DATA_DIR@@/ + +**.iml diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/favorites/ScriptFavoritesService.java b/src/main/java/de/jgoldhammer/alfresco/jscript/favorites/ScriptFavoritesService.java index 5f7ede4..09464e0 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/favorites/ScriptFavoritesService.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/favorites/ScriptFavoritesService.java @@ -4,13 +4,11 @@ package de.jgoldhammer.alfresco.jscript.favorites; import com.google.common.base.Preconditions; -import de.jgoldhammer.alfresco.jscript.jobs.ScriptJob; import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; import org.alfresco.repo.favourites.PersonFavourite; import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.ScriptNode; -import org.alfresco.repo.processor.BaseProcessorExtension; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.DictionaryService; diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/hidden/ScriptHiddenAspect.java b/src/main/java/de/jgoldhammer/alfresco/jscript/hidden/ScriptHiddenAspect.java index 3a8aefa..48ee1c5 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/hidden/ScriptHiddenAspect.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/hidden/ScriptHiddenAspect.java @@ -3,6 +3,8 @@ import com.google.common.base.Preconditions; import org.alfresco.repo.jscript.ScriptNode; import org.alfresco.repo.model.filefolder.HiddenAspect; +import org.alfresco.repo.model.filefolder.HiddenFileInfo; +import org.alfresco.service.cmr.repository.NodeRef; /** * wraps the api to hide nodes for certain clients or completely... @@ -20,5 +22,28 @@ public void hideNodeExplicit(ScriptNode scriptNode){ hiddenAspect.hideNodeExplicit(scriptNode.getNodeRef()); } + public void unhideNode(ScriptNode scriptNode){ + Preconditions.checkNotNull(scriptNode); + hiddenAspect.unhideExplicit(scriptNode.getNodeRef()); + } + + public boolean hasHiddenAspect(ScriptNode scriptNode){ + Preconditions.checkNotNull(scriptNode); + return hiddenAspect.hasHiddenAspect(scriptNode.getNodeRef()); + } + + public void removeHiddenAspect(ScriptNode scriptNode){ + Preconditions.checkNotNull(scriptNode); + hiddenAspect.removeHiddenAspect(scriptNode.getNodeRef()); + } + + public HiddenFileInfo onHiddenPath(ScriptNode scriptNode){ + Preconditions.checkNotNull(scriptNode); + return hiddenAspect.onHiddenPath(scriptNode.getNodeRef()); + } + + + + } diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/messages/MessageScript.java b/src/main/java/de/jgoldhammer/alfresco/jscript/messages/ScriptMessageService.java similarity index 72% rename from src/main/java/de/jgoldhammer/alfresco/jscript/messages/MessageScript.java rename to src/main/java/de/jgoldhammer/alfresco/jscript/messages/ScriptMessageService.java index 6c2ccef..68f3b70 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/messages/MessageScript.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/messages/ScriptMessageService.java @@ -1,10 +1,13 @@ package de.jgoldhammer.alfresco.jscript.messages; import java.util.List; +import java.util.Set; +import com.google.common.base.Preconditions; import org.alfresco.repo.i18n.MessageService; import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.ValueConverter; +import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; /** @@ -12,7 +15,7 @@ * * copied from https://github.com/bluedolmen/App-blue-courrier/blob/ba0fa1e8119419fdb3bb3ccf844e60ad9df9a736/alfresco-extensions/src/main/java/org/bluedolmen/repo/jscript/MessageScript.java */ -public class MessageScript extends BaseScopableProcessorExtension { +public class ScriptMessageService extends BaseScopableProcessorExtension { private final ValueConverter valueConverter = new ValueConverter(); @@ -31,13 +34,19 @@ public String get(String messageKey, Scriptable params) { public String getMessage(String messageKey, Scriptable params) { final Object convertedValue = valueConverter.convertValueForJava(params); - if (!(convertedValue instanceof List)) return null; - + Preconditions.checkArgument(convertedValue instanceof List); + final List paramsList = (List) convertedValue; final Object[] paramsArray = paramsList.toArray(); return messageService.getMessage(messageKey, paramsArray); } + + public Scriptable getRegisteredBundles(){ + Set registeredBundles = messageService.getRegisteredBundles(); + return Context.getCurrentContext().newArray(getScope(),registeredBundles.toArray(new Object[registeredBundles.size()])); + + } // IoC diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/model/ScriptModelService.java b/src/main/java/de/jgoldhammer/alfresco/jscript/model/ScriptModelService.java index 649541a..13e3055 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/model/ScriptModelService.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/model/ScriptModelService.java @@ -1,8 +1,10 @@ package de.jgoldhammer.alfresco.jscript.model; import org.alfresco.query.PagingRequest; +import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.ScriptNode; import org.alfresco.repo.processor.BaseProcessorExtension; +import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.CustomModelDefinition; import org.alfresco.service.cmr.dictionary.CustomModelService; @@ -15,19 +17,10 @@ /** * Created by jgoldhammer on 17.09.16. */ -public class ScriptModelService extends BaseProcessorExtension { +public class ScriptModelService extends BaseScopableProcessorExtension { CustomModelService customModelService; ServiceRegistry serviceRegistry; - Scriptable scope; - - /** - * @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable) - */ - public void setScope(Scriptable scope) - { - this.scope = scope; - } public void setServiceRegistry(ServiceRegistry serviceRegistry) { this.serviceRegistry = serviceRegistry; @@ -37,6 +30,14 @@ public void setCustomModelService(CustomModelService customModelService) { this.customModelService = customModelService; } + /** + * checks whether the current user is a model admin... + * @return true if the user is a model admin or super admin, false if not + */ + public boolean isModelAdmin(){ + return customModelService.isModelAdmin(AuthenticationUtil.getRunAsUser()); + } + /** * activates a custom model by name * @@ -65,7 +66,8 @@ public ScriptNode getModelNode(String model){ public Scriptable getCustomModels(int start, int end){ List customModels = customModelService.getCustomModels(new PagingRequest(start, end)).getPage(); - return Context.getCurrentContext().newArray(scope,customModels.toArray(new Object[customModels.size()])); + return Context.getCurrentContext().newArray(getScope(),customModels.toArray(new Object[customModels.size()])); } + } diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/permission/ScriptPermissionService.java b/src/main/java/de/jgoldhammer/alfresco/jscript/permission/ScriptPermissionService.java index afba311..76b9497 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/permission/ScriptPermissionService.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/permission/ScriptPermissionService.java @@ -20,19 +20,19 @@ import com.google.common.base.Preconditions; import org.alfresco.repo.jscript.BaseScopableProcessorExtension; +import org.alfresco.repo.jscript.People; import org.alfresco.repo.jscript.ScriptNode; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; -import org.apache.commons.lang3.StringUtils; +import org.jbpm.graph.action.Script; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; -import java.util.ArrayList; -import java.util.List; import java.util.Set; /** @@ -47,26 +47,49 @@ public class ScriptPermissionService extends BaseScopableProcessorExtension { private RetryingTransactionHelper retryingTransactionHelper; - public boolean hasReadPermission(String nodeRef){ + public boolean hasReadPermission(String nodeRef) { Preconditions.checkNotNull(nodeRef); - return permissionService.hasReadPermission(new NodeRef(nodeRef))==AccessStatus.ALLOWED; + return permissionService.hasReadPermission(new NodeRef(nodeRef)) == AccessStatus.ALLOWED; } - public boolean hasPermission(String nodeRef, String permission){ + public boolean hasPermission(String nodeRef, String permission) { Preconditions.checkNotNull(nodeRef); Preconditions.checkNotNull(permission); - return permissionService.hasPermission(new NodeRef(nodeRef), permission)==AccessStatus.ALLOWED; + return permissionService.hasPermission(new NodeRef(nodeRef), permission) == AccessStatus.ALLOWED; } - public boolean hasPermission(String nodeRef, String permission, String authority){ + public boolean hasPermission(String nodeRef, String permission, String authority) { Preconditions.checkNotNull(nodeRef); Preconditions.checkNotNull(permission); Preconditions.checkNotNull(authority); - return AuthenticationUtil.runAs(() -> - permissionService.hasPermission(new NodeRef(nodeRef), permission) == AccessStatus.ALLOWED, authority); + return AuthenticationUtil.runAs(() -> + permissionService.hasPermission(new NodeRef(nodeRef), permission) == AccessStatus.ALLOWED, authority); } + public boolean hasReadPermission(ScriptNode node) { + Preconditions.checkNotNull(node); + return permissionService.hasReadPermission(node.getNodeRef()) == AccessStatus.ALLOWED; + } + + public boolean hasPermission(ScriptNode node, String permission) { + Preconditions.checkNotNull(node); + Preconditions.checkNotNull(permission); + return permissionService.hasPermission(node.getNodeRef(), permission) == AccessStatus.ALLOWED; + } + + + public boolean hasPermission(ScriptNode node, String permission, ScriptNode authority) { + Preconditions.checkNotNull(node); + Preconditions.checkNotNull(permission); + Preconditions.checkNotNull(authority); + + return AuthenticationUtil.runAs(() -> + permissionService.hasPermission(node.getNodeRef(), permission) == AccessStatus.ALLOWED, (String) authority.getProperties().get("userName")); + } + + + /** * sets a new permission for a certain authority on a certain node by specifying if the permission is allowed or denied. * @@ -94,6 +117,43 @@ public void setPermission( ); } + /** + * get the permissions of a node as native javascript array of type AccessPermission + * + * @param nodeRef the node to get the permissions for + */ + public Scriptable getPermissions(String nodeRef){ + Preconditions.checkNotNull(nodeRef); + Set permissions = permissionService.getPermissions(new NodeRef(nodeRef)); + Object[] permissionsArray = permissions.toArray(new Object[permissions.size()]); + + return Context.getCurrentContext().newArray(getScope(), permissionsArray); + + } + + /** + * get the current user permissions of a node as native javascript array of type AccessPermission + * + * @param node the scriptnode + */ + public Scriptable getPermissionsOfCurrentUser(ScriptNode node){ + Preconditions.checkNotNull(node); + return getPermissions(node.getNodeRef().toString()); + } + + /** + * get all permissions of a node as native javascript array of type AccessPermission + * + * @param node the scriptnode + */ + public Scriptable getAllPermissions(ScriptNode node){ + Preconditions.checkNotNull(node); + Set permissions = permissionService.getAllSetPermissions(node.getNodeRef()); + + Object[] permissionsArray = permissions.toArray(new Object[permissions.size()]); + return Context.getCurrentContext().newArray(getScope(), permissionsArray); + } + /** * delete a certain permission for a certain authority on a certain node. * diff --git a/src/main/java/de/jgoldhammer/alfresco/jscript/globalproperties/ScriptGlobalProperties.java b/src/main/java/de/jgoldhammer/alfresco/jscript/variables/ScriptVariablesService.java similarity index 82% rename from src/main/java/de/jgoldhammer/alfresco/jscript/globalproperties/ScriptGlobalProperties.java rename to src/main/java/de/jgoldhammer/alfresco/jscript/variables/ScriptVariablesService.java index 6b0bdec..eb294aa 100644 --- a/src/main/java/de/jgoldhammer/alfresco/jscript/globalproperties/ScriptGlobalProperties.java +++ b/src/main/java/de/jgoldhammer/alfresco/jscript/variables/ScriptVariablesService.java @@ -1,4 +1,4 @@ -package de.jgoldhammer.alfresco.jscript.globalproperties; +package de.jgoldhammer.alfresco.jscript.variables; import java.util.Properties; import org.alfresco.repo.jscript.BaseScopableProcessorExtension; @@ -7,7 +7,7 @@ * Expose global properties to js scripts * */ -public class ScriptGlobalProperties extends BaseScopableProcessorExtension { +public class ScriptVariablesService extends BaseScopableProcessorExtension { private Properties properties; diff --git a/src/main/resources/alfresco/module/alfresco-jscript-extension/module-context.xml b/src/main/resources/alfresco/module/alfresco-jscript-extension/module-context.xml index 447dac0..6fc2306 100644 --- a/src/main/resources/alfresco/module/alfresco-jscript-extension/module-context.xml +++ b/src/main/resources/alfresco/module/alfresco-jscript-extension/module-context.xml @@ -145,7 +145,7 @@ - +