Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

101303: Merge RA-SPRINT2 to HEAD-BUG-FIX (5.1)
      99855: RA-61: move /slingshot/profile webscripts.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@101446 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-04-08 16:06:54 +00:00
parent 3edd50bfdc
commit c5f1a7cba1
19 changed files with 0 additions and 641 deletions

View File

@@ -1,16 +0,0 @@
<webscript kind="org.alfresco.repository.content.stream">
<shortname>Avatar</shortname>
<description>
Returns a user avatar image in the format specified by the thumbnailname, or the "avatar" preset if omitted.
</description>
<url>/slingshot/profile/avatar/avatar</url>
<url>/slingshot/profile/avatar/avatar/thumbnail/{thumbnailname}</url>
<url>/slingshot/profile/avatar/{store_type}/{store_id}/{id}/thumbnail/{thumbnailname}</url>
<url>/slingshot/profile/avatar/{store_type}/{store_id}/{id}</url>
<url>/slingshot/profile/avatar/{username}/thumbnail/{thumbnailname}</url>
<url>/slingshot/profile/avatar/{username}</url>
<format default="">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,104 +0,0 @@
/**
* User Profile - User avatar GET method
*
* Returns a user avatar image in the format specified by the thumbnailname, or the "avatar" preset if omitted.
*
* @method GET
*/
function getPlaceholder(thumbnailName)
{
// Try and get the place holder resource for a png avatar.
var phPath = thumbnailService.getMimeAwarePlaceHolderResourcePath(thumbnailName, "images/png");
if (phPath == null)
{
// 404 since no thumbnail was found
status.setCode(status.STATUS_NOT_FOUND, "Thumbnail was not found and no place holder resource set for '" + thumbnailName + "'");
return;
}
return phPath;
}
function main()
{
var userName = url.templateArgs.username,
thumbnailName = url.templateArgs.thumbnailname || "avatar",
avatarNode;
// If there is no store type, store id or id on the request then this WebScript has most likely been requested
// for a user with no avatar image so we will just return the placeholder image.
if (userName == null && url.templateArgs.store_type == null && url.templateArgs.store_id == null && url.templateArgs.id == null)
{
// If there is no userName or nodeRef data then we want to return the browser cacheable placeholder...
model.contentPath = getPlaceholder(thumbnailName);
model.allowBrowserToCache = "true";
return;
}
else if (url.templateArgs.store_type == null && url.templateArgs.store_id == null && url.templateArgs.id == null)
{
// There is no nodeRef data but there is a username... this should return the user image that needs revalidation
var person = people.getPerson(userName);
if (person == null)
{
// Stream the placeholder image
model.contentPath = getPlaceholder(thumbnailName);
return;
}
else
{
// Retrieve the avatar NodeRef for this person, if there is one.
var avatarAssoc = person.assocs["cm:avatar"];
if (avatarAssoc != null)
{
avatarNode = avatarAssoc[0];
}
}
}
else if (userName == null)
{
// There is no user name but there is nodeREf data... this should return the image that CAN be cached by the browser
model.allowBrowserToCache = "true";
avatarNode = search.findNode(url.templateArgs.store_type + "://" + url.templateArgs.store_id + "/" + url.templateArgs.id);
if (avatarNode == null)
{
// Stream the placeholder image if the avatar node cannot be found.
model.contentPath = getPlaceholder(thumbnailName);
return;
}
}
// Get the thumbnail for the avatar...
if (avatarNode != null)
{
// Get the thumbnail
var thumbnail = avatarNode.getThumbnail(thumbnailName);
if (thumbnail == null || thumbnail.size == 0)
{
// Remove broken thumbnail
if (thumbnail != null)
{
thumbnail.remove();
}
// Force the creation of the thumbnail
thumbnail = avatarNode.createThumbnail(thumbnailName, false);
if (thumbnail != null)
{
model.contentNode = thumbnail;
return;
}
}
else
{
// Place the details of the thumbnail into the model, this will be used to stream the content to the client
model.contentNode = thumbnail;
return;
}
}
// Stream the placeholder image
model.contentPath = getPlaceholder(thumbnailName);
}
main();

View File

@@ -1,9 +0,0 @@
<webscript>
<shortname>Reset Avatar image</shortname>
<description>User Profile - Reset Avatar image for a user</description>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<url>/slingshot/profile/resetavatar/{userName}</url>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,3 +0,0 @@
{
"success": ${success?string}
}

View File

@@ -1,46 +0,0 @@
/**
* User Profile - Reset user avatar REST method
*
* Current user can only modify their own settings or an admin can reset all.
*
* @method PUT
*/
function main()
{
// Get the person details and ensure they exist for update
var userName = url.extension;
var user = people.getPerson(userName);
if (user == null)
{
status.setCode(status.STATUS_NOT_FOUND, "Person " + userName + " does not exist");
return;
}
// ensure we found a valid user and that it is the current user or we are an admin
if (user == null ||
(people.isAdmin(person) == false && user.properties.userName != person.properties.userName))
{
status.code = 500;
status.message = "Failed to locate user to modify or permission denied.";
status.redirect = true;
return;
}
// remove old image child node if we have one
var assocs = user.childAssocs["cm:preferenceImage"];
if (assocs != null && assocs.length == 1)
{
assocs[0].remove();
}
// remove 'cm:avatar' target association - backward compatible with JSF web-client avatar
assocs = user.associations["cm:avatar"];
if (assocs != null && assocs.length == 1)
{
user.removeAssociation(assocs[0], "cm:avatar");
}
model.success = true;
}
main();

View File

@@ -1,9 +0,0 @@
<webscript>
<shortname>Avatar Upload</shortname>
<description>Upload avatar file content and apply to person preferences</description>
<format default="json" />
<authentication>user</authentication>
<transaction>required</transaction>
<url>/slingshot/profile/uploadavatar</url>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,15 +0,0 @@
<html>
<head>
<title>Upload Avatar Success</title>
</head>
<body>
<#if (args.success!"")?matches("^[\\w\\d\\._]+$")>
<script type="text/javascript">
${args.success}({
nodeRef: "${image.nodeRef}",
fileName: "${image.name}"
});
</script>
</#if>
</body>
</html>

View File

@@ -1,19 +0,0 @@
<html>
<head>
<title>Upload Avatar Failure</title>
</head>
<body>
<#if (args.failure!"")?matches("^[\\w\\d\\._]+$")>
<script type="text/javascript">
${args.failure}({
status: {
"code" : ${status.code},
"name" : "${status.codeName}",
"description" : "${status.codeDescription}"
},
message: "${jsonUtils.encodeJSONString(status.message)}"
});
</script>
</#if>
</body>
</html>

View File

@@ -1,115 +0,0 @@
/**
* User Profile Avatar Upload method
*
* @method POST
* @param username {string}
* filedata {file}
*/
function main()
{
try
{
var filename = null;
var content = null;
var username = null;
// locate file attributes
for each (field in formdata.fields)
{
if (field.name == "filedata" && field.isFile)
{
filename = field.filename;
content = field.content;
}
else if (field.name == "username")
{
username = field.value;
}
}
// ensure all mandatory attributes have been located
if (filename == undefined || content == undefined)
{
status.code = 400;
status.message = "Uploaded file cannot be located in request";
status.redirect = true;
return;
}
if (username == null || username.length == 0)
{
status.code = 500;
status.message = "Username parameter not supplied.";
status.redirect = true;
return;
}
var user = people.getPerson(username);
// ensure we found a valid user and that it is the current user or we are an admin
if (user == null ||
(people.isAdmin(person) == false && user.properties.userName != person.properties.userName))
{
status.code = 500;
status.message = "Failed to locate user to modify or permission denied.";
status.redirect = true;
return;
}
// ensure cm:person has 'cm:preferences' aspect applied - as we want to add the avatar as
// the child node of the 'cm:preferenceImage' association
if (!user.hasAspect("cm:preferences"))
{
user.addAspect("cm:preferences");
}
// remove old image child node if we already have one
var assocs = user.childAssocs["cm:preferenceImage"];
if (assocs != null && assocs.length == 1)
{
assocs[0].remove();
}
// create the new image node
var image = user.createNode(filename, "cm:content", "cm:preferenceImage");
image.properties.content.write(content);
image.properties.content.guessMimetype(filename);
if (image.properties.content.getMimetype().indexOf("image/") != 0)
{
user.removeNode(image);
status.code = 500;
status.message = " Only image files are allowed for user avatar.";
status.redirect = true;
return;
}
image.properties.content.encoding = "UTF-8";
image.save();
// wire up 'cm:avatar' target association - backward compatible with JSF web-client avatar
assocs = user.associations["cm:avatar"];
if (assocs != null && assocs.length == 1)
{
user.removeAssociation(assocs[0], "cm:avatar");
}
user.createAssociation(image, "cm:avatar");
// save ref to be returned
model.image = image;
}
catch (e)
{
var x = e;
status.code = 500;
status.message = "Unexpected error occured during upload of new content.";
if(x.message && x.message.indexOf("org.alfresco.service.cmr.usage.ContentQuotaException") == 0)
{
status.code = 413;
status.message = x.message;
}
status.redirect = true;
return;
}
}
main();

View File

@@ -1,12 +0,0 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"nodeRef": "${image.nodeRef}",
"fileName": "${image.name}",
"status":
{
"code": 200,
"name": "OK",
"description" : "File uploaded successfully"
}
}
</#escape>

View File

@@ -1,9 +0,0 @@
<webscript>
<shortname>Last edited user contents</shortname>
<description>Last edited user contents</description>
<format default="json" />
<authentication>guest</authentication>
<url>/slingshot/profile/usercontents</url>
<transaction allow="readonly">required</transaction>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,90 +0,0 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js">
var maxResults = (args.maxResults !== undefined) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS;
function padZeros(number)
{
return (number < 10) ? '0' + number : number;
}
function getContents(user, type)
{
// set range to within last 28 days
var date = new Date();
var toQuery = date.getFullYear() + "-" + padZeros((date.getMonth()+1)) + "-" + padZeros(date.getDate());
date.setDate(date.getDate() - 28);
var fromQuery = date.getFullYear() + "-" + padZeros((date.getMonth()+1)) + "-" + padZeros(date.getDate());
var userProperty = (type == 'created') ? 'creator' : 'modifier';
var getBlogPostsQuery = function getBlogPosts()
{
return 'PATH:"/app:company_home/st:sites/*/cm:blog/*" ' +
'AND +TYPE:"cm:content" ' +
'AND +@cm:' + userProperty + ':"' + user + '" ' +
'AND +@cm:' + type + ':["' + fromQuery + '" TO "' + toQuery + '"]';
};
var getWikiPagesQuery = function getWikiPagesQuery()
{
return 'PATH:"/app:company_home/st:sites/*/cm:wiki/*" ' +
'AND +TYPE:"cm:content" ' +
'AND +@cm:' + userProperty + ':"' + user + '" ' +
'AND +@cm:' + type + ':["' + fromQuery + '" TO "' + toQuery + '"]';
};
var getDiscussionsQuery = function getDiscussionsQuery()
{
return 'PATH:"/app:company_home/st:sites/*/cm:discussions//*" ' +
'AND +TYPE:"fm:post" ' +
'AND +@cm:' + userProperty + ':"' + user + '" ' +
'AND +@cm:' + type + ':["' + fromQuery + '" TO "' + toQuery + '"]';
};
var getDocumentsQuery = function getDocumentsQuery()
{
return 'TYPE:"cm:content" ' +
'AND +@cm:' + userProperty + ':"' + user + '" ' +
'AND +@cm:' + type + ':["' + fromQuery + '" TO "' + toQuery + '"] AND -QNAME:comment\\-*';
};
var sortColumns = [];
sortColumns.push(
{
column: "@" + utils.longQName("cm:" + type),
ascending: false
});
var queryDef = {
query: "",
language: "fts-alfresco",
page: {maxItems: maxResults},
onerror: "no-results",
sort: sortColumns
};
// perform fts-alfresco language queries
var results;
queryDef.query = getBlogPostsQuery();
results = search.query(queryDef);
queryDef.query = getWikiPagesQuery();
results = results.concat(search.query(queryDef));
queryDef.query = getDiscussionsQuery();
results = results.concat(search.query(queryDef));
queryDef.query = getDocumentsQuery();
results = results.concat(search.query(queryDef));
results.sort(function(a, b)
{
var date1 = a.properties[type].getTime(),
date2 = b.properties[type].getTime();
return (date1 < date2) ? 1 : (date1 > date2) ? -1 : 0;
}
);
return processResults(results, maxResults);
}
model.data = [];
model.data['created'] = getContents(args.user, 'created', maxResults);
model.data['modified'] = getContents(args.user, 'modified', maxResults);

View File

@@ -1,37 +0,0 @@
<#macro dateFormat date>${date?string("yyyy-MM-dd'T'HH:mm:ss.SSSZ")}</#macro>
<#macro formatDataItems data>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"items":
[
<#list data.items as item>
{
"nodeRef": "${item.nodeRef}",
"type": "${item.type}",
"name": "${item.name!''}",
"displayName": "${item.displayName!''}",
"description": "${item.description!''}",
"createdOn": "<@dateFormat item.createdOn />",
"createdBy": "${item.createdBy!''}",
"createdByUser": "${item.createdByUser!''}",
"modifiedOn": "<@dateFormat item.modifiedOn />",
"modifiedByUser": "${item.modifiedByUser}",
"modifiedBy": "${item.modifiedBy}",
"size": ${item.size?c},
<#if item.site??>"site":
{
"shortName": "${item.site.shortName}",
"title": "${item.site.title}"
},</#if>
"container": "${item.container!""}",
"tags": [<#list item.tags as tag>"${tag}"<#if tag_has_next>,</#if></#list>]
}<#if item_has_next>,</#if>
</#list>
]
}
</#escape>
</#macro>
{
"created": <@formatDataItems data['created'] />,
"modified": <@formatDataItems data['modified'] />
}

View File

@@ -1,9 +0,0 @@
<webscript>
<shortname>User Profile</shortname>
<description>User Profile POST for update</description>
<format default="json" />
<authentication>user</authentication>
<transaction>required</transaction>
<url>/slingshot/profile/userprofile</url>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,3 +0,0 @@
{
"success": ${success?string}
}

View File

@@ -1,88 +0,0 @@
/**
* User Profile REST Update method
*
* @method POST
* @param json {string}
* {
* username: "username",
* properties:
* {
* "cm:propname": "value"
* ...
* },
* content:
* {
* "cm:contentpropname": "contentstringvalue"
* ...
* }
* }
*/
function main()
{
model.success = false;
var username = json.get("username");
if (username == null)
{
status.code = 400;
status.message = "Username parameter not supplied.";
status.redirect = true;
return;
}
var user = people.getPerson(username);
// ensure we found a valid user and that it is the current user or we are an admin
if (user == null ||
(people.isAdmin(person) == false && user.properties.userName != person.properties.userName))
{
status.code = 500;
status.message = "Failed to locate user to modify or permission denied.";
status.redirect = true;
return;
}
if (json.has("properties"))
{
var props = json.get("properties");
if (props != null)
{
var names = props.names();
for (var i=0; i<props.length(); i++)
{
var propname = names.get(i);
var propval = props.get(propname);
// set simple text properties
user.properties[propname] = propval;
// update userStatusTime if updating userStatus
if (propname.toLowerCase() == "cm:userstatus")
{
user.properties["cm:userStatusTime"] = new Date();
}
}
}
}
if (json.has("content"))
{
var props = json.get("content");
if (props != null)
{
var names = props.names();
for (var i=0; i<props.length(); i++)
{
var propname = names.get(i);
var propval = props.get(propname);
// set content property
user.properties[propname].content = propval;
}
}
}
user.save();
model.success = true;
}
main();

View File

@@ -1,9 +0,0 @@
<webscript>
<shortname>User Status</shortname>
<description>User Status POST for update</description>
<format default="json" />
<authentication>user</authentication>
<transaction>required</transaction>
<url>/slingshot/profile/userstatus</url>
<lifecycle>internal</lifecycle>
</webscript>

View File

@@ -1,9 +0,0 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
<#if success>
"userStatus": "${userStatus}",
"userStatusTime": { "iso8601": "${xmldate(userStatusTime)}"},
</#if>
"success": ${success?string}
}
</#escape>

View File

@@ -1,39 +0,0 @@
/**
* User Status REST Update method
*
* @method POST
* @param json {string}
* {
* status: "value"
* }
*/
function main()
{
model.success = false;
if (json.has("status"))
{
var newStatus = json.get("status");
if (newStatus != null)
{
var statusTime = new Date();
person.properties["cm:userStatus"] = newStatus;
person.properties["cm:userStatusTime"] = statusTime;
person.save();
model.success = true;
model.userStatus = newStatus;
model.userStatusTime = statusTime;
if (newStatus.trim() != "")
{
var activity = {};
activity.status = newStatus;
activities.postActivity("org.alfresco.profile.status-changed", null, "profile", jsonUtils.toJSONString(activity));
}
}
}
}
main();