You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/07/18 19:13:10 UTC

[1/3] couch commit: updated refs/heads/master to ac3dae3

Repository: couchdb-couch
Updated Branches:
  refs/heads/master 4476595e0 -> ac3dae37d


Use couch_epi:decide for validate_dbname

COUCHDB-3066


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/11c25659
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/11c25659
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/11c25659

Branch: refs/heads/master
Commit: 11c25659c5057e45f0fbff44e4baf64ec7f92fe4
Parents: 4476595
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Jul 18 11:49:51 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Mon Jul 18 12:10:01 2016 -0700

----------------------------------------------------------------------
 src/couch_db.erl               |  8 ++------
 src/couch_db_plugin.erl        | 19 ++++++++++++++-----
 test/couch_db_plugin_tests.erl | 21 +++++++++++++++------
 3 files changed, 31 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/11c25659/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 8260a5c..3eff99f 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1536,12 +1536,8 @@ validate_dbname(DbName) when is_list(DbName) ->
     validate_dbname(?l2b(DbName));
 validate_dbname(DbName) when is_binary(DbName) ->
     Normalized = normalize_dbname(DbName),
-    case couch_db_plugin:validate_dbname(DbName, Normalized) of
-        true ->
-            ok;
-        false ->
-            validate_dbname_int(DbName, Normalized)
-    end.
+    couch_db_plugin:validate_dbname(
+        DbName, Normalized, fun validate_dbname_int/2).
 
 validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
     case re:run(DbName, ?DBNAME_REGEX, [{capture,none}, dollar_endonly]) of

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/11c25659/src/couch_db_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_plugin.erl b/src/couch_db_plugin.erl
index 1a6d2ea..774e9e0 100644
--- a/src/couch_db_plugin.erl
+++ b/src/couch_db_plugin.erl
@@ -13,7 +13,7 @@
 -module(couch_db_plugin).
 
 -export([
-    validate_dbname/2,
+    validate_dbname/3,
     before_doc_update/2,
     after_doc_read/2,
     validate_docid/1,
@@ -29,10 +29,8 @@
 %% API Function Definitions
 %% ------------------------------------------------------------------
 
-validate_dbname(DbName, Normalized) ->
-    Handle = couch_epi:get_handle(?SERVICE_ID),
-    %% callbacks return true only if it specifically allow the given Id
-    couch_epi:any(Handle, ?SERVICE_ID, validate_dbname, [DbName, Normalized], []).
+validate_dbname(DbName, Normalized, Default) ->
+    maybe_handle(validate_dbname, [DbName, Normalized], Default).
 
 before_doc_update(#db{before_doc_update = Fun} = Db, Doc0) ->
     case with_pipe(before_doc_update, [Doc0, Db]) of
@@ -70,3 +68,14 @@ with_pipe(Func, Args) ->
 do_apply(Func, Args, Opts) ->
     Handle = couch_epi:get_handle(?SERVICE_ID),
     couch_epi:apply(Handle, ?SERVICE_ID, Func, Args, Opts).
+
+maybe_handle(Func, Args, Default) ->
+    Handle = couch_epi:get_handle(?SERVICE_ID),
+    case couch_epi:decide(Handle, ?SERVICE_ID, Func, Args, []) of
+       no_decision when is_function(Default) ->
+           apply(Default, Args);
+       no_decision ->
+           Default;
+       {decided, Result} ->
+           Result
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/11c25659/test/couch_db_plugin_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index 337207e..bbc01c7 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -52,9 +52,10 @@ setup() ->
 teardown(Ctx) ->
     couch_tests:teardown(Ctx).
 
-validate_dbname({true, _Db}, _) -> true;
-validate_dbname({false, _Db}, _) -> false;
-validate_dbname({fail, _Db}, _) -> throw(validate_dbname).
+validate_dbname({true, _Db}, _) -> {decided, true};
+validate_dbname({false, _Db}, _) -> {decided, false};
+validate_dbname({fail, _Db}, _) -> throw(validate_dbname);
+validate_dbname({pass, _Db}, _) -> no_decision.
 
 before_doc_update({fail, _Doc}, _Db) -> throw(before_doc_update);
 before_doc_update({true, Doc}, Db) -> [{true, [before_doc_update|Doc]}, Db];
@@ -85,6 +86,7 @@ callback_test_() ->
                 fun validate_dbname_match/0,
                 fun validate_dbname_no_match/0,
                 fun validate_dbname_throw/0,
+                fun validate_dbname_pass/0,
 
                 fun before_doc_update_match/0,
                 fun before_doc_update_no_match/0,
@@ -111,15 +113,22 @@ callback_test_() ->
 
 
 validate_dbname_match() ->
-    ?assert(couch_db_plugin:validate_dbname({true, [db]}, db)).
+    ?assert(couch_db_plugin:validate_dbname(
+        {true, [db]}, db, fun(_, _) -> pass end)).
 
 validate_dbname_no_match() ->
-    ?assertNot(couch_db_plugin:validate_dbname({false, [db]}, db)).
+    ?assertNot(couch_db_plugin:validate_dbname(
+        {false, [db]}, db, fun(_, _) -> pass end)).
 
 validate_dbname_throw() ->
     ?assertThrow(
         validate_dbname,
-        couch_db_plugin:validate_dbname({fail, [db]}, db)).
+        couch_db_plugin:validate_dbname(
+            {fail, [db]}, db, fun(_, _) -> pass end)).
+
+validate_dbname_pass() ->
+    ?assertEqual(pass, couch_db_plugin:validate_dbname(
+        {pass, [db]}, db, fun(_, _) -> pass end)).
 
 before_doc_update_match() ->
     ?assertMatch(


[2/3] couch commit: updated refs/heads/master to ac3dae3

Posted by ii...@apache.org.
Name test cases

COUCHDB-3066


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/7d2e1a73
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/7d2e1a73
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/7d2e1a73

Branch: refs/heads/master
Commit: 7d2e1a734e31aa220fcb43b1c6472da1098f9be2
Parents: 11c2565
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Jul 18 11:52:01 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Mon Jul 18 12:10:39 2016 -0700

----------------------------------------------------------------------
 test/couch_db_plugin_tests.erl | 48 ++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7d2e1a73/test/couch_db_plugin_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index bbc01c7..ea9b230 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -83,30 +83,30 @@ callback_test_() ->
         {
             setup, fun setup/0, fun teardown/1,
             [
-                fun validate_dbname_match/0,
-                fun validate_dbname_no_match/0,
-                fun validate_dbname_throw/0,
-                fun validate_dbname_pass/0,
-
-                fun before_doc_update_match/0,
-                fun before_doc_update_no_match/0,
-                fun before_doc_update_throw/0,
-
-                fun after_doc_read_match/0,
-                fun after_doc_read_no_match/0,
-                fun after_doc_read_throw/0,
-
-                fun validate_docid_match/0,
-                fun validate_docid_no_match/0,
-                fun validate_docid_throw/0,
-
-                fun check_is_admin_match/0,
-                fun check_is_admin_no_match/0,
-                fun check_is_admin_throw/0,
-
-                fun on_delete_match/0,
-                fun on_delete_no_match/0,
-                fun on_delete_throw/0
+                {"validate_dbname_match", fun validate_dbname_match/0},
+                {"validate_dbname_no_match", fun validate_dbname_no_match/0},
+                {"validate_dbname_throw", fun validate_dbname_throw/0},
+                {"validate_dbname_pass", fun validate_dbname_pass/0},
+
+                {"before_doc_update_match", fun before_doc_update_match/0},
+                {"before_doc_update_no_match", fun before_doc_update_no_match/0},
+                {"before_doc_update_throw", fun before_doc_update_throw/0},
+
+                {"after_doc_read_match", fun after_doc_read_match/0},
+                {"after_doc_read_no_match", fun after_doc_read_no_match/0},
+                {"after_doc_read_throw", fun after_doc_read_throw/0},
+
+                {"validate_docid_match", fun validate_docid_match/0},
+                {"validate_docid_no_match", fun validate_docid_no_match/0},
+                {"validate_docid_throw", fun validate_docid_throw/0},
+
+                {"check_is_admin_match", fun check_is_admin_match/0},
+                {"check_is_admin_no_match", fun check_is_admin_no_match/0},
+                {"check_is_admin_throw", fun check_is_admin_throw/0},
+
+                {"on_delete_match", fun on_delete_match/0},
+                {"on_delete_no_match", fun on_delete_no_match/0},
+                {"on_delete_throw", fun on_delete_throw/0}
             ]
         }
     }.


[3/3] couch commit: updated refs/heads/master to ac3dae3

Posted by ii...@apache.org.
Merge remote branch 'cloudant:70457-use-couch_epi-decide'

This closes #187

Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/ac3dae37
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/ac3dae37
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/ac3dae37

Branch: refs/heads/master
Commit: ac3dae37da1e44dfba6fbed8ec11fa1c6779ee33
Parents: 4476595 7d2e1a7
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Jul 18 12:12:44 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Mon Jul 18 12:12:44 2016 -0700

----------------------------------------------------------------------
 src/couch_db.erl               |  8 ++---
 src/couch_db_plugin.erl        | 19 ++++++++---
 test/couch_db_plugin_tests.erl | 67 +++++++++++++++++++++----------------
 3 files changed, 54 insertions(+), 40 deletions(-)
----------------------------------------------------------------------