diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js
index 140bcc9341..1a11bf9cb0 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/lib/wiki.lib.js
@@ -24,12 +24,15 @@ function getTemplateArgs(params)
/* Format and return error object */
function jsonError(errorString)
{
+/*
var obj =
{
"error": errorString
};
return obj;
+*/
+ status.setCode(status.STATUS_BAD_REQUEST, errorString);
}
// NOTE: may need a custom content type for a wiki entry
diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.json.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.json.js
index 9dbdef2ef3..b4aee0bc6a 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.json.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/wiki/page.put.json.js
@@ -9,24 +9,25 @@
function getTemplateParams()
{
- // Grab the URI parameters
- var siteId = "" + url.templateArgs.siteId;
- var pageTitle = "" + url.templateArgs.pageTitle;
+ // Grab the URI parameters
+ var siteId = "" + url.templateArgs.siteId;
+ var pageTitle = "" + url.templateArgs.pageTitle;
- if (siteId === null || siteId.length === 0)
- {
- return null;
- }
+ if (siteId === null || siteId.length === 0)
+ {
+ return null;
+ }
- if (pageTitle === null || pageTitle.length === 0)
- {
- return null;
- }
+ if (pageTitle === null || pageTitle.length === 0)
+ {
+ return null;
+ }
- return {
- "siteId": siteId,
- "pageTitle": pageTitle
- };
+ return (
+ {
+ "siteId": siteId,
+ "pageTitle": pageTitle
+ });
}
function update()
@@ -34,14 +35,14 @@ function update()
var params = getTemplateArgs(["siteId", "pageTitle"]);
if (params === null)
{
- return jsonError("No parameters supplied");
+ return jsonError("No parameters supplied");
}
// Get the site
var site = siteService.getSite(params.siteId);
if (site === null)
{
- return jsonError("Could not find site: " + siteId);
+ return jsonError("Could not find site: " + siteId);
}
var wiki = getWikiContainer(site);
@@ -49,38 +50,47 @@ function update()
{
return jsonError("Could not locate wiki container");
}
-
- var page = wiki.childByNamePath(params.pageTitle), activityType;
- // Create the page if it doesn't exist
- if (page === null)
+
+ var page = wiki.childByNamePath(params.pageTitle), activityType;
+ // Create the page if it doesn't exist
+ if (page === null)
{
- page = createWikiPage(params.pageTitle, wiki,
- {
- content: json.get("pagecontent"),
- versionable: true
- });
-
+ page = createWikiPage(params.pageTitle, wiki,
+ {
+ content: json.get("pagecontent"),
+ versionable: true
+ });
+
activityType = "org.alfresco.wiki.page-created";
}
else
{
- // Create a new revision of the page
- var workingCopy = page.checkout();
- workingCopy.content = json.get("pagecontent");
- workingCopy.checkin();
-
- activityType = "org.alfresco.wiki.page-edited";
+ // Check the version of the page being submitted against the version now in the repo, or a forced save
+ if (pageVersionMatchesSubmitted(page) || json.has("forceSave"))
+ {
+ // Create a new revision of the page
+ var workingCopy = page.checkout();
+ workingCopy.content = json.get("pagecontent");
+ workingCopy.checkin();
+
+ activityType = "org.alfresco.wiki.page-edited";
+ }
+ else
+ {
+ status.setCode(status.STATUS_CONFLICT, "Repository version is newer.");
+ return;
+ }
}
-
- var data =
- {
+
+ var data =
+ {
title: params.pageTitle.replace(/_/g, " "),
page: json.get("page") + "?title=" + params.pageTitle
}
- // Log activity
- activities.postActivity(activityType, params.siteId, "wiki", jsonUtils.toJSONString(data));
-
- if (!json.isNull("tags"))
+ // Log activity
+ activities.postActivity(activityType, params.siteId, "wiki", jsonUtils.toJSONString(data));
+
+ if (!json.isNull("tags"))
{
var tags = Array(json.get("tags"));
if (tags)
@@ -90,7 +100,7 @@ function update()
// string and call the (native) method split
var tags = [];
var tmp = json.get("tags");
- for (var x=0; x < tmp.length(); x++)
+ for (var x = 0, xx = tmp.length(); x < xx; x++)
{
tags.push(tmp.get(x));
}
@@ -102,14 +112,64 @@ function update()
}
page.save();
}
-
- // NOTE: for now we return the raw page content and do the transformation
- // of any wiki markup on the client. This is because the edit view needs to display
- // the raw content (for editing) whereas the page view needs to display the rendered content.
- return {
- page: page,
- tags: page.tags
- }
+
+ // NOTE: for now we return the raw page content and do the transformation
+ // of any wiki markup on the client. This is because the edit view needs to display
+ // the raw content (for editing) whereas the page view needs to display the rendered content.
+ return (
+ {
+ page: page,
+ tags: page.tags
+ });
+}
+
+/**
+ * Checks whether the current repository version is newer than a submitted version number.
+ * Returns:
+ * false if currentVersion is older than repoVersion
+ * true otherwise
+ */
+function pageVersionMatchesSubmitted(page)
+{
+ var currentVersion = 0, repoVersion = 0;
+
+ if (json.has("currentVersion"))
+ {
+ currentVersion = json.get("currentVersion");
+ }
+
+ if (page.hasAspect("cm:versionable"))
+ {
+ repoVersion = getLatestVersion(page.versionHistory);
+ }
+
+ return (sortByLabel(
+ { label: repoVersion},
+ { label: currentVersion }
+ ) != -1);
+}
+
+function sortByLabel(version1, version2)
+{
+ var major1 = new Number(version1.label.substring(0, version1.label.indexOf(".")));
+ var major2 = new Number(version2.label.substring(0, version2.label.indexOf(".")));
+ if (major1 - 0 == major2 - 0)
+ {
+ var minor1 = new Number(version1.label.substring(version1.label.indexOf(".")+1));
+ var minor2 = new Number(version2.label.substring(version2.label.indexOf(".")+1));
+ return (minor1 < minor2) ? 1 : (minor1 > minor2) ? -1 : 0;
+ }
+ else
+ {
+ return (major1 < major2) ? 1 : -1;
+ }
+}
+
+
+function getLatestVersion(versionHistory)
+{
+ versionHistory.sort(sortByLabel);
+ return versionHistory[0].label;
}
model.result = update();
\ No newline at end of file
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index 7af2da8c5c..b21140a780 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -351,6 +351,7 @@
parent="webscript">
+
diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java
index f3ebd9f5aa..0f13b4318b 100644
--- a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java
+++ b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java
@@ -43,6 +43,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.AuthenticationService;
+import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowException;
@@ -100,6 +101,7 @@ public class Invite extends DeclarativeWebScript
private WorkflowService workflowService;
private PersonService personService;
private AuthenticationService authenticationService;
+ private PermissionService permissionService;
private MutableAuthenticationDao mutableAuthenticationDao;
private SiteService siteService;
private NodeService nodeService;
@@ -214,6 +216,16 @@ public class Invite extends DeclarativeWebScript
this.namespaceService = namespaceService;
}
+ /**
+ * Set the permission service
+ *
+ * @param permissionService the permission service
+ */
+ public void setPermissionService(PermissionService permissionService)
+ {
+ this.permissionService = permissionService;
+ }
+
/*
* (non-Javadoc)
*
@@ -419,11 +431,13 @@ public class Invite extends DeclarativeWebScript
properties.put(ContentModel.PROP_LASTNAME, inviteeLastName);
properties.put(ContentModel.PROP_EMAIL, inviteeEmail);
+ final String finalUserName = inviteeUserName;
AuthenticationUtil.runAs(new RunAsWork