rnewson commented on a change in pull request #1482: add partition endpoint for 
views along with validation on which
URL: https://github.com/apache/couchdb/pull/1482#discussion_r206905449
 
 

 ##########
 File path: src/chttpd/src/chttpd_db.erl
 ##########
 @@ -250,20 +251,83 @@ handle_view_cleanup_req(Req, Db) ->
     ok = fabric:cleanup_index_files_all_nodes(Db),
     send_json(Req, 202, {[{ok, true}]}).
 
+
+handle_partition_design_req(#httpd{
+        path_parts=[DbName, <<"_partition">>, PartitionKey, _Design, Name, 
<<"_",_/binary>> = Action | _Rest]
+    }=Req, Db) -> 
+    validate_partition_key(PartitionKey),
+
+    case chttpd:qs_value(Req, "partition") of
+        undefined ->
+            ok;
+        _ ->
+            throw({
+                bad_request,
+                <<"Partition key is not allowed in the query string">>
+            })
+     end,
+
+    case mem3:is_partitioned(DbName) of
+        false -> throw(<<"Database is not partitioned">>);
+        true -> ok
+    end,
+
+    DDoc = get_design_doc(DbName, Name),
+    case check_ddoc_can_use_partitionkey(DDoc) of
+        true ->
+            Handler = chttpd_handlers:partition_design_handler(Action, fun 
bad_action_partition_req/4),
+            Handler(Req, Db, DDoc, PartitionKey);
+        false ->
+            throw({bad_request, <<"Design doc cannot be used on a partitioned 
query">>})
+    end;
+handle_partition_design_req(_Req, _Db) ->
+    throw({bad_request, <<"missing partition key">>}).
+
+
+validate_partition_key(<<"_", _/binary>>) ->
+    throw({bad_request, <<"partition keys must not begin with an 
underscore">>});
+validate_partition_key(<<" ">>) ->
+    throw({bad_request, <<"partition keys cannot begin with a space">>});
+validate_partition_key(_) ->
+    ok.
+
+
+check_ddoc_can_use_partitionkey(#doc{body={DDocBody}}) ->
 
 Review comment:
   this needs to be deeper down as we will have the same question in other 
places. As a placeholder, fine.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to