couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [48/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74
Date Fri, 01 Aug 2014 09:06:24 GMT
Add cassim


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

Branch: refs/heads/windsor-merge
Commit: 2a2705967db91b43a476e7e3850fad5220ab269b
Parents: 58c203d
Author: Robert Newson <rnewson@apache.org>
Authored: Wed Jul 30 12:07:19 2014 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd.app.src          |  3 ++-
 src/chttpd_auth_request.erl |  2 +-
 src/chttpd_db.erl           | 56 ++++++++++++++++++++++++++++++++--------
 3 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd.app.src
----------------------------------------------------------------------
diff --git a/src/chttpd.app.src b/src/chttpd.app.src
index f24716d..5e63d66 100644
--- a/src/chttpd.app.src
+++ b/src/chttpd.app.src
@@ -39,7 +39,8 @@
         config,
         couch,
         ets_lru,
-        fabric
+        fabric,
+        cassim
     ]},
     {mod, {chttpd_app,[]}}
 ]}.

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd_auth_request.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_auth_request.erl b/src/chttpd_auth_request.erl
index 0c311a0..c9cc3a9 100644
--- a/src/chttpd_auth_request.erl
+++ b/src/chttpd_auth_request.erl
@@ -74,7 +74,7 @@ server_authorization_check(#httpd{path_parts=[<<"_", _/binary>>|_]}=Req)
->
     require_admin(Req).
 
 db_authorization_check(#httpd{path_parts=[DbName|_],user_ctx=Ctx}=Req) ->
-    {_} = fabric:get_security(DbName, [{user_ctx, Ctx}]),
+    {_} = cassim:get_security(DbName, [{user_ctx, Ctx}]),
     Req.
 
 require_admin(Req) ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 4741502..86e32dd 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -244,7 +244,7 @@ delete_db_req(#httpd{}=Req, DbName) ->
     end.
 
 do_db_req(#httpd{path_parts=[DbName|_], user_ctx=Ctx}=Req, Fun) ->
-    fabric:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
+    cassim:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
     Fun(Req, #db{name=DbName, user_ctx=Ctx}).
 
 db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) ->
@@ -462,22 +462,25 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_revs_diff">>]}=Req,
Db) ->
 db_req(#httpd{path_parts=[_,<<"_revs_diff">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "POST");
 
-db_req(#httpd{method='PUT',path_parts=[_,<<"_security">>],user_ctx=Ctx}=Req,
-        Db) ->
-    SecObj = chttpd:json_body(Req),
-    case fabric:set_security(Db, SecObj, [{user_ctx, Ctx}]) of
-        ok ->
-            send_json(Req, {[{<<"ok">>, true}]});
-        Else ->
-            throw(Else)
-    end;
+%% DEPRECATED: this endpoint functionality will be replaced by _security_mvcc
+db_req(#httpd{method='PUT',path_parts=[_,<<"_security">>]}=Req, Db) ->
+    put_security(Req, Db, true);
 
 db_req(#httpd{method='GET',path_parts=[_,<<"_security">>],user_ctx=Ctx}=Req,
Db) ->
-    send_json(Req, fabric:get_security(Db, [{user_ctx,Ctx}]));
+    send_json(Req, cassim:get_security(Db, [{user_ctx,Ctx}]));
 
 db_req(#httpd{path_parts=[_,<<"_security">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "PUT,GET");
 
+db_req(#httpd{method='PUT',path_parts=[_,<<"_security_mvcc">>]}=Req, Db) ->
+    put_security(Req, Db, false);
+
+db_req(#httpd{method='GET',path_parts=[_,<<"_security_mvcc">>],user_ctx=Ctx}=Req,
Db) ->
+    send_json(Req, cassim:get_security(Db, [{user_ctx,Ctx}]));
+
+db_req(#httpd{path_parts=[_,<<"_security_mvcc">>]}=Req, _Db) ->
+    send_method_not_allowed(Req, "PUT,GET");
+
 db_req(#httpd{method='PUT',path_parts=[_,<<"_revs_limit">>],user_ctx=Ctx}=Req,
         Db) ->
     Limit = chttpd:json_body(Req),
@@ -1392,6 +1395,37 @@ monitor_attachments(Att) ->
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
 
+put_security(#httpd{user_ctx=Ctx}=Req, Db, FetchRev) ->
+    DbName = Db#db.name,
+    DocId = cassim_metadata_cache:security_meta_id(DbName),
+    {SecObj0} = chttpd:json_body(Req),
+    {OldSecDoc} = cassim:get_security(DbName),
+    OldRev = couch_util:get_value(<<"_rev">>, OldSecDoc, undefined),
+    %% Maybe update the security doc with the rev when hiding mvcc logic
+    SecObj = case {FetchRev, OldRev} of
+        %% User supplied rev, just use the req body
+        {false, _} ->
+            SecObj0;
+        %% User did not supply rev, but new security doc
+        {true, undefined} ->
+            SecObj0;
+        %% User did not supply rev, use the old rev
+        {true, OldRev} ->
+            [{<<"_rev">>, OldRev} | proplists:delete(<<"_rev">>,
SecObj0)]
+    end,
+    SecDoc = couch_doc_from_req(Req, DocId, {SecObj}),
+    Options = [
+        delay_commit,
+        interactive_edit,
+        {user_ctx, Ctx},
+        {w, integer_to_list(mem3:quorum(Db))}
+    ],
+    {Status, {etag, Etag}, Body} =
+        cassim:set_security(Db, SecDoc, Options),
+    HttpCode = http_code_from_status(Status),
+    ResponseHeaders = [{"Etag", Etag}],
+    send_json(Req, HttpCode, ResponseHeaders, Body).
+
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 


Mime
View raw message