diff options
author | John Christopher Anderson <jchris@apache.org> | 2010-01-05 18:11:58 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2010-01-05 18:11:58 +0000 |
commit | 3a1f041e07c75001cf52cbae1391dcd801c17396 (patch) | |
tree | 749cf6441f847bea450f007b46b01a506beb4a58 /src/couchdb/couch_httpd_db.erl | |
parent | 47d4f324ec2fe0e4ab907b8a023bc689c8192fb1 (diff) |
merge account branch to apache branch
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/account@896158 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_db.erl')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 35f32514..c7e127c2 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -298,13 +298,23 @@ handle_design_info_req(Req, _Db, _DDoc) -> create_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> ok = couch_httpd:verify_is_server_admin(Req), - case couch_server:create(DbName, [{user_ctx, UserCtx}]) of - {ok, Db} -> - couch_db:close(Db), - DocUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), - send_json(Req, 201, [{"Location", DocUrl}], {[{ok, true}]}); - Error -> - throw(Error) + LDbName = ?b2l(DbName), + case couch_config:get("couch_httpd_auth", "authentication_db") of + LDbName -> + % make sure user's db always has the auth ddoc + {ok, Db} = couch_httpd_auth:ensure_users_db_exists(DbName), + couch_db:close(Db), + DbUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), + send_json(Req, 201, [{"Location", DbUrl}], {[{ok, true}]}); + _Else -> + case couch_server:create(DbName, [{user_ctx, UserCtx}]) of + {ok, Db} -> + couch_db:close(Db), + DbUrl = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName)), + send_json(Req, 201, [{"Location", DbUrl}], {[{ok, true}]}); + Error -> + throw(Error) + end end. delete_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> @@ -317,6 +327,14 @@ delete_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) -> end. do_db_req(#httpd{user_ctx=UserCtx,path_parts=[DbName|_]}=Req, Fun) -> + LDbName = ?b2l(DbName), + case couch_config:get("couch_httpd_auth", "authentication_db") of + LDbName -> + % make sure user's db always has the auth ddoc + {ok, ADb} = couch_httpd_auth:ensure_users_db_exists(DbName), + couch_db:close(ADb); + _Else -> ok + end, case couch_db:open(DbName, [{user_ctx, UserCtx}]) of {ok, Db} -> try @@ -553,7 +571,7 @@ db_req(#httpd{path_parts=[_,<<"_revs_limit">>]}=Req, _Db) -> % as slashes in document IDs must otherwise be URL encoded. db_req(#httpd{method='GET',mochi_req=MochiReq, path_parts=[DbName,<<"_design/",_/binary>>|_]}=Req, _Db) -> PathFront = "/" ++ couch_httpd:quote(binary_to_list(DbName)) ++ "/", - [PathFront|PathTail] = re:split(MochiReq:get(raw_path), "_design%2F", + [_|PathTail] = re:split(MochiReq:get(raw_path), "_design%2F", [{return, list}]), couch_httpd:send_redirect(Req, PathFront ++ "_design/" ++ mochiweb_util:join(PathTail, "_design%2F")); |