[RM-823] Hold folder is empty for all users except admin. Read permission check is hardcoded in doclist-lib.js. RM now overrides this library's main method to allow ReadRecords checks.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@54600 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jared Ottley
2013-08-28 22:49:43 +00:00
parent 4f5fec647b
commit d67d5a448e
2 changed files with 241 additions and 1 deletions

View File

@@ -4,8 +4,9 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary-v2/parse-args.lib.js">
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary-v2/rm-parse-args.lib.js">
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary-v2/doclist.lib.js">
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary-v2/rm-doclist.lib.js">
/**
* Document List Component: doclist
*/
model.doclist = doclist_main();
model.doclist = rm_doclist_main();

View File

@@ -0,0 +1,239 @@
/**
* Main entry point: Create collection of documents and folders in the given space
*
* @method rm_doclist_main
*/
function rm_doclist_main()
{
// Use helper function to get the arguments
var parsedArgs = ParseArgs.getParsedArgs();
if (parsedArgs === null)
{
return;
}
var filter = args.filter,
items = [];
// Try to find a filter query based on the passed-in arguments
var allNodes = [],
totalRecords = 0,
requestTotalCountMax = 0,
paged = false,
favourites = Common.getFavourites(),
filterParams = Filters.getFilterParams(filter, parsedArgs,
{
favourites: favourites
}),
query = filterParams.query,
allSites = (parsedArgs.nodeRef == "alfresco://sites/home");
if (logger.isLoggingEnabled())
logger.log("rm-doclist.lib.js - NodeRef: " + parsedArgs.nodeRef + " Query: " + query);
var totalItemCount = filterParams.limitResults ? parseInt(filterParams.limitResults, 10) : -1;
// For all sites documentLibrary query we pull in all available results and post filter
if (totalItemCount === 0) totalItemCount = -1;
else if (allSites) totalItemCount = (totalItemCount > 0 ? totalItemCount * 10 : 500);
var allNodesResult = doclist_getAllNodes(parsedArgs, filterParams, query, totalItemCount);
allNodes = allNodesResult.allNodes;
totalRecords = allNodesResult.totalRecords;
requestTotalCountMax = allNodesResult.requestTotalCountMax;
paged = allNodesResult.paged;
query = allNodesResult.query;
if (logger.isLoggingEnabled())
logger.log("rm-doclist.lib.js - query results: " + allNodes.length);
// Generate the qname path match regex required for all sites 'documentLibrary' results match
var pathRegex;
if (allSites)
{
// escape the forward slash characters in the qname path
// TODO: replace with java.lang.String regex match for performance
var pathMatch = new String(parsedArgs.rootNode.qnamePath).replace(/\//g, '\\/') + "\\/.*\\/cm:documentLibrary\\/.*";
pathRegex = new RegExp(pathMatch, "gi");
if (logger.isLoggingEnabled())
logger.log("rm-doclist.lib.js - will match results using regex: " + pathMatch);
}
// Ensure folders and folderlinks appear at the top of the list
var folderNodes = [],
documentNodes = [];
for each (node in allNodes)
{
if (totalItemCount !== 0)
{
try
{
if (!allSites || node.qnamePath.match(pathRegex))
{
totalItemCount--;
if (node.isContainer || node.isLinkToContainer)
{
folderNodes.push(node);
}
else
{
documentNodes.push(node);
}
}
}
catch (e)
{
// Possibly an old indexed node - ignore it
}
} else break;
}
// Node type counts
var folderNodesCount = folderNodes.length,
documentNodesCount = documentNodes.length,
nodes;
if (parsedArgs.type === "documents")
{
nodes = documentNodes;
totalRecords -= folderNodesCount;
}
else
{
// TODO: Sorting with folders at end -- swap order of concat()
nodes = folderNodes.concat(documentNodes);
}
if (logger.isLoggingEnabled())
logger.log("rm-doclist.lib.js - totalRecords: " + totalRecords);
// Pagination
var pageSize = args.size || nodes.length,
pagePos = args.pos || "1",
startIndex = (pagePos - 1) * pageSize;
if (!paged)
{
// Trim the nodes array down to the page size
nodes = nodes.slice(startIndex, pagePos * pageSize);
}
// Common or variable parent container?
var parent = null;
if (!filterParams.variablePath)
{
// Parent node permissions (and Site role if applicable)
parent = Evaluator.run(parsedArgs.pathNode, true);
}
var thumbnail = null,
locationNode,
item;
// Loop through and evaluate each node in this result set
for each (node in nodes)
{
// Get evaluated properties.
item = Evaluator.run(node);
if (item !== null)
{
item.isFavourite = (favourites[item.node.nodeRef] === true);
item.likes = Common.getLikes(node);
// Does this collection of nodes have potentially differering paths?
if (filterParams.variablePath || item.isLink)
{
locationNode = item.isLink ? item.linkedNode : item.node;
// Ensure we have Read permissions on the destination on the link object
if (!locationNode.hasPermission("ReadRecords")) continue;
location = Common.getLocation(locationNode, parsedArgs.libraryRoot);
// Parent node
if (node.parent != null && node.parent.isContainer && node.parent.hasPermission("ReadRecords"))
{
item.parent = Evaluator.run(node.parent, true);
}
}
else
{
location =
{
site: parsedArgs.location.site,
siteTitle: parsedArgs.location.siteTitle,
sitePreset: parsedArgs.location.sitePreset,
container: parsedArgs.location.container,
containerType: parsedArgs.location.containerType,
path: parsedArgs.location.path,
file: node.name
};
}
// Resolved location
item.location = location;
items.push(item);
}
else
{
--totalRecords;
}
}
// Array Remove - By John Resig (MIT Licensed)
var fnArrayRemove = function fnArrayRemove(array, from, to)
{
var rest = array.slice((to || from) + 1 || array.length);
array.length = from < 0 ? array.length + from : from;
return array.push.apply(array, rest);
};
/**
* De-duplicate orignals for any existing working copies.
* This can't be done in evaluator.lib.js as it has no knowledge of the current filter or UI operation.
* Note: This may result in pages containing less than the configured amount of items (50 by default).
*/
for each (item in items)
{
if (item.workingCopy && item.workingCopy.isWorkingCopy)
{
var workingCopySource = String(item.workingCopy.sourceNodeRef);
for (var i = 0, ii = items.length; i < ii; i++)
{
if (String(items[i].node.nodeRef) == workingCopySource)
{
fnArrayRemove(items, i);
--totalRecords;
break;
}
}
}
}
var paging =
{
totalRecords: totalRecords,
startIndex: startIndex
};
if (paged && (totalRecords == requestTotalCountMax))
{
paging.totalRecordsUpper = requestTotalCountMax;
}
return (
{
luceneQuery: query,
paging: paging,
container: parsedArgs.rootNode,
parent: parent,
onlineEditing: utils.moduleInstalled("org.alfresco.module.vti"),
itemCount:
{
folders: folderNodesCount,
documents: documentNodesCount
},
items: items,
customJSON: slingshotDocLib.getJSON()
});
}