Skip to content

Commit

Permalink
[4.3] SUPP-22: do not normalize number if there is no dialplan or cap…
Browse files Browse the repository at this point in the history
…ture group (2600hz#6632)

Do not normalize number if there is no dialplan or number is not from
capture group when callflow wins the call.

Normalizing twice may result the number to be classified differently
so call won't be restricted.
  • Loading branch information
icehess authored and kageds committed Sep 24, 2020
1 parent 1f03965 commit afd78b5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions applications/callflow/src/cf_route_win.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,28 @@ maybe_closed_group_restriction(JObj, Call) ->

-spec maybe_classification_restriction(kz_json:object(), kapps_call:call()) ->
boolean().
maybe_classification_restriction(JObj, Call) ->
Request = find_request(Call),
AccountId = kapps_call:account_id(Call),
DialPlan = kz_json:get_json_value(<<"dial_plan">>, JObj, kz_json:new()),
Number = knm_converters:normalize(Request, AccountId, DialPlan),
maybe_classification_restriction(EndPointJObj, Call) ->
Number = maybe_normalize_number(EndPointJObj, Call),
Classification = knm_converters:classify(Number),
lager:debug("classified number ~s as ~s, testing for call restrictions"
,[Number, Classification]
),
kz_json:get_value([<<"call_restriction">>, Classification, <<"action">>], JObj) =:= <<"deny">>.
kz_json:get_value([<<"call_restriction">>, Classification, <<"action">>], EndPointJObj) =:= <<"deny">>.

maybe_normalize_number(EndPointJObj, Call) ->
AccountId = kapps_call:account_id(Call),
DialPlan = kz_json:get_json_value(<<"dial_plan">>, EndPointJObj, kz_json:new()),
Request = find_request(Call),
case kz_json:is_empty(DialPlan)
andalso kapps_call:kvs_fetch('cf_capture_group', Call) =:= 'undefined'
of
'true' ->
lager:debug("no dial plan or capture group, using original dialed number '~s'", [Request]),
Request;
'false' ->
lager:debug("normalizing number '~s'", [Request]),
knm_converters:normalize(Request, AccountId, DialPlan)
end.

-spec find_request(kapps_call:call()) -> kz_term:ne_binary().
find_request(Call) ->
Expand Down

0 comments on commit afd78b5

Please sign in to comment.