Skip to content

Commit

Permalink
Doc validation functions from deleted ddocs must be ignored
Browse files Browse the repository at this point in the history
If a design document is deleted by updating it with a "_deleted"
field set to the boolean value true, its validate_doc_update function
should be ignored for subsequent document insertions/updates.

This closes COUCHDB-1227.




git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1157428 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
fdmanana committed Aug 13, 2011
1 parent 6a0f615 commit 938ab9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
39 changes: 39 additions & 0 deletions share/www/script/test/design_docs.js
Expand Up @@ -421,6 +421,45 @@ couchTests.design_docs = function(debug) {

run_on_modified_server(server_config, testFun);

// COUCHDB-1227 - if a design document is deleted, by adding a "_deleted"
// field with the boolean value true, its validate_doc_update functions
// should no longer have effect.
db.deleteDb();
db.createDb();
var ddoc = {
_id: "_design/test",
language: "javascript",
validate_doc_update: (function(newDoc, oldDoc, userCtx, secObj) {
if (newDoc.value % 2 == 0) {
throw({forbidden: "dont like even numbers"});
}
return true;
}).toString()
};

TEquals(true, db.save(ddoc).ok);
try {
db.save({_id: "doc1", value: 4});
T(false, "doc insertion should have failed");
} catch (x) {
TEquals("forbidden", x.error);
}

var doc = db.open("doc1");
TEquals(null, doc);
ddoc._deleted = true;
TEquals(true, db.save(ddoc).ok);

try {
TEquals(true, db.save({_id: "doc1", value: 4}).ok);
} catch (x) {
T(false, "doc insertion should have succeeded");
}

doc = db.open("doc1");
TEquals(true, doc !== null, "doc was not persisted");
TEquals(4, doc.value);

// cleanup
db.deleteDb();
db2.deleteDb();
Expand Down
4 changes: 3 additions & 1 deletion src/couchdb/couch_db.erl
Expand Up @@ -297,7 +297,9 @@ sum_tree_sizes(Acc, [T | Rest]) ->
get_design_docs(Db) ->
{ok, _, Docs} = couch_view:fold(
#view{btree=by_id_btree(Db)},
fun(#full_doc_info{id= <<"_design/",_/binary>>}=FullDocInfo, _Reds, AccDocs) ->
fun(#full_doc_info{deleted = true}, _Reds, AccDocs) ->
{ok, AccDocs};
(#full_doc_info{id= <<"_design/",_/binary>>}=FullDocInfo, _Reds, AccDocs) ->
{ok, Doc} = open_doc_int(Db, FullDocInfo, [ejson_body]),
{ok, [Doc | AccDocs]};
(_, _Reds, AccDocs) ->
Expand Down

0 comments on commit 938ab9d

Please sign in to comment.