couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject fabric commit: updated refs/heads/2510-add-system-db-handlers to 4e0e81f
Date Fri, 12 Dec 2014 02:15:19 GMT
Repository: couchdb-fabric
Updated Branches:
  refs/heads/2510-add-system-db-handlers [created] 4e0e81fd9


Add system db handlers to fabric_doc_update

This hard codes the before_doc_write functions for replicator and user
databases like they are in couch_server. This is mostly motivated by the
fact that couch_users_db:before_doc_update/1 adds random salt values to
user documents when a password is changed. The replicator databases are
included at this level for consistency with couch_server.

COUCHDB-2510


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/4e0e81fd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/4e0e81fd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/4e0e81fd

Branch: refs/heads/2510-add-system-db-handlers
Commit: 4e0e81fd9d668bf4d532864b9cab3ad2d7653d50
Parents: 5930256
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Thu Dec 11 20:13:57 2014 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Thu Dec 11 20:13:57 2014 -0600

----------------------------------------------------------------------
 src/fabric_doc_update.erl | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/4e0e81fd/src/fabric_doc_update.erl
----------------------------------------------------------------------
diff --git a/src/fabric_doc_update.erl b/src/fabric_doc_update.erl
index f593b12..4febe13 100644
--- a/src/fabric_doc_update.erl
+++ b/src/fabric_doc_update.erl
@@ -21,7 +21,8 @@
 go(_, [], _) ->
     {ok, []};
 go(DbName, AllDocs0, Opts) ->
-    AllDocs = tag_docs(AllDocs0),
+    AllDocs1 = before_doc_update(DbName, AllDocs0),
+    AllDocs = tag_docs(AllDocs1),
     validate_atomic_update(DbName, AllDocs, lists:member(all_or_nothing, Opts)),
     Options = lists:delete(all_or_nothing, Opts),
     GroupedDocs = lists:map(fun({#shard{name=Name, node=Node} = Shard, Docs}) ->
@@ -97,6 +98,28 @@ handle_message({not_found, no_db_file} = X, Worker, Acc0) ->
 handle_message({bad_request, Msg}, _, _) ->
     throw({bad_request, Msg}).
 
+before_doc_update(DbName, Docs) ->
+    case {is_replicator_db(DbName), is_users_db(DbName)} of
+        {true, _} ->
+            lists:map(fun couch_replicator_manager:before_doc_update/1, Docs);
+        {_, true} ->
+            lists:map(fun couch_users_db:before_doc_update/1, Docs);
+        _ ->
+            Docs
+    end.
+
+is_replicator_db(DbName) ->
+    ConfigName = list_to_binary(config:get("replicator", "db", "_replicator")),
+    DbName == ConfigName orelse path_ends_with(DbName, <<"_replicator">>).
+
+is_users_db(DbName) ->
+    ConfigName = list_to_binary(config:get(
+        "couch_httpd_auth", "authentication_db", "_users")),
+    DbName == ConfigName orelse path_ends_with(DbName, <<"_users">>).
+
+path_ends_with(Path, Suffix) ->
+    Suffix == lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global])).
+
 tag_docs([]) ->
     [];
 tag_docs([#doc{meta=Meta}=Doc | Rest]) ->


Mime
View raw message