You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2011/08/14 00:10:00 UTC

svn commit: r1157429 - in /couchdb/branches/1.1.x: share/www/script/test/design_docs.js src/couchdb/couch_db.erl

Author: fdmanana
Date: Sat Aug 13 22:10:00 2011
New Revision: 1157429

URL: http://svn.apache.org/viewvc?rev=1157429&view=rev
Log:
Merge revision 1157428 from trunk

    Doc validation functions from deleted ddocs must be ignored

    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.


Modified:
    couchdb/branches/1.1.x/share/www/script/test/design_docs.js
    couchdb/branches/1.1.x/src/couchdb/couch_db.erl

Modified: couchdb/branches/1.1.x/share/www/script/test/design_docs.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/design_docs.js?rev=1157429&r1=1157428&r2=1157429&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/design_docs.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/design_docs.js Sat Aug 13 22:10:00 2011
@@ -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();

Modified: couchdb/branches/1.1.x/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_db.erl?rev=1157429&r1=1157428&r2=1157429&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_db.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_db.erl Sat Aug 13 22:10:00 2011
@@ -273,7 +273,9 @@ get_db_info(Db) ->
 get_design_docs(#db{fulldocinfo_by_id_btree=Btree}=Db) ->
     {ok, _, Docs} = couch_view:fold(
         #view{btree=Btree},
-        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} = couch_db:open_doc_int(Db, FullDocInfo, []),
             {ok, [Doc | AccDocs]};
         (_, _Reds, AccDocs) ->