couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [39/50] chttpd commit: updated refs/heads/master to 58020ab
Date Thu, 28 Aug 2014 12:00:02 GMT
 Only use cassim:set_security if cassim is enabled

BugzId: 32070


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

Branch: refs/heads/master
Commit: 554ef748625f97d21e6808b8ba09981b3ae076c5
Parents: 2a27059
Author: Russell Branca <chewbranca@apache.org>
Authored: Mon Jun 30 13:31:04 2014 -0700
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 72 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/554ef748/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 86e32dd..14e9594 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1395,36 +1395,50 @@ monitor_attachments(Att) ->
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
 
+%% This function should exist in cassim, but its depedence on the #httpd{}
+%% record makes it difficult to separate. This function should be refactored and
+%% moved into cassim once couch_doc_from_req and update_doc are reworked.
 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).
+    case cassim:is_enabled() of
+        true ->
+            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);
+        false ->
+            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
+    end.
 
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").


Mime
View raw message