diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.ftl index 2b5d575820..ce5a7d48f2 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.ftl @@ -1,3 +1,5 @@ +<#escape x as jsonUtils.encodeJSONString(x)> { - "message":"deleted" -} \ No newline at end of file + "message":"${message}" +} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.js index 539682c3b8..f72ea79ad7 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links-delete.post.json.js @@ -39,9 +39,14 @@ function getRequestNodes() for (var i in items) { - var tmpNode = node.childByNamePath(items[i]); - if (tmpNode) - nodes.push(tmpNode); + if (i) + { + var tmpNode = node.childByNamePath(items[i]); + if (tmpNode) + { + nodes.push(tmpNode); + } + } } return nodes; @@ -58,17 +63,20 @@ function deleteLink(linkNode) var isDeleted = linkNode.remove(); if (! isDeleted) { - status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Unable to delete node: " + nodeRef); + var mes = "Unable to delete node: " + nodeRef; + status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, mes); + model.message = mes; return; } - //model.message = "Node " + nodeRef + " deleted"; + model.message = "Node " + nodeRef + " deleted"; var siteId = url.templateArgs.site; var containerId = url.templateArgs.container; - var data = { - title:linkData["title"], + var data = + { + title:linkData.title, page: "links" - } + }; activities.postActivity("org.alfresco.links.link-deleted", siteId, containerId, jsonUtils.toJSONString(data)); } @@ -82,8 +90,22 @@ function main() return; } - for (var i in nodes) - deleteLink(nodes[i]); + for (var i in nodes) + { + if (i) + { + if (!nodes[i].hasPermission("Delete")) + { + status.code = 403; + var mes = "Permission to delete is denied"; + status.message = mes; + model.message = mes; + return; + } + + deleteLink(nodes[i]); + } + } } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.get.js index 95842dfce4..8cd085af2b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.get.js @@ -3,29 +3,29 @@ +const DEFAULT_NUM_DAYS = 7; /** * Fetches all links added to the site */ -function getLinksList(node,filter,tag,numdays, index, count) +function getLinksList(node, filter, tag, numdays, index, count) { - //var fromDate = getTodayMinusXDays(numdays); - // query information - var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/linksmodel/1.0}link\"" + - " +PATH:\"" + node.qnamePath + "/*\""; + var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/linksmodel/1.0}link\" +PATH:\"" + node.qnamePath + "/*\""; - if (filter == "internal") + if (filter == "recent") { - //luceneQuery += " +@cm\\:internal:\"true\""; - luceneQuery += "+ASPECT:\"{http://www.alfresco.org/model/linksmodel/1.0}internal\" "; + var fromDate = getTodayMinusXDays(DEFAULT_NUM_DAYS); + var toDate = new Date(); + + luceneQuery += getCreationDateRangeQuery(fromDate, toDate); } - else if (filter == "www") + else if (filter == "user") { - luceneQuery += "-ASPECT:\"{http://www.alfresco.org/model/linksmodel/1.0}internal\" "; + luceneQuery += " +@cm\\:creator:" + person.properties.userName; } - if (tag != null) + if (tag !== null) { luceneQuery += " +PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(tag) + "/member\" "; } @@ -44,20 +44,19 @@ function main() { return; } - - var pNumber = parseInt(args.page); - var pSize = parseInt(args.pageSize); + + var pNumber = parseInt(args.page, 10); + var pSize = parseInt(args.pageSize, 10); var filter = args.filter; - var tag = (args["tag"] != undefined && args["tag"].length > 0) ? args["tag"] : null; - - if ((pNumber == undefined) || (pSize == undefined)) + var tag = (args.tag != undefined && args.tag.length > 0) ? args.tag : null; + + if ((pNumber === undefined) || (pSize === undefined)) { model.error = "Parameters missing!"; return; } + model.links = node; model.data = getLinksList(node,filter,tag,7,(pNumber - 1) * pSize,pSize); - - } main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.ftl index 43c7d2ac70..0fc43401ec 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.ftl @@ -1,57 +1,66 @@ -<#import "../generic-paged-results.lib.ftl" as gen/> +<#import "../generic-paged-results.lib.ftl" as gen> <#macro renderPerson person fieldName> -<#escape x as jsonUtils.encodeJSONString(x)> - "${fieldName}" : { - <#if person.assocs["cm:avatar"]??> - "avatarRef" : "${person.assocs["cm:avatar"][0].nodeRef?string}", - - "username" : "${person.properties["cm:userName"]}", - "firstName" : "${person.properties["cm:firstName"]}", - "lastName" : "${person.properties["cm:lastName"]}" + "${fieldName}": + { + <#if person.assocs["cm:avatar"]??> + "avatarRef": "${person.assocs["cm:avatar"][0].nodeRef?string}", + + "username": "${person.properties["cm:userName"]}", + "firstName": "${person.properties["cm:firstName"]}", + "lastName": "${person.properties["cm:lastName"]}" }, - <#-- This template renders a link. --> - <#macro linkJSON item> <#escape x as jsonUtils.encodeJSONString(x)> { - "url" : "${item.url!''}", - "commentsUrl" : "/node/${item.node.nodeRef?replace('://','/')}/comments", - "description" : "${item.description!''}", - "nodeRef" : "${item.node.nodeRef}", - "name" : "${item.name!''}", - "title" : "${item.title!''}", - "internal" : "${item.internal!'false'}", - "isUpdated" : "${item.isUpdated!'false'}", - <#if item.author??> - <@renderPerson person=item.author fieldName="author" /> + "url": "${item.url!''}", + "commentsUrl": "/node/${item.node.nodeRef?replace('://','/')}/comments", + "description": "${item.description!''}", + "nodeRef": "${item.node.nodeRef}", + "name": "${item.name!''}", + "title": "${item.title!''}", + "internal": ${(item.internal!false)?string}, + "createdOn": "${item.createdOn?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}", + <#if item.creator??> + <@renderPerson person=item.creator fieldName="author" /> <#else> - "author" : { "username" : "${item.node.properties.creator}" }, - - "permissions" : { - "edit" : ${item.node.hasPermission("Write")?string}, - "delete" : ${item.node.hasPermission("Delete")?string} + "author": + { + "username": "${item.node.properties.creator}" }, - "tags" : [<#list item.tags as x>"${x}"<#if x_has_next>, ] + + "permissions": + { + "edit": ${item.node.hasPermission("Write")?string}, + "delete": ${item.node.hasPermission("Delete")?string} + }, + "tags": [<#list item.tags as x>"${x}"<#if x_has_next>, ] } <#macro renderLinkList> { - <@gen.pagedResults data=data ; item> - <@linkJSON item=item /> - + "metadata": + { + "linkPermissions": + { + "create": "${links.hasPermission("CreateChildren")?string}" + } + }, + <@gen.pagedResults data=data ; item> + <@linkJSON item=item /> + } <#macro renderLink> { - "item" : <@linkJSON item=item /> + "item": <@linkJSON item=item /> } \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js index 1f72a8c76f..b3ab53aaeb 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.lib.js @@ -2,25 +2,22 @@ const LINK_INTERNAL_ASPECT = "lnk:internal"; const ASPECT_INTERNAL = "lnk:isInternal"; - function getLinksData(node) { - var itm = {}; - itm.node = node; - itm.name = node.name||""; - itm.title = node.properties["lnk:linkTitle"]||""; - itm.description = node.properties["lnk:description"]||""; - itm.url = node.properties["lnk:url"]||""; + var itm = {}; + itm.node = node; + itm.name = node.name || ""; + itm.title = node.properties["lnk:title"] || ""; + itm.description = node.properties["lnk:description"] || ""; + itm.url = node.properties["lnk:url"] || ""; + itm.createdOn = node.properties.created || ""; + itm.modifiedOn = node.properties.modified || ""; + itm.creator = people.getPerson(node.properties["cm:creator"]); - // get the tags JSONArray and copy it into a real javascript array object - itm.tags = node.tags; - itm.internal = (node.hasAspect("lnk:internal")?"true":"false"); - - itm.author = people.getPerson(node.properties["cm:creator"]); - // (re-)enable permission - node.setInheritsPermissions(true); - /*itm.isUpdated = node.properties.isUpdated || "false";*/ - return itm; + itm.tags = node.tags; + itm.internal = node.hasAspect("lnk:internal"); + + return itm; } /** @@ -34,17 +31,17 @@ function getLinkProperties() if (json.has("title")) { - data["lnk:linkTitle"] = json.get("title"); + data["lnk:title"] = json.get("title"); } if (json.has("url")) { - data["lnk:url"] = json.get("url"); + data["lnk:url"] = json.get("url"); } if (json.has("description")) { - data["lnk:description"] = json.get("description"); + data["lnk:description"] = json.get("description"); } return data; @@ -52,5 +49,5 @@ function getLinkProperties() function isLinkInternal() { - return (json.has("isinternal")?true:false); + return (json.has("internal") ? true : false); } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.ftl index b6e2058be4..91d4bf1787 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.ftl @@ -1,3 +1,7 @@ +<#escape x as jsonUtils.encodeJSONString(x)> { - "name" : "${item.name}" -} \ No newline at end of file + "message": "${message}"<#if item??>, + "name": "${item.name?string}" + +} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.js index 4e0ca9b8a8..963816ee67 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.post.json.js @@ -1,17 +1,16 @@ - function ensureTagScope(node) { - if (! node.isTagScope) + if (!node.isTagScope) { - node.isTagScope = true; + node.isTagScope = true; } // also check the parent (the site!) - if (! node.parent.isTagScope) + if (!node.parent.isTagScope) { node.parent.isTagScope = true; } @@ -27,22 +26,22 @@ function createLink(linkNode) { // get the tags JSONArray and copy it into a real javascript array object var tmp = json.get("tags"); - for (var x=0; x < tmp.length(); x++) + for (var x = 0; x < tmp.length(); x++) { - tags.push(tmp.get(x)); + tags.push(tmp.get(x)); } } // get a unique name var nodeName = getUniqueChildName(linkNode, "link"); + linkNode = linkNode.createNode(nodeName, "lnk:link",getLinkProperties()); - var linkNode = linkNode.createNode(nodeName, "lnk:link",getLinkProperties()); - - if (isLinkInternal()) { - var pr = []; - pr["lnk:isInternal"] = "true"; - linkNode.addAspect("lnk:internal", pr); - } + if (isLinkInternal()) + { + var pr = []; + pr["lnk:isInternal"] = "true"; + linkNode.addAspect("lnk:internal", pr); + } linkNode.tags = tags; linkNode.mimetype = "text/html"; @@ -51,13 +50,16 @@ function createLink(linkNode) var siteId = url.templateArgs.site; var containerId = url.templateArgs.container; - var data = { + var data = + { title: json.get("title"), - page: json.get("page") + "?container=links&linkId=" + nodeName - } + page: json.get("page") + "?linkId=" + nodeName + }; + var mes = linkNode.properties["name"]; + model.message = mes; activities.postActivity("org.alfresco.links.link-created", siteId, containerId, jsonUtils.toJSONString(data)); - + return linkNode; } @@ -69,11 +71,20 @@ function main() { return; } + + if (!node.hasPermission("CreateChildren")) + { + status.code = 403; + var mes = "Permission to create is denied"; + status.message = mes; + model.message = mes; + return; + } ensureTagScope(node); var link = createLink(node); - model.item = link; + model.item = link; } -main(); +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.ftl index 80c5ea4d0e..64c991a177 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.ftl @@ -1,3 +1,5 @@ +<#escape x as jsonUtils.encodeJSONString(x)> { - "message":"update" -} \ No newline at end of file + "message": "${message}" +} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.js index 1bad3e26b0..5388a70b50 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/links/links.put.json.js @@ -6,46 +6,50 @@ */ function updateLink(linkNode) { - var tags = []; - if (json.has("tags")) - { - // get the tags JSONArray and copy it into a real javascript array object - var tmp = json.get("tags"); - for (var x = 0; x < tmp.length(); x++) - { - tags.push(tmp.get(x)); - } - } + var tags = []; + if (json.has("tags")) + { + // get the tags JSONArray and copy it into a real javascript array object + var tmp = json.get("tags"); + for (var x = 0; x < tmp.length(); x++) + { + tags.push(tmp.get(x)); + } + } - var isInternal = isLinkInternal(); - if (!linkNode.hasAspect("lnk:internal") && isInternal) - { - var pr = []; - pr["lnk:isInternal"] = "true"; - linkNode.addAspect("lnk:internal", pr); + var isInternal = isLinkInternal(); + if (!linkNode.hasAspect("lnk:internal") && isInternal) + { + var pr = []; + pr["lnk:isInternal"] = "true"; + linkNode.addAspect("lnk:internal", pr); + } + else if (linkNode.hasAspect("lnk:internal") && !isInternal) + { + linkNode.removeAspect("lnk:internal"); + } - } else if (linkNode.hasAspect("lnk:internal") && !isInternal) - { - linkNode.removeAspect("lnk:internal"); - } + var prs = getLinkProperties(); + for (var propName in prs) + { + if (propName) + { + linkNode.properties[propName] = prs[propName]; + } + } - var prs = getLinkProperties(); - for (var propName in prs) - { - linkNode.properties[propName] = prs[propName]; - } - - linkNode.mimetype = "text/html"; - linkNode.content = linkNode.properties["lnk:url"]; - linkNode.tags = tags; - linkNode.save(); - - var siteId = url.templateArgs.site; - var containerId = url.templateArgs.container; - var data = { + linkNode.mimetype = "text/html"; + linkNode.content = linkNode.properties["lnk:url"]; + linkNode.tags = tags; + linkNode.save(); + model.message = "Node " + linkNode.nodeRef + " updated"; + var siteId = url.templateArgs.site; + var containerId = url.templateArgs.container; + var data = + { title: json.get("title"), - page: json.get("page") + "?container=links&linkId=" + linkNode.name - } + page: json.get("page") + "?linkId=" + linkNode.name + }; activities.postActivity("org.alfresco.links.link-updated", siteId, containerId, jsonUtils.toJSONString(data)); @@ -56,9 +60,15 @@ function main() { // get requested node var node = getRequestNode(); - - var link = updateLink(node); - + if (!node.hasPermission("WriteProperties") || !node.hasPermission("WriteContent")) + { + status.code = 403; + var mes = "Permission to update is denied"; + status.message = mes; + model.message = mes; + return; + } + updateLink(node); } main(); \ No newline at end of file