diff options
author | Garren Smith <garren.smith@gmail.com> | 2018-09-06 12:13:25 +0200 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-10-03 15:41:41 +0100 |
commit | 9c136d97db71de013d41ae083d0861e3668caa8f (patch) | |
tree | b31708cfe7f4882bf3c5b30356c31e686ccc4cd3 | |
parent | 947b62bb6fd0ec4db732f8bd2f20878809c0e5a7 (diff) | |
download | couchdb-9c136d97db71de013d41ae083d0861e3668caa8f.tar.gz |
move view validation to chttp_view for partition checks
-rw-r--r-- | src/chttpd/src/chttpd_view.erl | 20 | ||||
-rw-r--r-- | src/couch_mrview/src/couch_mrview_util.erl | 14 |
2 files changed, 20 insertions, 14 deletions
diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl index 3743e6da9..e56be0c7b 100644 --- a/src/chttpd/src/chttpd_view.erl +++ b/src/chttpd/src/chttpd_view.erl @@ -121,6 +121,7 @@ handle_partition_view_req(#httpd{method='POST', Args0 = couch_mrview_http:parse_params(Req, Keys), Args1 = couch_mrview_util:set_extra(Args0, partition, Partition), Args2 = couch_mrview_util:set_extra(Args1, partitioned, true), + ok = check_partition_restrictions(Args2), design_doc_view_int(Req, Db, DDoc, ViewName, Args2); _ -> throw({ @@ -135,12 +136,31 @@ handle_partition_view_req(#httpd{method='GET', Args = couch_mrview_http:parse_params(Req, Keys), Args1 = couch_mrview_util:set_extra(Args, partition, Partition), Args2 = couch_mrview_util:set_extra(Args1, partitioned, true), + ok = check_partition_restrictions(Args2), design_doc_view_int(Req, Db, DDoc, ViewName, Args2); handle_partition_view_req(Req, _Db, _DDoc, _Pk) -> chttpd:send_method_not_allowed(Req, "GET"). +check_partition_restrictions(#mrargs{} = Args) -> + Restrictions = [ + {<<"include_docs">>, Args#mrargs.include_docs, true}, + {<<"stable">>, Args#mrargs.stable, true}, + {<<"conflicts">>, Args#mrargs.conflicts, true} + ], + lists:foreach(fun ({Param, Field, Value}) -> + case Field =:= Value of + true -> + Msg = [<<"`">>, Param, <<"=true` is not supported in this view.">>], + throw({bad_request, ?l2b(Msg)}); + false -> + ok + end + end, Restrictions), + ok. + + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl index 9e16ea621..fcdadda5f 100644 --- a/src/couch_mrview/src/couch_mrview_util.erl +++ b/src/couch_mrview/src/couch_mrview_util.erl @@ -642,20 +642,6 @@ validate_args(Args) -> mrverror(<<"`partition` parameter is not supported in this view.">>) end, - case {Partitioned, Args#mrargs.conflicts} of - {true, true} -> - mrverror(<<"`conflicts=true` is not supported in this view.">>); - {_, _} -> - ok - end, - - case {Partitioned, Args#mrargs.stable} of - {true, true} -> - mrverror(<<"`stable=true` is not supported in this view.">>); - {_, _} -> - ok - end, - Args1 = case {Style, Partitioned, Partition} of {all_docs, true, undefined} -> Args; |