Permalink
Browse files

WHISTLE-680 cb_cdrs was not using the right + problem with pivot keys…

… from user_id to sip user@realm
  • Loading branch information...
1 parent 53b9681 commit c9285e2f96247cf6ac60447e31ee2015e44a9351 Edouard Swiac committed Oct 14, 2011
@@ -6,7 +6,7 @@
"map": "function(doc) { if(doc.pvt_deleted || doc.pvt_type != 'cdr') return; emit(doc._id, {'id':doc._id, 'caller_id_name': doc.caller_id_name, 'caller_id_number': doc.caller_id_number, 'callee_id_name': doc.callee_id_name, 'callee_id_number': doc.callee_id_number, 'duration_seconds': doc.duration_seconds, 'billing_seconds': doc.billing_seconds, 'timestamp': doc.timestamp, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'owner_id':doc.custom_channel_vars.owner_id})}"
},
"listing_by_user" : {
- "map": "function(doc) { if(doc.pvt_deleted || doc.pvt_type != 'cdr') return; emit([doc.custom_channel_vars.username, doc.custom_channel_vars.realm], {'id':doc._id, 'caller_id_name': doc.caller_id_name, 'caller_id_number': doc.caller_id_number, 'callee_id_name': doc.callee_id_name, 'callee_id_number': doc.callee_id_number, 'duration_seconds': doc.duration_seconds, 'timestamp': doc.timestamp, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'call_direction':doc.call_direction})}"
+ "map": "function(doc) { if(doc.pvt_deleted || doc.pvt_type != 'cdr') return; emit([doc.custom_channel_vars.realm, doc.custom_channel_vars.username], {'id':doc._id, 'caller_id_name': doc.caller_id_name, 'caller_id_number': doc.caller_id_number, 'callee_id_name': doc.callee_id_name, 'callee_id_number': doc.callee_id_number, 'duration_seconds': doc.duration_seconds, 'timestamp': doc.timestamp, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'call_direction':doc.call_direction})}"
}
}
}
@@ -4,6 +4,9 @@
,"views": {
"crossbar_listing": {
"map": "function(doc) { if (doc.pvt_type != 'device' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'owner_id': doc.owner_id}); }"
+ },
+ "listing_by_owner": {
+ "map": "function(doc) { if (doc.pvt_type != 'device' || doc.pvt_deleted) return; emit(doc.owner_id, {'id': doc._id, 'name': doc.name}); }"
}
,"sip_credentials":{
"map": "function(doc) { if (typeof doc.sip == 'undefined' || doc.pvt_deleted) return; var sip = JSON.parse(JSON.stringify(doc.sip)); sip.authorizing_id = doc._id; if(typeof(sip.realm) == 'string') { emit([sip.realm, sip.username], sip); } else { for (var i in sip.realm) emit([sip.realm[i], sip.username], sip); } }"
@@ -24,7 +24,7 @@
-include_lib("webmachine/include/webmachine.hrl").
-define(SERVER, ?MODULE).
--define(CB_LIST_BY_USER, <<"cdrs/listing_by_owner">>).
+-define(CB_LIST_BY_USER, <<"cdrs/listing_by_user">>).
-define(CB_LIST, <<"cdrs/crossbar_listing">>).
%%%===================================================================
@@ -247,7 +247,12 @@ load_cdr_summary(#cb_context{db_name=DbName}=Context, QueryParams) ->
Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST, QueryParams, []),
Context#cb_context{resp_data=Result, resp_status=success, resp_etag=automatic};
{<<"users">>, [UserId]} ->
- Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST_BY_USER, QueryParams, [{<<"key">>, UserId}]),
+ {ok, SipCredsFromDevices} = couch_mgr:get_results(DbName, <<"devices/listing_by_owner">>, [{<<"key">>, UserId}, {<<"include_docs">>, true}]),
+ SipCredsKeys = lists:foldl(fun(SipCred, Acc) ->
+ [[wh_json:get_value([<<"doc">>, <<"sip">>, <<"realm">>], SipCred),
+ wh_json:get_value([<<"doc">>, <<"sip">>, <<"username">>], SipCred)]|Acc]
+ end, [], SipCredsFromDevices),
+ Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST_BY_USER, QueryParams, [{<<"keys">>, SipCredsKeys}]),
Context#cb_context{resp_data=Result, resp_status=success, resp_etag=automatic};
_ ->
crossbar_util:response_faulty_request(Context)
@@ -24,7 +24,7 @@
-include_lib("webmachine/include/webmachine.hrl").
-define(SERVER, ?MODULE).
--define(CB_LIST_BY_USER, <<"cdrs/listing_by_owner">>).
+-define(CB_LIST_BY_USER, <<"cdrs/listing_by_user">>).
-define(CB_LIST, <<"cdrs/crossbar_listing">>).
%%%===================================================================
@@ -247,7 +247,12 @@ load_cdr_summary(#cb_context{db_name=DbName}=Context, QueryParams) ->
Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST, QueryParams, []),
Context#cb_context{resp_data=Result, resp_status=success, resp_etag=automatic};
{<<"users">>, [UserId]} ->
- Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST_BY_USER, QueryParams, [{<<"key">>, UserId}]),
+ {ok, SipCredsFromDevices} = couch_mgr:get_results(DbName, <<"devices/listing_by_owner">>, [{<<"key">>, UserId}, {<<"include_docs">>, true}]),
+ SipCredsKeys = lists:foldl(fun(SipCred, Acc) ->
+ [[wh_json:get_value([<<"doc">>, <<"sip">>, <<"realm">>], SipCred),
+ wh_json:get_value([<<"doc">>, <<"sip">>, <<"username">>], SipCred)]|Acc]
+ end, [], SipCredsFromDevices),
+ Result = crossbar_filter:filter_on_query_string(DbName, ?CB_LIST_BY_USER, QueryParams, [{<<"keys">>, SipCredsKeys}]),
Context#cb_context{resp_data=Result, resp_status=success, resp_etag=automatic};
_ ->
crossbar_util:response_faulty_request(Context)

0 comments on commit c9285e2

Please sign in to comment.