couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r915829 - in /couchdb/branches/0.11.x: ./ etc/default/couchdb share/www/script/test/reader_acl.js src/couchdb/couch_db.erl src/couchdb/couch_rep.erl src/couchdb/couch_view_group.erl
Date Wed, 24 Feb 2010 15:38:52 GMT
Author: jchris
Date: Wed Feb 24 15:38:52 2010
New Revision: 915829

URL: http://svn.apache.org/viewvc?rev=915829&view=rev
Log:
backport 915827 from trunk to 0.11.x to allow view generation and replication to work with
read-controlled databases

Modified:
    couchdb/branches/0.11.x/   (props changed)
    couchdb/branches/0.11.x/etc/default/couchdb   (props changed)
    couchdb/branches/0.11.x/share/www/script/test/reader_acl.js
    couchdb/branches/0.11.x/src/couchdb/couch_db.erl
    couchdb/branches/0.11.x/src/couchdb/couch_rep.erl
    couchdb/branches/0.11.x/src/couchdb/couch_view_group.erl

Propchange: couchdb/branches/0.11.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 24 15:38:52 2010
@@ -6,4 +6,4 @@
 /couchdb/branches/list-iterator:782292-784593
 /couchdb/branches/tail_header:775760-778477
 /couchdb/tags/0.10.0:825400
-/couchdb/trunk:909247,910054,910696,910910-910911,911544,911559,911578,911602,911717,911837,912474,912606,912608,912615,912636,915529
+/couchdb/trunk:909247,910054,910696,910910-910911,911544,911559,911578,911602,911717,911837,912474,912606,912608,912615,912636,915529,915827

Propchange: couchdb/branches/0.11.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 24 15:38:52 2010
@@ -6,5 +6,5 @@
 /couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
 /couchdb/branches/tail_header/etc/default/couchdb:775760-778477
 /couchdb/tags/0.10.0/etc/default/couchdb:825400
-/couchdb/trunk/etc/default/couchdb:909247,910054,910696,911544,911602,911717,911837,912474,912606,912608,912615,912636,915529
+/couchdb/trunk/etc/default/couchdb:909247,910054,910696,911544,911602,911717,911837,912474,912606,912608,912615,912636,915529,915827
 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440

Modified: couchdb/branches/0.11.x/share/www/script/test/reader_acl.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/reader_acl.js?rev=915829&r1=915828&r2=915829&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/reader_acl.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/reader_acl.js Wed Feb 24 15:38:52 2010
@@ -90,10 +90,26 @@
       // server _admin can always read
       T(secretDb.open("baz").foo == "bar");
 
+      // and run temp views
+      TEquals(secretDb.query(function(doc) {
+        emit(null, null)
+      }).total_rows, 1);
+
+      T(secretDb.save({
+        "_id" : "_design/foo",
+        views : {
+          bar : {
+            map : "function(doc){emit(null, null)}"
+          }
+        }
+      }).ok)
+
       // now top-secret users can read too
       T(CouchDB.login("jchris@apache.org", "funnybone").ok);
       T(CouchDB.session().userCtx.roles.indexOf("_admin") == -1);
       T(secretDb.open("baz").foo == "bar");
+      // readers can query stored views
+      T(secretDb.view("foo/bar").total_rows == 1);
       
       CouchDB.logout();
 

Modified: couchdb/branches/0.11.x/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_db.erl?rev=915829&r1=915828&r2=915829&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_db.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_db.erl Wed Feb 24 15:38:52 2010
@@ -13,7 +13,7 @@
 -module(couch_db).
 -behaviour(gen_server).
 
--export([open/2,close/1,create/2,start_compact/1,get_db_info/1,get_design_docs/1]).
+-export([open/2,open_int/2,close/1,create/2,start_compact/1,get_db_info/1,get_design_docs/1]).
 -export([open_ref_counted/2,is_idle/1,monitor/1,count_changes_since/2]).
 -export([update_doc/3,update_doc/4,update_docs/4,update_docs/2,update_docs/3,delete_doc/3]).
 -export([get_doc_info/2,open_doc/2,open_doc/3,open_doc_revs/4]).
@@ -64,6 +64,13 @@
 create(DbName, Options) ->
     couch_server:create(DbName, Options).
 
+% this is for opening a database for internal purposes like the replicator
+% or the view indexer. it never throws a reader error.
+open_int(DbName, Options) ->
+    couch_server:open(DbName, Options).
+
+% this should be called anytime an http request opens the database.
+% it ensures that the http userCtx is a valid reader
 open(DbName, Options) ->
     case couch_server:open(DbName, Options) of
         {ok, Db} ->

Modified: couchdb/branches/0.11.x/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_rep.erl?rev=915829&r1=915828&r2=915829&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_rep.erl Wed Feb 24 15:38:52 2010
@@ -646,7 +646,7 @@
     true = proplists:get_value(<<"ok">>, ResultProps),
     proplists:get_value(<<"instance_start_time">>, ResultProps);
 ensure_full_commit(Target) ->
-    {ok, NewDb} = couch_db:open(Target#db.name, []),
+    {ok, NewDb} = couch_db:open_int(Target#db.name, []),
     UpdateSeq = couch_db:get_update_seq(Target),
     CommitSeq = couch_db:get_committed_update_seq(NewDb),
     InstanceStartTime = NewDb#db.instance_start_time,
@@ -674,7 +674,7 @@
         proplists:get_value(<<"instance_start_time">>, ResultProps);
     undefined -> nil end;
 ensure_full_commit(Source, RequiredSeq) ->
-    {ok, NewDb} = couch_db:open(Source#db.name, []),
+    {ok, NewDb} = couch_db:open_int(Source#db.name, []),
     CommitSeq = couch_db:get_committed_update_seq(NewDb),
     InstanceStartTime = NewDb#db.instance_start_time,
     couch_db:close(NewDb),
@@ -705,7 +705,7 @@
 up_to_date(#http_db{}, _Seq) ->
     true;
 up_to_date(Source, Seq) ->
-    {ok, NewDb} = couch_db:open(Source#db.name, []),
+    {ok, NewDb} = couch_db:open_int(Source#db.name, []),
     T = NewDb#db.update_seq == Seq,
     couch_db:close(NewDb),
     T.

Modified: couchdb/branches/0.11.x/src/couchdb/couch_view_group.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_view_group.erl?rev=915829&r1=915828&r2=915829&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_view_group.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_view_group.erl Wed Feb 24 15:38:52 2010
@@ -125,7 +125,7 @@
             updater_pid=nil,
             waiting_list=WaitList
             }=State) when RequestSeq > Seq ->
-    {ok, Db} = couch_db:open(DbName, []),
+    {ok, Db} = couch_db:open_int(DbName, []),
     Group2 = Group#group{db=Db},
     Owner = self(),
     Pid = spawn_link(fun()-> couch_view_updater:update(Owner, Group2) end),
@@ -164,7 +164,7 @@
         init_args = {RootDir, DbName, _}
     } = State,
     ?LOG_INFO("View index compaction starting for ~s ~s", [DbName, GroupId]),
-    {ok, Db} = couch_db:open(DbName, []),
+    {ok, Db} = couch_db:open_int(DbName, []),
     {ok, Fd} = open_index_file(compact, RootDir, DbName, GroupSig),
     NewGroup = reset_file(Db, Fd, DbName, Group),
     Pid = spawn_link(fun() -> CompactFun(Group, NewGroup) end),
@@ -224,7 +224,7 @@
     ?LOG_INFO("View index compaction still behind for ~s ~s -- current: ~p " ++
         "compact: ~p", [DbName, GroupId, CurrentSeq, NewGroup#group.current_seq]),
     couch_db:close(NewGroup#group.db),
-    {ok, Db} = couch_db:open(DbName, []),
+    {ok, Db} = couch_db:open_int(DbName, []),
     Pid = spawn_link(fun() ->
         {_,Ref} = erlang:spawn_monitor(fun() ->
             couch_view_updater:update(nil, NewGroup#group{db = Db})
@@ -257,7 +257,7 @@
     {noreply, State}.
 
 handle_info(delayed_commit, #group_state{db_name=DbName,group=Group}=State) ->
-    {ok, Db} = couch_db:open(DbName, []),
+    {ok, Db} = couch_db:open_int(DbName, []),
     CommittedSeq = couch_db:get_committed_update_seq(Db),
     couch_db:close(Db),
     if CommittedSeq >= Group#group.current_seq ->
@@ -292,7 +292,7 @@
                 group=Group#group{db=nil}, updater_pid=nil}};
     StillWaiting ->
         % we still have some waiters, reopen the database and reupdate the index
-        {ok, Db2} = couch_db:open(DbName, []),
+        {ok, Db2} = couch_db:open_int(DbName, []),
         Group2 = Group#group{db=Db2},
         Owner = self(),
         Pid = spawn_link(fun() -> couch_view_updater:update(Owner, Group2) end),
@@ -372,7 +372,7 @@
     State#group_state{waiting_list=[]}.
 
 prepare_group({RootDir, DbName, #group{sig=Sig}=Group}, ForceReset)->
-    case couch_db:open(DbName, []) of
+    case couch_db:open_int(DbName, []) of
     {ok, Db} ->
         case open_index_file(RootDir, DbName, Sig) of
         {ok, Fd} ->
@@ -437,7 +437,7 @@
     end.
 
 open_temp_group(DbName, Language, DesignOptions, MapSrc, RedSrc) ->
-    case couch_db:open(DbName, []) of
+    case couch_db:open_int(DbName, []) of
     {ok, Db} ->
         View = #view{map_names=[<<"_temp">>],
             id_num=0,
@@ -459,7 +459,7 @@
     G#group{sig=erlang:md5(term_to_binary({Views, Language, DesignOptions}))}.
 
 open_db_group(DbName, GroupId) ->
-    case couch_db:open(DbName, []) of
+    case couch_db:open_int(DbName, []) of
     {ok, Db} ->
         case couch_db:open_doc(Db, GroupId) of
         {ok, Doc} ->



Mime
View raw message