diff --git a/applications/crossbar/doc/ref/users.md b/applications/crossbar/doc/ref/users.md index 186e6384b91..a405649504c 100644 --- a/applications/crossbar/doc/ref/users.md +++ b/applications/crossbar/doc/ref/users.md @@ -27,6 +27,7 @@ Key | Description | Type | Default | Required | Support Level `caller_id_options` | custom properties for configuring caller_id | `object()` | | `false` | `contact_list.exclude` | If set to true the device is excluded from the contact list | `boolean()` | | `false` | `supported` `contact_list` | Contact List Parameters | `object()` | `{}` | `false` | +`create_caller_id_name_if_undefined` | Create the users caller id name from the first and last name fields if no caller id is defined | `boolean()` | | `false` | `supported` `dial_plan` | A list of rules used to modify dialed numbers | [#/definitions/dialplans](#dialplans) | | `false` | `directories` | Provides the mappings for what directory the user is a part of (the key), and what callflow (the value) to invoke if the user is selected by the caller. | `object()` | | `false` | `do_not_disturb.enabled` | Is do-not-disturb enabled for this user? | `boolean()` | | `false` | diff --git a/applications/crossbar/doc/users.md b/applications/crossbar/doc/users.md index 15359d600d7..e7de0b55751 100644 --- a/applications/crossbar/doc/users.md +++ b/applications/crossbar/doc/users.md @@ -29,6 +29,7 @@ Key | Description | Type | Default | Required | Support Level `caller_id_options` | custom properties for configuring caller_id | `object()` | | `false` | `contact_list.exclude` | If set to true the device is excluded from the contact list | `boolean()` | | `false` | `supported` `contact_list` | Contact List Parameters | `object()` | `{}` | `false` | +`create_caller_id_name_if_undefined` | Create the users caller id name from the first and last name fields if no caller id is defined | `boolean()` | | `false` | `supported` `dial_plan` | A list of rules used to modify dialed numbers | [#/definitions/dialplans](#dialplans) | | `false` | `directories` | Provides the mappings for what directory the user is a part of (the key), and what callflow (the value) to invoke if the user is selected by the caller. | `object()` | | `false` | `do_not_disturb.enabled` | Is do-not-disturb enabled for this user? | `boolean()` | | `false` | diff --git a/applications/crossbar/priv/api/swagger.json b/applications/crossbar/priv/api/swagger.json index f7d200f5744..153e3b68e0d 100644 --- a/applications/crossbar/priv/api/swagger.json +++ b/applications/crossbar/priv/api/swagger.json @@ -36765,6 +36765,10 @@ }, "type": "object" }, + "create_caller_id_name_if_undefined": { + "description": "Create the users caller id name from the first and last name fields if no caller id is defined", + "type": "boolean" + }, "dial_plan": { "$ref": "#/definitions/dialplans", "description": "A list of rules used to modify dialed numbers" diff --git a/applications/crossbar/priv/couchdb/schemas/users.json b/applications/crossbar/priv/couchdb/schemas/users.json index 8b8f2dceab1..edf8a1e3423 100644 --- a/applications/crossbar/priv/couchdb/schemas/users.json +++ b/applications/crossbar/priv/couchdb/schemas/users.json @@ -107,6 +107,11 @@ }, "type": "object" }, + "create_caller_id_name_if_undefined": { + "description": "Create the users caller id name from the first and last name fields if no caller id is defined", + "support_level": "supported", + "type": "boolean" + }, "dial_plan": { "$ref": "dialplans", "description": "A list of rules used to modify dialed numbers" diff --git a/core/kazoo_documents/src/kzd_users.erl b/core/kazoo_documents/src/kzd_users.erl index 5b9ae08b1c5..e76a2ac3e18 100644 --- a/core/kazoo_documents/src/kzd_users.erl +++ b/core/kazoo_documents/src/kzd_users.erl @@ -21,6 +21,7 @@ -export([caller_id/1, caller_id/2, set_caller_id/2]). -export([contact_list/1, contact_list/2, set_contact_list/2]). -export([contact_list_exclude/1, contact_list_exclude/2, set_contact_list_exclude/2]). +-export([create_caller_id_name_if_undefined/1, create_caller_id_name_if_undefined/2, set_create_caller_id_name_if_undefined/2]). -export([dial_plan/1, dial_plan/2, set_dial_plan/2]). -export([directories/1, directories/2, set_directories/2]). -export([do_not_disturb/1, do_not_disturb/2, set_do_not_disturb/2]). @@ -279,6 +280,18 @@ contact_list_exclude(Doc, Default) -> set_contact_list_exclude(Doc, ContactListExclude) -> kz_json:set_value([<<"contact_list">>, <<"exclude">>], ContactListExclude, Doc). +-spec create_caller_id_name_if_undefined(doc()) -> kz_term:api_boolean(). +create_caller_id_name_if_undefined(Doc) -> + create_caller_id_name_if_undefined(Doc, 'undefined'). + +-spec create_caller_id_name_if_undefined(doc(), Default) -> boolean() | Default. +create_caller_id_name_if_undefined(Doc, Default) -> + kz_json:get_boolean_value([<<"create_caller_id_name_if_undefined">>], Doc, Default). + +-spec set_create_caller_id_name_if_undefined(doc(), boolean()) -> doc(). +set_create_caller_id_name_if_undefined(Doc, CreateCallerIdNameIfUndefined) -> + kz_json:set_value([<<"create_caller_id_name_if_undefined">>], CreateCallerIdNameIfUndefined, Doc). + -spec dial_plan(doc()) -> kz_term:api_object(). dial_plan(Doc) -> dial_plan(Doc, 'undefined'). diff --git a/core/kazoo_documents/src/kzd_users.erl.src b/core/kazoo_documents/src/kzd_users.erl.src index e92c22a18ad..5e7a9b578b0 100644 --- a/core/kazoo_documents/src/kzd_users.erl.src +++ b/core/kazoo_documents/src/kzd_users.erl.src @@ -23,6 +23,7 @@ -export([caller_id_options_outbound_privacy/1, caller_id_options_outbound_privacy/2, set_caller_id_options_outbound_privacy/2]). -export([contact_list/1, contact_list/2, set_contact_list/2]). -export([contact_list_exclude/1, contact_list_exclude/2, set_contact_list_exclude/2]). +-export([create_caller_id_name_if_undefined/1, create_caller_id_name_if_undefined/2, set_create_caller_id_name_if_undefined/2]). -export([dial_plan/1, dial_plan/2, set_dial_plan/2]). -export([directories/1, directories/2, set_directories/2]). -export([do_not_disturb/1, do_not_disturb/2, set_do_not_disturb/2]). @@ -279,6 +280,18 @@ contact_list_exclude(Doc, Default) -> set_contact_list_exclude(Doc, ContactListExclude) -> kz_json:set_value([<<"contact_list">>, <<"exclude">>], ContactListExclude, Doc). +-spec create_caller_id_name_if_undefined(doc()) -> kz_term:api_boolean(). +create_caller_id_name_if_undefined(Doc) -> + create_caller_id_name_if_undefined(Doc, 'undefined'). + +-spec create_caller_id_name_if_undefined(doc(), Default) -> boolean() | Default. +create_caller_id_name_if_undefined(Doc, Default) -> + kz_json:get_boolean_value([<<"create_caller_id_name_if_undefined">>], Doc, Default). + +-spec set_create_caller_id_name_if_undefined(doc(), boolean()) -> doc(). +set_create_caller_id_name_if_undefined(Doc, CreateCallerIdNameIfUndefined) -> + kz_json:set_value([<<"create_caller_id_name_if_undefined">>], CreateCallerIdNameIfUndefined, Doc). + -spec dial_plan(doc()) -> kz_term:api_object(). dial_plan(Doc) -> dial_plan(Doc, 'undefined'). diff --git a/core/kazoo_endpoint/src/kz_endpoint.erl b/core/kazoo_endpoint/src/kz_endpoint.erl index c03c21e704d..1f784aabedd 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(CREATE_CALLER_ID_NAME_IF_UNDEFINED(UserJObj), kzd_users:create_caller_id_name_if_undefined(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 ?CREATE_CALLER_ID_NAME_IF_UNDEFINED(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()) ->