Commit f691326f authored by Tristan Cavelier's avatar Tristan Cavelier

fix bug in post and put from revisionstorage.js

put {"_id":"test"} when "test" already exists -> conflicts
revisions can pass the checkRevisionFormat function now
parent 32ee4fb8
...@@ -300,13 +300,13 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -300,13 +300,13 @@ jIO.addStorageType('revision', function (spec, my) {
doc = command.cloneDoc(); doc = command.cloneDoc();
docid = command.getDocId(); docid = command.getDocId();
if (typeof doc._rev === "string" && if (typeof doc._rev === "string" &&
priv.checkRevisionFormat(doc._rev)) { !priv.checkRevisionFormat(doc._rev)) {
that.error({ that.error({
"status": 31, "status": 31,
"statusText": "Wrong Revision Format", "statusText": "Wrong Revision Format",
"error": "wrong_revision_format", "error": "wrong_revision_format",
"message": "The document previous revision does not match "+ "message": "The document previous revision does not match "+
"[0-9]+-[0-9a-zA-Z]+", "^[0-9]+-[0-9a-zA-Z]+$",
"reason": "Previous revision is wrong" "reason": "Previous revision is wrong"
}); });
return; return;
...@@ -315,6 +315,9 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -315,6 +315,9 @@ jIO.addStorageType('revision', function (spec, my) {
doc._id = priv.generateUuid(); doc._id = priv.generateUuid();
docid = doc._id; docid = doc._id;
} }
if (priv.update_doctree_allowed === undefined) {
priv.update_doctree_allowed = true;
}
f.getDocumentTree = function () { f.getDocumentTree = function () {
var option = command.cloneOption(); var option = command.cloneOption();
if (option["max_retry"] === 0) { if (option["max_retry"] === 0) {
...@@ -327,7 +330,17 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -327,7 +330,17 @@ jIO.addStorageType('revision', function (spec, my) {
option, option,
function (response) { function (response) {
doctree = response; doctree = response;
if (priv.update_doctree_allowed) {
f.postDocument("put"); f.postDocument("put");
} else {
that.error({
"status": 409,
"statusText": "Conflict",
"error": "conflict",
"message": "Cannot update a document",
"reason": "Document update conflict"
});
}
}, function (err) { }, function (err) {
switch(err.status) { switch(err.status) {
case 404: case 404:
...@@ -398,6 +411,9 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -398,6 +411,9 @@ jIO.addStorageType('revision', function (spec, my) {
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.put = function (command) { that.put = function (command) {
if (command.cloneDoc()._rev === undefined) {
priv.update_doctree_allowed = false;
}
that.post(command); that.post(command);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment