Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISTON-1289: create_caller_id_name_if_undefined #6722

Open
wants to merge 3 commits into
base: 4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions applications/crossbar/doc/ref/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Key | Description | Type | Default | Required | Support Level
`ringtones.external` | The alert info SIP header added when the call is from internal sources | `string(0..256)` | | `false` |
`ringtones.internal` | The alert info SIP header added when the call is from external sources | `string(0..256)` | | `false` |
`ringtones` | Ringtone Parameters | `object()` | `{}` | `false` |
`should_create_caller_id` | Create the users caller id name from the first and last name fields if no caller id is defined | `boolean()` | | `false` |
`timezone` | User's timezone | `string()` | | `false` | `supported`
`username` | The GUI login username - alpha-numeric, dashes, at symbol, periods, plusses, and underscores allowed | `string(1..256)` | | `false` | `supported`
`verified` | Determines if the user has been verified | `boolean()` | `false` | `false` |
Expand Down
1 change: 1 addition & 0 deletions applications/crossbar/doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Key | Description | Type | Default | Required | Support Level
`ringtones.external` | The alert info SIP header added when the call is from internal sources | `string(0..256)` | | `false` |
`ringtones.internal` | The alert info SIP header added when the call is from external sources | `string(0..256)` | | `false` |
`ringtones` | Ringtone Parameters | `object()` | `{}` | `false` |
`should_create_caller_id` | Create the users caller id name from the first and last name fields if no caller id is defined | `boolean()` | | `false` |
`timezone` | User's timezone | `string()` | | `false` | `supported`
`username` | The GUI login username - alpha-numeric, dashes, at symbol, periods, plusses, and underscores allowed | `string(1..256)` | | `false` | `supported`
`verified` | Determines if the user has been verified | `boolean()` | `false` | `false` |
Expand Down
4 changes: 4 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -36933,6 +36933,10 @@
},
"type": "object"
},
"should_create_caller_id": {
"description": "Create the users caller id name from the first and last name fields if no caller id is defined",
"type": "boolean"
},
"timezone": {
"description": "User's timezone",
"type": "string"
Expand Down
4 changes: 4 additions & 0 deletions applications/crossbar/priv/couchdb/schemas/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@
},
"type": "object"
},
"should_create_caller_id": {
"description": "Create the users caller id name from the first and last name fields if no caller id is defined",
"type": "boolean"
},
"timezone": {
"description": "User's timezone",
"support_level": "supported",
Expand Down
13 changes: 13 additions & 0 deletions core/kazoo_documents/src/kzd_users.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
-export([ringtones/1, ringtones/2, set_ringtones/2]).
-export([ringtones_external/1, ringtones_external/2, set_ringtones_external/2]).
-export([ringtones_internal/1, ringtones_internal/2, set_ringtones_internal/2]).
-export([should_create_caller_id_name_if_undefined/1, should_create_caller_id_name_if_undefined/2, set_should_create_caller_id_name_if_undefined/2]).
-export([timezone/1, timezone/2, set_timezone/2]).
-export([username/1, username/2, set_username/2]).
-export([verified/1, verified/2, set_verified/2]).
Expand Down Expand Up @@ -663,6 +664,18 @@ ringtones_internal(Doc, Default) ->
set_ringtones_internal(Doc, RingtonesInternal) ->
kz_json:set_value([<<"ringtones">>, <<"internal">>], RingtonesInternal, Doc).

-spec should_create_caller_id_name_if_undefined(doc()) -> kz_term:api_boolean().
should_create_caller_id_name_if_undefined(Doc) ->
should_create_caller_id_name_if_undefined(Doc, 'undefined').

-spec should_create_caller_id_name_if_undefined(doc(), Default) -> boolean() | Default.
should_create_caller_id_name_if_undefined(Doc, Default) ->
kz_json:get_boolean_value([<<"should_create_caller_id_name_if_undefined">>], Doc, Default).

-spec set_should_create_caller_id_name_if_undefined(doc(), boolean()) -> doc().
set_should_create_caller_id_name_if_undefined(Doc, ShouldCreateCallerIdNameIfUndefined) ->
kz_json:set_value([<<"should_create_caller_id_name_if_undefined">>], ShouldCreateCallerIdNameIfUndefined, Doc).

-spec timezone(doc()) -> kz_term:api_binary().
timezone(Doc) ->
timezone(Doc, 'undefined').
Expand Down
13 changes: 13 additions & 0 deletions core/kazoo_documents/src/kzd_users.erl.src
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
-export([ringtones/1, ringtones/2, set_ringtones/2]).
-export([ringtones_external/1, ringtones_external/2, set_ringtones_external/2]).
-export([ringtones_internal/1, ringtones_internal/2, set_ringtones_internal/2]).
-export([should_create_caller_id/1, should_create_caller_id/2, set_should_create_caller_id/2]).
-export([timezone/1, timezone/2, set_timezone/2]).
-export([username/1, username/2, set_username/2]).
-export([verified/1, verified/2, set_verified/2]).
Expand Down Expand Up @@ -663,6 +664,18 @@ ringtones_internal(Doc, Default) ->
set_ringtones_internal(Doc, RingtonesInternal) ->
kz_json:set_value([<<"ringtones">>, <<"internal">>], RingtonesInternal, Doc).

-spec should_create_caller_id(doc()) -> kz_term:api_boolean().
should_create_caller_id(Doc) ->
should_create_caller_id(Doc, 'undefined').

-spec should_create_caller_id(doc(), Default) -> boolean() | Default.
should_create_caller_id(Doc, Default) ->
kz_json:get_boolean_value([<<"should_create_caller_id">>], Doc, Default).

-spec set_should_create_caller_id(doc(), boolean()) -> doc().
set_should_create_caller_id(Doc, ShouldCreateCallerId) ->
kz_json:set_value([<<"should_create_caller_id">>], ShouldCreateCallerId, Doc).

-spec timezone(doc()) -> kz_term:api_binary().
timezone(Doc) ->
timezone(Doc, 'undefined').
Expand Down
10 changes: 7 additions & 3 deletions core/kazoo_endpoint/src/kz_endpoint.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@

-define(RECORDING_ARGS(Call, Data), [kapps_call:clear_helpers(Call), Data]).

-define(SHOULD_CREATE_CALLER_ID(UserJObj), kzd_users:should_create_caller_id(UserJObj, 'true')).

-type sms_route() :: {binary(), kz_term:proplist()}.
-type sms_routes() :: [sms_route(), ...].

Expand Down Expand Up @@ -500,15 +502,17 @@ merge_value(Key, Account, Endpoint, Owner) ->
caller_id_owner_attr(Owner) ->
OwnerAttr = kz_json:get_json_value(<<"caller_id">>, Owner, kz_json:new()),
L = [<<"internal">>, <<"name">>],
case kz_json:get_ne_binary_value(L, OwnerAttr) of
'undefined' ->
case ?SHOULD_CREATE_CALLER_ID(Owner)
andalso not kz_json:is_defined(L, OwnerAttr) of
'true' ->
lager:debug("creating caller id name from users first and last name"),
Name = create_endpoint_name(kz_json:get_ne_binary_value(<<"first_name">>, Owner)
,kz_json:get_ne_binary_value(<<"last_name">>, Owner)
,'undefined'
,'undefined'
),
kz_json:set_value(L, Name, OwnerAttr);
_Else -> OwnerAttr
'false' -> OwnerAttr
end.

-spec merge_call_restrictions(kz_term:ne_binaries(), kz_json:object(), kz_json:object(), kz_json:object()) ->
Expand Down