This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-6
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8de56b5910f71c6e0ff6a2acc6f182b98642853e
Author: Garren Smith <[email protected]>
AuthorDate: Wed Sep 5 11:55:13 2018 +0200

    validate partitioned design docs
---
 src/couch_mrview/src/couch_mrview.erl | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview.erl 
b/src/couch_mrview/src/couch_mrview.erl
index 1b1a06b..32e4b39 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -175,16 +175,44 @@ join([H|T], Sep, Acc) ->
     join(T, Sep, [Sep, H | Acc]).
 
 
+validate_partitioned_ddoc(#doc{} = DDoc) ->
+    {DDocProps} = DDoc#doc.body,
+    Banned = [
+        <<"shows">>,
+        <<"rewrites">>,
+        <<"lists">>,
+        <<"updates">>,
+        <<"filters">>,
+        <<"validate_doc_update">>
+        ],
+    validate_partitioned_ddoc(DDocProps, Banned).
+
+
+validate_partitioned_ddoc([], _Banned) ->
+    ok;
+validate_partitioned_ddoc([{Key, _Value} | Rest], Banned) ->
+    case lists:member(Key, Banned) of
+        true ->
+            Msg = [<<"`">>, Key, <<"` cannot be used in a partitioned design 
doc">>],
+            throw({invalid_design_doc, ?l2b(Msg)});
+        false ->
+            validate_partitioned_ddoc(Rest, Banned)
+    end.
+
+
 validate(DbName,  DDoc) ->
     ok = validate_ddoc_fields(DDoc#doc.body),
     DbPartitioned = mem3:is_partitioned(DbName),
     DDocPartitioned = get_partitioned_opt(DDoc#doc.body, DbPartitioned),
-    if
-        not DbPartitioned andalso DDocPartitioned ->
+
+    case {DbPartitioned, DDocPartitioned} of
+        {true, true} ->
+            validate_partitioned_ddoc(DDoc);
+        {false, true} ->
             throw({invalid_design_doc,
                 <<"partitioned option cannot be true in a "
                   "non-partitioned database.">>});
-        true ->
+        {_, _} -> 
             ok
     end,
     GetName = fun

Reply via email to