Skip to content

Commit

Permalink
WHISTLE-697: be more aggressive creating the account definition in ac…
Browse files Browse the repository at this point in the history
…counts
  • Loading branch information
k-anderson committed Oct 18, 2011
1 parent d9dce44 commit f11ed4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 6 additions & 4 deletions whistle_apps/apps/crossbar/src/modules/cb_accounts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ handle_info({binding_fired, Pid, <<"v1_resource.execute.post.accounts">>, [RD, C
crossbar_util:put_reqid(Context),
crossbar_util:binding_heartbeat(Pid),
Context1 = crossbar_doc:save(Context#cb_context{db_name=whapps_util:get_db_name(AccountId, encoded)}),
whapps_util:replicate_from_account(whapps_util:get_db_name(AccountId, unencoded), ?AGG_DB, ?AGG_FILTER),
couch_mgr:ensure_saved(?AGG_DB, Context1#cb_context.doc),
%% whapps_util:replicate_from_account(whapps_util:get_db_name(AccountId, unencoded), ?AGG_DB, ?AGG_FILTER),
Pid ! {binding_result, true, [RD, Context1, Params]}
end),
{noreply, State};
Expand Down Expand Up @@ -416,10 +417,10 @@ load_account(AccountId, Context) ->
-spec(update_account/2 :: (AccountId :: binary(), Context :: #cb_context{}) -> #cb_context{}).
update_account(AccountId, #cb_context{req_data=Data}=Context) ->
case is_valid_doc(Data) of
{false, Fields} ->
{error, Fields} ->
?LOG_SYS("Failed to validate JSON"),
crossbar_util:response_invalid_data(Fields, Context);
{true, _} ->
{ok, _} ->
case is_unique_realm(AccountId, Context) of
true ->
%% Update the aggregate accounts DB (/accounts/AB/CB)
Expand Down Expand Up @@ -703,7 +704,8 @@ create_new_account_db(#cb_context{doc=Doc}=Context) ->
#cb_context{resp_status=success}=Context1 ->
_ = crossbar_bindings:map(<<"account.created">>, Db),
couch_mgr:revise_docs_from_folder(Db, crossbar, "account"),
whapps_util:replicate_from_account(whapps_util:get_db_name(Db, unencoded), ?AGG_DB, ?AGG_FILTER),
couch_mgr:ensure_saved(?AGG_DB, Doc),
%% whapps_util:replicate_from_account(whapps_util:get_db_name(Db, unencoded), ?AGG_DB, ?AGG_FILTER),
Context1;
Else ->
?LOG_SYS("Other PUT resp: ~s: ~p~n", [Else#cb_context.resp_status, Else#cb_context.doc]),
Expand Down
9 changes: 8 additions & 1 deletion whistle_apps/apps/crossbar/src/modules/cb_shared_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
-define(SERVER, ?MODULE).

-define(TOKEN_DB, <<"token_auth">>).

-define(AGG_DB, <<"accounts">>).
-define(SHARED_AUTH_CONF, list_to_binary([code:lib_dir(crossbar, priv), "/shared_auth/shared_auth.conf"])).

-record(state, {xbar_url=undefined :: undefined | string()}).
Expand Down Expand Up @@ -430,6 +430,13 @@ import_missing_account(AccountId, Account) ->
case couch_mgr:db_exists(Db) of
true ->
?LOG("remote account ~s alread exists locally", [AccountId]),
case couch_mgr:lookup_doc_rev(?AGG_DB, AccountId) of
{error, not_found} ->
?LOG("faild to locate account definition, forcing ~p creation", [AccountId]),
couch_mgr:ensure_saved(?AGG_DB, Account);
_ ->
ok
end,
true;
false ->
Event = <<"v1_resource.execute.put.accounts">>,
Expand Down

0 comments on commit f11ed4a

Please sign in to comment.