Fix to Site Profile dashlet to handle missing "isPublic" flag.

Refactor of upload webscript to fix issue with missing document reference and reduce code paths.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10118 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-07-30 11:38:03 +00:00
parent abc20e4b06
commit 9392bbf502

View File

@@ -1,23 +1,25 @@
var filename = null;
var content = null;
var mimetype = null;
var siteId = null;
var containerId = null;
var thumbnailNames = null;
// Upload specific
var uploadDirectory = null;
var title = "";
var overwrite = true; // If a filename clashes for a versionable file
// Update specific
var updateNodeRef = null;
var majorVersion = false;
var description = "";
// Parse file attributes
for each (field in formdata.fields)
function main()
{
var filename = null;
var content = null;
var mimetype = null;
var siteId = null;
var containerId = null;
var thumbnailNames = null;
// Upload specific
var uploadDirectory = null;
var title = "";
var overwrite = true; // If a filename clashes for a versionable file
// Update specific
var updateNodeRef = null;
var majorVersion = false;
var description = "";
// Parse file attributes
for each (field in formdata.fields)
{
switch (String(field.name).toLowerCase())
{
case "filedata":
@@ -79,26 +81,26 @@ for each (field in formdata.fields)
thumbnailNames = field.value;
break;
}
}
}
// Ensure mandatory file attributes have been located
if (siteId === null || containerId === null || filename === null || content === null)
{
// Ensure mandatory file attributes have been located
if (siteId === null || containerId === null || filename === null || content === null)
{
status.code = 400;
status.message = "Required parameters are missing";
//status.redirect = false;
}
else
{
status.redirect = true;
return;
}
var site = siteService.getSite(siteId);
if (site === null)
{
status.code = 404;
status.message = "Site (" + siteId + ") not found.";
status.redirect = true;
return;
}
else
{
// Upload mode, since uploadDirectory was used
var container = site.getContainer(containerId);
if (container === null)
@@ -123,8 +125,10 @@ else
status.code = 404;
status.message = "Cannot upload document since updateNodeRef '" + updateNodeRef + "' points to a locked document, supply a nodeRef to its working copy instead.";
status.redirect = true;
return;
}
else if (!workingCopy.hasAspect("cm:workingcopy"))
if (!workingCopy.hasAspect("cm:workingcopy"))
{
// It's not a working copy, do a check out to get the working copy
workingCopy = workingCopy.checkout();
@@ -147,10 +151,10 @@ else
status.code = 404;
status.message = "Cannot upload file since uploadDirectory '" + uploadDirectory + "' does not exist.";
status.redirect = true;
return;
}
var existingFile = container.childByNamePath(uploadDirectory + filename);
var overwritten = false;
if (existingFile !== null)
{
// File already exists, decide what to do
@@ -159,8 +163,7 @@ else
// Upload component was configured to overwrite files if name clashes
existingFile.properties.content.write(content);
model.document = existingFile;
// Stop creation of new file below
overwritten = true;
return;
}
else
{
@@ -178,8 +181,6 @@ else
}
// save the new file (original or renamed file) as long as an overwrite hasn't been performed
if (!overwritten)
{
var newFile = destNode.createFile(filename);
newFile.properties.contentType = contentType;
newFile.properties.content.write(content);
@@ -190,8 +191,8 @@ else
newFile.properties.description = description;
// Make file versionable (todo: check that this is ok depending on version store development)
newFile.addAspect("cm:versionable");
// Save new file
newFile.save();
// Create thumbnail?
if (thumbnailNames != null)
{
@@ -207,12 +208,13 @@ else
}
model.document = newFile;
}
}
else
{
status.code = 404;
status.message = "Illegal arguments: updateNodeRef OR uploadDirectory must be provided (not both)";
status.redirect = true;
}
return;
}
}
main();