summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-07 10:40:14 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-06-07 10:40:14 -0400
commit3d4fdbbfa1393ea7e3ed8898164852ffbe139576 (patch)
tree1093931af18f1254d199db249aa92a21e3a2afeb
parent25238d8967ec52cfc8d132b1a2747ba587787e04 (diff)
partial support for #user_ctx in fabric RPC calls, BugzID 10277
-rw-r--r--src/fabric.erl25
-rw-r--r--src/fabric_rpc.erl14
2 files changed, 26 insertions, 13 deletions
diff --git a/src/fabric.erl b/src/fabric.erl
index b493d55c..29af3224 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -36,29 +36,29 @@ get_doc_count(DbName) ->
fabric_db_doc_count:go(dbname(DbName)).
create_db(DbName, Options) ->
- fabric_db_create:create_db(dbname(DbName), Options).
+ fabric_db_create:create_db(dbname(DbName), opts(Options)).
delete_db(DbName, Options) ->
- fabric_db_delete:delete_db(dbname(DbName), Options).
+ fabric_db_delete:delete_db(dbname(DbName), opts(Options)).
open_doc(DbName, Id, Options) ->
- fabric_doc_open:go(dbname(DbName), docid(Id), Options).
+ fabric_doc_open:go(dbname(DbName), docid(Id), opts(Options)).
open_revs(DbName, Id, Revs, Options) ->
- fabric_doc_open_revs:go(dbname(DbName), docid(Id), Revs, Options).
+ fabric_doc_open_revs:go(dbname(DbName), docid(Id), Revs, opts(Options)).
get_missing_revs(DbName, IdsRevs) when is_list(IdsRevs) ->
Sanitized = [idrevs(IdR) || IdR <- IdsRevs],
fabric_doc_missing_revs:go(dbname(DbName), Sanitized).
update_doc(DbName, Doc, Options) ->
- {ok, [Result]} = update_docs(DbName, [Doc], Options),
+ {ok, [Result]} = update_docs(DbName, [Doc], opts(Options)),
Result.
update_docs(DbName, Docs, Options) ->
- fabric_doc_update:go(dbname(DbName), docs(Docs), Options).
+ fabric_doc_update:go(dbname(DbName), docs(Docs), opts(Options)).
all_docs(DbName, #view_query_args{} = QueryArgs, Callback, Acc0) when
@@ -101,6 +101,19 @@ rev(Rev) when is_list(Rev); is_binary(Rev) ->
rev({Seq, Hash} = Rev) when is_integer(Seq), is_binary(Hash) ->
Rev.
+opts(Options) ->
+ case couch_util:get_value(user_ctx, Options) of
+ undefined ->
+ case erlang:get(user_ctx) of
+ #user_ctx{} = Ctx ->
+ [{user_ctx, Ctx} | Options];
+ _ ->
+ Options
+ end;
+ _ ->
+ Options
+ end.
+
generate_customer_path("/", _Customer) ->
"";
generate_customer_path("/favicon.ico", _Customer) ->
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index 81a8ba48..a2d42007 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -40,10 +40,10 @@ all_docs(DbName, #view_query_args{keys=nil} = QueryArgs) ->
final_all_docs_response(Db, Acc#view_acc.offset).
get_db_info(DbName) ->
- with_db(DbName, {couch_db, get_db_info, []}).
+ with_db(DbName, [], {couch_db, get_db_info, []}).
get_doc_count(DbName) ->
- with_db(DbName, {couch_db, get_doc_count, []}).
+ with_db(DbName, [], {couch_db, get_doc_count, []}).
get_update_seq(DbName) ->
rexi:reply(case couch_db:open(DbName, []) of
@@ -54,10 +54,10 @@ get_update_seq(DbName) ->
end).
open_doc(DbName, DocId, Options) ->
- with_db(DbName, {couch_db, open_doc_int, [DocId, Options]}).
+ with_db(DbName, Options, {couch_db, open_doc_int, [DocId, Options]}).
open_revs(DbName, Id, Revs, Options) ->
- with_db(DbName, {couch_db, open_doc_revs, [Id, Revs, Options]}).
+ with_db(DbName, Options, {couch_db, open_doc_revs, [Id, Revs, Options]}).
get_missing_revs(DbName, IdRevsList) ->
% reimplement here so we get [] for Ids with no missing revs in response
@@ -77,14 +77,14 @@ get_missing_revs(DbName, IdRevsList) ->
end).
update_docs(DbName, Docs, Options) ->
- with_db(DbName, {couch_db, update_docs, [Docs, Options]}).
+ with_db(DbName, Options, {couch_db, update_docs, [Docs, Options]}).
%%
%% internal
%%
-with_db(DbName, {M,F,A}) ->
- case couch_db:open(DbName, []) of
+with_db(DbName, Options, {M,F,A}) ->
+ case couch_db:open(DbName, Options) of
{ok, Db} ->
rexi:reply(apply(M, F, [Db | A]));
Error ->