couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject couchdb-cassim git commit: Remove public db record [Forced Update!]
Date Tue, 21 Feb 2017 17:20:34 GMT
Repository: couchdb-cassim
Updated Branches:
  refs/heads/COUCHDB-3288-remove-public-db-record 3d214af5f -> 89047a0a3 (forced update)


Remove public db record

COUCHDB-3288


Project: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/commit/89047a0a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/tree/89047a0a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/diff/89047a0a

Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: 89047a0a390f0ebc3206939d4db157aa5e9b55b6
Parents: 9bbfe82
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Thu Feb 16 09:57:26 2017 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Feb 21 11:20:12 2017 -0600

----------------------------------------------------------------------
 src/cassim_security.erl | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-cassim/blob/89047a0a/src/cassim_security.erl
----------------------------------------------------------------------
diff --git a/src/cassim_security.erl b/src/cassim_security.erl
index 08fe791..93c19f5 100644
--- a/src/cassim_security.erl
+++ b/src/cassim_security.erl
@@ -38,9 +38,7 @@ get_security(DbName) ->
     get_security(DbName, [?ADMIN_CTX]).
 
 
-get_security(#db{name=DbName}, Options) ->
-    get_security(DbName, Options);
-get_security(DbName, Options) ->
+get_security(DbName, Options) when is_binary(DbName) ->
     case cassim:is_active() of
         true ->
             UserCtx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
@@ -50,7 +48,9 @@ get_security(DbName, Options) ->
             {proplists:delete(<<"_id">>, SecProps)};
         false ->
             fabric:get_security(DbName, Options)
-    end.
+    end;
+get_security(Db, Options) ->
+    get_security(couch_db:name(Db), Options).
 
 
 get_security_doc(DbName) when is_binary(DbName) ->
@@ -90,20 +90,22 @@ set_security(DbName, SecProps) ->
     set_security(DbName, SecProps, [?ADMIN_CTX]).
 
 
-set_security(#db{name=DbName0}, #doc{}=SecDoc0, Options) ->
+set_security(DbName0, #doc{}=SecDoc0, Options) when is_binary(DbName0) ->
     DbName = mem3:dbname(DbName0),
     MetaId = cassim_metadata_cache:security_meta_id(DbName),
     SecDoc = SecDoc0#doc{id=MetaId},
     UserCtx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
     MetaDbName = cassim_metadata_cache:metadata_db(),
-    MetaDb = #db{name=MetaDbName, user_ctx=?ADMIN_USER},
+    MetaDb = couch_db:clustered_db(MetaDbName, ?ADMIN_USER),
     cassim:verify_admin_role(UserCtx),
     ok = validate_security_doc(SecDoc),
     {Status, Etag, {Body0}} =
         chttpd_db:update_doc(MetaDb, MetaId, SecDoc, Options),
     Body = {proplists:delete(<<"_id">>, Body0)},
     ok = cassim_metadata_cache:cleanup_old_docs(MetaId),
-    {Status, Etag, Body}.
+    {Status, Etag, Body};
+set_security(Db, SecDoc, Options) ->
+    set_security(couch_db:name(Db), SecDoc, Options).
 
 
 migrate_security_props(DbName0, {SecProps}) ->
@@ -111,7 +113,7 @@ migrate_security_props(DbName0, {SecProps}) ->
     MetaId = cassim_metadata_cache:security_meta_id(DbName),
     SecDoc = #doc{id=MetaId, body={SecProps}},
     MetaDbName = cassim_metadata_cache:metadata_db(),
-    MetaDb = #db{name=MetaDbName, user_ctx=?ADMIN_USER},
+    MetaDb = couch_db:clustered_db(MetaDbName, ?ADMIN_USER),
     %% Better way to construct a new #doc{} with the rev?
     {_, _, {Body}} = chttpd_db:update_doc(MetaDb, MetaId, SecDoc, [?ADMIN_CTX]),
     Rev = proplists:get_value(rev, Body),
@@ -149,8 +151,5 @@ validate_roles_list(Field, _Roles) ->
 
 
 check_is_member(UserCtx, SecProps) ->
-    FakeDb = #db{
-        security = SecProps,
-        user_ctx = UserCtx
-    },
+    {ok, FakeDb} = couch_db:clustered_db(<<"foo">>, UserCtx, SecProps),
     couch_db:check_is_member(FakeDb).


Mime
View raw message