Skip to content

Commit

Permalink
PISTON-1289: Added new attribute to the users object
Browse files Browse the repository at this point in the history
'create_caller_id_name_if_undefined' to allow the creation of the users
caller id name to be optional when no caller id is defined.
  • Loading branch information
bradfordben committed Aug 11, 2021
1 parent 446c630 commit 9f035fe
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions applications/crossbar/doc/ref/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
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 @@ -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` |
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 @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions applications/crossbar/priv/couchdb/schemas/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 @@ -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]).
Expand Down Expand Up @@ -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').
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 @@ -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]).
Expand Down Expand Up @@ -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').
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(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(), ...].

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 ?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()) ->
Expand Down

0 comments on commit 9f035fe

Please sign in to comment.