diff --git a/applications/crossbar/doc/ref/users.md b/applications/crossbar/doc/ref/users.md index 186e6384b91..519a036cf0b 100644 --- a/applications/crossbar/doc/ref/users.md +++ b/applications/crossbar/doc/ref/users.md @@ -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` | diff --git a/applications/crossbar/doc/users.md b/applications/crossbar/doc/users.md index 15359d600d7..bab30bcee56 100644 --- a/applications/crossbar/doc/users.md +++ b/applications/crossbar/doc/users.md @@ -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` | diff --git a/applications/crossbar/priv/api/swagger.json b/applications/crossbar/priv/api/swagger.json index f7d200f5744..80b1c4095e2 100644 --- a/applications/crossbar/priv/api/swagger.json +++ b/applications/crossbar/priv/api/swagger.json @@ -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" diff --git a/applications/crossbar/priv/couchdb/schemas/users.json b/applications/crossbar/priv/couchdb/schemas/users.json index 8b8f2dceab1..5c5e8593092 100644 --- a/applications/crossbar/priv/couchdb/schemas/users.json +++ b/applications/crossbar/priv/couchdb/schemas/users.json @@ -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", diff --git a/core/kazoo_documents/src/kzd_users.erl b/core/kazoo_documents/src/kzd_users.erl index 5b9ae08b1c5..0dd06c03742 100644 --- a/core/kazoo_documents/src/kzd_users.erl +++ b/core/kazoo_documents/src/kzd_users.erl @@ -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]). @@ -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'). diff --git a/core/kazoo_documents/src/kzd_users.erl.src b/core/kazoo_documents/src/kzd_users.erl.src index e92c22a18ad..9de5881fdb8 100644 --- a/core/kazoo_documents/src/kzd_users.erl.src +++ b/core/kazoo_documents/src/kzd_users.erl.src @@ -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]). @@ -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'). diff --git a/core/kazoo_endpoint/src/kz_endpoint.erl b/core/kazoo_endpoint/src/kz_endpoint.erl index c03c21e704d..07f862e536c 100644 --- a/core/kazoo_endpoint/src/kz_endpoint.erl +++ b/core/kazoo_endpoint/src/kz_endpoint.erl @@ -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(), ...]. @@ -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()) ->