05-06-2009 02:29 PM
script:
{
var currentUser = null;
var debug = (args.debug != null) ? args.debug : "false";
var recursive = (args.recursive != null) ? args.recursive : "false";
var impersonateUser = args.impersonate;
if (impersonateUser != null) {
currentUser = impersonation.impersonate(impersonateUser);
}
var fullpath = url.extension;
var share = null;
var filename = null;
var content = null;
var noderef = null;
var title = "";
var description = "";
// locate file attributes
for each (field in formdata.fields)
{
if (field.name == "share")
{
share = field.value;
}
else if (field.name == "noderef")
{
noderef = field.value;
}
else if (field.name == "title")
{
title = field.value;
}
else if (field.name == "desc")
{
description = field.value;
}
else if (field.name == "file" && field.isFile)
{
filename = field.filename;
content = field.content;
}
}
// ensure mandatory file attributes have been located
if (filename == undefined || content == undefined)
{
status.code = 400;
status.message = "Uploaded file cannot be located in request";
status.redirect = true;
break script;
}
// Check via the noderef
var node = null;
if (noderef != undefined && noderef != "")
{
node = search.findNode(noderef);
}
// Check share
else if (share != undefined && share != "")
{
// Get the share site
var site = siteService.getSite(share);
if (site == undefined)
{
status.code = 400;
status.message = "Site cannot be located in request";
status.redirect = true;
break script;
}
// Now get the folder
if (fullpath != undefined && fullpath != "")
{
node = site.getContainer("documentLibrary/" + fullpath);
}
else
{
node = site.getContainer("documentLibrary");
}
}
else
{
node = roothome.childByNamePath("Company Home/" + fullpath);
}
if (node == undefined)
{
status.code = 404;
status.message = "Path " + fullpath + ".";
status.redirect = true;
break script;
}
if (!node.hasPermission("Read") || !node.hasPermission("Write"))
{
status.code = 404;
status.message = "Access denied to " + fullpath + ".";
status.redirect = true;
break script;
}
var upload = null;
if (noderef != undefined && noderef != "")
{
upload = node;
}
else
{
upload = node.childByNamePath(filename);
if (upload != null)
{
if (!upload.hasPermission("Read") || !upload.hasPermission("Write"))
{
status.code = 404;
status.message = "Access denied to " + fullpath + ".";
status.redirect = true;
break script;
}
}
else
{
if (!node.hasPermission("CreateChildren"))
{
status.code = 404;
status.message = "Access denied to create files under " + fullpath + ".";
status.redirect = true;
break script;
}
upload = node.createFile(filename);
}
}
// Set the content
upload.properties.content.write(content);
upload.properties.content.guessMimetype(filename);
upload.properties.content.encoding = "UTF-8";
upload.properties.title = title;
upload.properties.description = description;
upload.save();
// Set the owner to the user who uploaded the file
if (impersonateUser != null) {
upload.setOwner(impersonateUser);
}
// setup model for response template
model.upload = upload;
model.debug = debug;
model.recursive = recursive;
if (currentUser != null) {
impersonation.impersonate(currentUser);
}
}
// String currentUser = AuthenticationUtil.getCurrentUserName();
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
if (currentUser == null || !currentUser.equals(username)) {
// AuthenticationUtil.setCurrentUser(username);
AuthenticationUtil.setRunAsUser(username);
}
return currentUser;
05-14-2009 11:00 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.