Site Service: fix issue when non-admin users create site containers

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9963 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-07-21 15:52:51 +00:00
parent 1fcbb2eca2
commit cef534a8c1

View File

@@ -332,48 +332,49 @@ public class Site implements Serializable
* @param folderType folder type to create * @param folderType folder type to create
* @return ScriptNode the created container * @return ScriptNode the created container
*/ */
public ScriptNode createContainer(String componentId, String folderType, Object permissions) public ScriptNode createContainer(final String componentId, final String folderType, final Object permissions)
{ {
ScriptNode container = null; ScriptNode container = null;
try try
{ {
// Get the container type NodeRef containerNodeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
QName folderQName = (folderType == null) ? null : QName.createQName(folderType, serviceRegistry.getNamespaceService());
// Create the container node
final NodeRef containerNodeRef = this.siteService.createContainer(getShortName(), componentId, folderQName, null);
// Set any permissions that might have been provided for the container
if (permissions != null && permissions instanceof ScriptableObject)
{ {
ScriptableObject scriptable = (ScriptableObject)permissions; public NodeRef doWork() throws Exception
Object[] propIds = scriptable.getIds();
for (int i = 0; i < propIds.length; i++)
{ {
// work on each key in turn // Get the container type
Object propId = propIds[i]; QName folderQName = (folderType == null) ? null : QName.createQName(folderType, serviceRegistry.getNamespaceService());
// we are only interested in keys that are formed of Strings // Create the container node
if (propId instanceof String) NodeRef containerNodeRef = Site.this.siteService.createContainer(getShortName(), componentId, folderQName, null);
// Set any permissions that might have been provided for the container
if (permissions != null && permissions instanceof ScriptableObject)
{ {
// get the value out for the specified key - it must be String ScriptableObject scriptable = (ScriptableObject)permissions;
final String key = (String)propId; Object[] propIds = scriptable.getIds();
final Object value = scriptable.get(key, scriptable); for (int i = 0; i < propIds.length; i++)
if (value instanceof String)
{ {
AuthenticationUtil.runAs(new RunAsWork<Object>() // work on each key in turn
Object propId = propIds[i];
// we are only interested in keys that are formed of Strings
if (propId instanceof String)
{ {
public Object doWork() throws Exception // get the value out for the specified key - it must be String
final String key = (String)propId;
final Object value = scriptable.get(key, scriptable);
if (value instanceof String)
{ {
// Set the permission on the container // Set the permission on the container
Site.this.serviceRegistry.getPermissionService().setPermission(containerNodeRef, key, (String)value, true); Site.this.serviceRegistry.getPermissionService().setPermission(containerNodeRef, key, (String)value, true);
return null;
} }
}, AuthenticationUtil.SYSTEM_USER_NAME); }
} }
} }
return containerNodeRef;
} }
} }, AuthenticationUtil.SYSTEM_USER_NAME);
// Create the script node for the container // Create the script node for the container
container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope); container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);