Skip to content

Commit

Permalink
Use the accessors luke (2600hz#4511)
Browse files Browse the repository at this point in the history
* bulk rename

* less bad formatting

* update schema with missing properties

* remove extra line from builder

* update kz_device usage with kzd_devices

* nicer xref output

* add more targets

* better rules

* add missing functions

* update docs/swagger with missing fields

* remove unreachable clause, update building

* remove kz_device

* build patternProperty accessors

* add custom functions

* update accounts schema/docs with missing fields

* guess type

* update uses of kz_account->kzd_accounts

* convert calls to document accessors

* fix spec

* join sub-object path

* join with underscores

* just name the var Value

* add more accessors

* fix top-level patternproperties

* add accessors

* update swagger

* update defaults

* use default

* handle diff types of errors

* formatting

* add some defaults

* list the beams

* some grammar corrections

* define schema as a macro and use it

* list the files

* move fixture setup to shared module

* update building new objects

* update building new docs

* notifications are not like those notifications

* compile schemas for testing

* not a notification like we think of notifications

* log schema errors

* switch to fload when testing

* update account doc

* update schemas

* remove kz_account

* don't cache failed media lookups

* handle more classes of input

* return error if upload failed

* use SOURCES to list BEAMS

* populate the app file

* log failed attempt
  • Loading branch information
jamesaimonetti authored and lazedo committed Jan 26, 2018
1 parent e58b855 commit ff2b2f6
Show file tree
Hide file tree
Showing 313 changed files with 2,876 additions and 2,300 deletions.
4 changes: 2 additions & 2 deletions applications/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ init([AccountId, AgentId, Supervisor, Props, IsThief]) ->

-spec max_failures(kz_term:ne_binary() | kz_json:object()) -> non_neg_integer().
max_failures(Account) when is_binary(Account) ->
case kz_account:fetch(Account) of
case kzd_accounts:fetch(Account) of
{'ok', AccountJObj} -> max_failures(AccountJObj);
{'error', _} -> ?MAX_FAILURES
end;
Expand Down Expand Up @@ -1686,7 +1686,7 @@ missed_reason(Reason) -> Reason.

-spec find_username(kz_json:object()) -> kz_term:api_binary().
find_username(EP) ->
find_sip_username(EP, kz_device:sip_username(EP)).
find_sip_username(EP, kzd_devices:sip_username(EP)).

-spec find_sip_username(kz_json:object(), kz_term:api_binary()) -> kz_term:api_binary().
find_sip_username(EP, 'undefined') -> kz_json:get_value(<<"To-User">>, EP);
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_handlers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ send_route_response(ReqJObj, Call, AccountId, Id, Type) ->
,{<<"Routes">>, []}
,{<<"Method">>, <<"park">>}
,{<<"Custom-Channel-Vars">>, kz_json:from_list(CCVs)}
,{<<"From-Realm">>, kz_account:fetch_realm(AccountId)}
,{<<"From-Realm">>, kzd_accounts:fetch_realm(AccountId)}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
],
ServerId = kz_api:server_id(ReqJObj),
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ migrate_to_acdc_db() ->
-spec maybe_remove_acdc_account(kz_term:ne_binary()) -> 'ok'.
maybe_remove_acdc_account(<<"_design/", _/binary>>) -> 'ok';
maybe_remove_acdc_account(AccountId) ->
case kz_account:fetch(AccountId) of
case kzd_accounts:fetch(AccountId) of
{'ok', _} -> 'ok';
{'error', 'not_found'} ->
{'ok', JObj} = kz_datamgr:open_cache_doc(?KZ_ACDC_DB, AccountId),
Expand Down
2 changes: 1 addition & 1 deletion applications/acdc/src/acdc_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ presence_update(AcctId, PresenceId, State) ->

-spec presence_update(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary()) -> 'ok'.
presence_update(AcctId, PresenceId, State, CallId) ->
{'ok', AcctDoc} = kz_account:fetch(AcctId),
{'ok', AcctDoc} = kzd_accounts:fetch(AcctId),
To = <<PresenceId/binary, "@", (kz_json:get_value(<<"realm">>, AcctDoc))/binary>>,

lager:debug("sending presence update '~s' to '~s'", [State, To]),
Expand Down
2 changes: 1 addition & 1 deletion applications/ananke/src/tasks/ananke_vm_callback.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ handle_req(JObj, Props) ->
UserId ->
lager:debug("voicemail owner is ~p", [UserId]),
{'ok', UserJObj} = kz_datamgr:open_cache_doc(AccountDb, UserId),
{'ok', AccountJObj} = kz_account:fetch(AccountId),
{'ok', AccountJObj} = kzd_accounts:fetch(AccountId),

OptionsPath = [<<"notify">>, <<"callback">>],
VMBoxNotifyJObj = kz_json:get_value(OptionsPath, VMBoxJObj),
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/callflow_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ all_accounts_set_classifier_deny(Classifier) ->
-spec set_account_classifier_action(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:ne_binary()) -> 'ok'.
set_account_classifier_action(Action, Classifier, AccountDb) ->
'true' = is_classifier(Classifier),
io:format("found account: ~p", [kz_account:fetch_name(AccountDb)]),
io:format("found account: ~p", [kzd_accounts:fetch_name(AccountDb)]),
AccountId = kz_util:format_account_id(AccountDb, 'raw'),

kz_datamgr:update_doc(AccountDb, AccountId, [{[<<"call_restriction">>, Classifier, <<"action">>], Action}]),
Expand Down
6 changes: 3 additions & 3 deletions applications/callflow/src/cf_route_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ handle_req(JObj, Props) ->
) -> 'ok'.
maybe_prepend_preflow(JObj, Props, Call, Callflow, NoMatch) ->
AccountId = kapps_call:account_id(Call),
case kz_account:fetch(AccountId) of
case kzd_accounts:fetch(AccountId) of
{'error', _E} ->
lager:warning("could not open account doc ~s : ~p", [AccountId, _E]),
maybe_reply_to_req(JObj, Props, Call, Callflow, NoMatch);
{'ok', AccountDoc} ->
case kz_account:preflow_id(AccountDoc) of
case kzd_accounts:preflow_id(AccountDoc) of
'undefined' ->
lager:debug("ignore preflow, not set"),
maybe_reply_to_req(JObj, Props, Call, Callflow, NoMatch);
Expand Down Expand Up @@ -192,7 +192,7 @@ send_route_response(Flow, JObj, Call) ->
,{<<"Transfer-Media">>, get_transfer_media(Flow, JObj)}
,{<<"Ringback-Media">>, get_ringback_media(Flow, JObj)}
,{<<"Pre-Park">>, pre_park_action(Call)}
,{<<"From-Realm">>, kz_account:fetch_realm(AccountId)}
,{<<"From-Realm">>, kzd_accounts:fetch_realm(AccountId)}
,{<<"Custom-Channel-Vars">>, kapps_call:custom_channel_vars(Call)}
,{<<"Custom-Application-Vars">>, kapps_call:custom_application_vars(Call)}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
Expand Down
4 changes: 2 additions & 2 deletions applications/callflow/src/cf_route_win.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ get_services(JObj) ->
-spec maybe_account_service_unavailable(kz_json:object(), kapps_call:call()) -> boolean().
maybe_account_service_unavailable(JObj, Call) ->
AccountId = kapps_call:account_id(Call),
{'ok', Doc} = kz_account:fetch(AccountId),
{'ok', Doc} = kzd_accounts:fetch(AccountId),
Services = get_services(Doc),

case kz_json:is_true([<<"audio">>,<<"enabled">>], Services, 'true') of
Expand Down Expand Up @@ -245,7 +245,7 @@ set_language(Call) ->
Default = kz_media_util:prompt_language(kapps_call:account_id(Call)),
case kz_endpoint:get(Call) of
{'ok', Endpoint} ->
Language = kz_device:language(Endpoint, Default),
Language = kzd_devices:language(Endpoint, Default),
lager:debug("setting language '~s' for this call", [Language]),
kapps_call:set_language(kz_term:to_lower_binary(Language), Call);
{'error', _E} ->
Expand Down
8 changes: 4 additions & 4 deletions applications/callflow/src/cf_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ find_user_endpoints(UserIds, DeviceIds, Call) ->

-spec find_channels(kz_term:ne_binaries(), kapps_call:call()) -> kz_json:objects().
find_channels(Usernames, Call) ->
Realm = kz_account:fetch_realm(kapps_call:account_id(Call)),
Realm = kzd_accounts:fetch_realm(kapps_call:account_id(Call)),
lager:debug("finding channels for realm ~p, usernames ~p", [Realm, Usernames]),
Req = [{<<"Realm">>, Realm}
,{<<"Usernames">>, Usernames}
Expand Down Expand Up @@ -624,7 +624,7 @@ sip_user_from_device_id(EndpointId, Call) ->
case kz_endpoint:get(EndpointId, Call) of
{'error', _} -> 'undefined';
{'ok', Endpoint} ->
kz_device:sip_username(Endpoint)
kzd_devices:sip_username(Endpoint)
end.

-spec wait_for_noop(kapps_call:call(), kz_term:ne_binary()) ->
Expand Down Expand Up @@ -675,8 +675,8 @@ process_event(Call, NoopId, JObj) ->
-spec get_timezone(kz_json:object(), kapps_call:call()) -> kz_term:ne_binary().
get_timezone(JObj, Call) ->
case kz_json:get_ne_binary_value(<<"timezone">>, JObj) of
'undefined' -> kz_account:timezone(kapps_call:account_id(Call));
<<"inherit">> -> kz_account:timezone(kapps_call:account_id(Call)); %% UI-1808
'undefined' -> kzd_accounts:timezone(kapps_call:account_id(Call));
<<"inherit">> -> kzd_accounts:timezone(kapps_call:account_id(Call)); %% UI-1808
TZ -> TZ
end.

Expand Down
4 changes: 2 additions & 2 deletions applications/callflow/src/module/cf_branch_variable.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ handle(Data, Call) ->
ChildName = find_child_in_scope(Scope, Variable, Call),
maybe_branch_to_named_child(ChildName, Call).

-spec maybe_branch_to_named_child(variable_key(), kapps_call:call()) -> kapps_call:call().
-spec maybe_branch_to_named_child(variable_key(), kapps_call:call()) -> 'ok'.
maybe_branch_to_named_child('undefined', Call) ->
lager:info("trying '_'"),
cf_exe:continue(Call);
Expand Down Expand Up @@ -150,7 +150,7 @@ find_child_in_branch(ChildName, Call, Keys) ->
device_owner(Call) ->
DeviceId = kapps_call:authorizing_id(Call),
case kz_datamgr:open_cache_doc(kapps_call:account_db(Call), DeviceId) of
{'ok', JObj} -> kz_device:owner_id(JObj);
{'ok', JObj} -> kzd_devices:owner_id(JObj);
_Else ->
lager:debug("failed to open device doc ~s in account ~s", [DeviceId, kapps_call:account_id(Call)]),
'undefined'
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_camping_feature.erl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ get_sip_usernames_for_target(TargetId, TargetType, Call) ->
-spec get_device_sip_username(kz_term:ne_binary(), kz_term:ne_binary()) -> kz_term:api_ne_binary().
get_device_sip_username(AccountDb, DeviceId) ->
{'ok', JObj} = kz_datamgr:open_cache_doc(AccountDb, DeviceId),
kz_device:sip_username(JObj).
kzd_devices:sip_username(JObj).

-spec no_channels(state(), kapps_call:call()) -> maybe_m('accepted') |
maybe_m('connected').
Expand Down
6 changes: 6 additions & 0 deletions applications/callflow/src/module/cf_device.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ handle(Data, Call) ->
lager:info("completed successful bridge to the device"),
cf_exe:stop(Call);
{'fail', _}=Reason -> maybe_handle_bridge_failure(Reason, Call);
{'error', 'invalid_endpoint'} ->
lager:info("failed to build endpoint from device"),
cf_exe:continue(Call);
{'error', _R} when is_atom(_R) ->
lager:info("failed to build endpoint from device: ~p", [_R]),
cf_exe:continue(Call);
{'error', _R} ->
lager:info("error bridging to device: ~s"
,[kz_json:get_ne_binary_value(<<"Error-Message">>, _R)]
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_disa.erl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ should_restrict_call(Data, Call, Number) ->
%%--------------------------------------------------------------------
-spec should_restrict_call_by_account(kapps_call:call(), kz_term:ne_binary()) -> boolean().
should_restrict_call_by_account(Call, Number) ->
case kz_account:fetch(kapps_call:account_id(Call)) of
case kzd_accounts:fetch(kapps_call:account_id(Call)) of
{'error', _} -> 'false';
{'ok', JObj} ->
Classification = knm_converters:classify(Number),
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_eavesdrop.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sip_user_of_endpoint(EndpointId, Call) ->
case kz_endpoint:get(EndpointId, Call) of
{'error', _} -> 'undefined';
{'ok', Endpoint} ->
kz_device:sip_username(Endpoint)
kzd_devices:sip_username(Endpoint)
end.

-spec no_users(kapps_call:call()) -> any().
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_manual_presence.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
handle(Data, Call) ->
CaptureGroup = kapps_call:kvs_fetch('cf_capture_group', Call),
PresenceId =
case binary:match((P = kz_device:presence_id(Data, CaptureGroup)), <<"@">>) of
case binary:match((P = kzd_devices:presence_id(Data, CaptureGroup)), <<"@">>) of
'nomatch' -> <<P/binary, "@", (kapps_call:request_realm(Call))/binary>>;
_Else -> P
end,
Expand Down
4 changes: 2 additions & 2 deletions applications/callflow/src/module/cf_resources.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ get_from_uri_realm(Data, Call) ->
maybe_get_call_from_realm(Call) ->
case kapps_call:from_realm(Call) of
<<"norealm">> ->
kz_account:fetch_realm(kapps_call:account_id(Call));
kzd_accounts:fetch_realm(kapps_call:account_id(Call));
Realm -> Realm
end.

Expand Down Expand Up @@ -236,7 +236,7 @@ get_sip_headers(Data, Call) ->
],
AuthEndCSH = case kz_endpoint:get(Call) of
{'ok', AuthorizingEndpoint} ->
kz_device:custom_sip_headers_outbound(AuthorizingEndpoint, kz_json:new());
kzd_devices:custom_sip_headers_outbound(AuthorizingEndpoint, kz_json:new());
_ -> kz_json:new()
end,
CSH = kz_json:get_json_value(<<"custom_sip_headers">>, Data),
Expand Down
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_voicemail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ get_user_mailbox_doc(Data, Call, 'undefined') ->
DeviceId = kapps_call:authorizing_id(Call),
case kz_datamgr:open_cache_doc(kapps_call:account_db(Call), DeviceId) of
{'ok', DeviceJObj} ->
case kz_device:owner_id(DeviceJObj) of
case kzd_devices:owner_id(DeviceJObj) of
'undefined' ->
lager:debug("device used to check voicemail has no owner assigned", []),
{'error', "request voicemail box number"};
Expand Down
2 changes: 1 addition & 1 deletion applications/camper/src/camper_offnet_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ init([JObj]) ->

{'ok', StopTimerRef} = timer:apply_after(StopAfter, 'gen_listener', 'cast', [self(), 'stop_campering']),

Moh = case kz_account:fetch(kapps_call:account_id(Call)) of
Moh = case kzd_accounts:fetch(kapps_call:account_id(Call)) of
{'ok', JObj} ->
kz_media_util:media_path(
kz_json:get_value([<<"music_on_hold">>, <<"media_id">>], JObj)
Expand Down
4 changes: 2 additions & 2 deletions applications/cccp/src/cccp_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ cccp_allowed_callee(Number) ->

-spec build_request(kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:api_binary(), kz_term:ne_binary(),binary(),binary()) -> kz_term:proplist().
build_request(CallId, ToDID, AuthorizingId, Q, CtrlQ, AccountId, Action, RetainCID, RetainName, RetainNumber) ->
Realm = kz_account:fetch_realm(AccountId),
Realm = kzd_accounts:fetch_realm(AccountId),
CCVs = props:filter_undefined([{<<"Account-ID">>, AccountId}
,{<<"Authorizing-ID">>, AuthorizingId}
,{<<"Authorizing-Type">>, <<"user">>}
Expand Down Expand Up @@ -295,7 +295,7 @@ is_user_channel(Channel, UserId) ->

-spec current_account_channels(kz_term:ne_binary()) -> kz_json:objects().
current_account_channels(AccountId) ->
Req = [{<<"Realm">>, kz_account:fetch_realm(AccountId)}
Req = [{<<"Realm">>, kzd_accounts:fetch_realm(AccountId)}
,{<<"Usernames">>, []}
,{<<"Account-ID">>, AccountId}
,{<<"Active-Only">>, 'false'}
Expand Down
2 changes: 1 addition & 1 deletion applications/conference/src/conf_participant.erl
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ unbridge_from_conference(Call) ->

-spec get_account_realm(kapps_call:call()) -> kz_term:ne_binary().
get_account_realm(Call) ->
case kz_account:fetch_realm(kapps_call:account_id(Call)) of
case kzd_accounts:fetch_realm(kapps_call:account_id(Call)) of
'undefined' -> <<"unknown">>;
Realm -> Realm
end.
Expand Down
13 changes: 13 additions & 0 deletions applications/crossbar/doc/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Key | Description | Type | Default | Required | Support Level
`music_on_hold.media_id` | The ID of a media object that should be used as the default music on hold | `string(0..2048)` | | `false` |
`music_on_hold` | The default music on hold parameters | `object()` | `{}` | `false` |
`name` | A friendly name for the account | `string(1..128)` | | `true` |
`notifications.first_occurrence.sent_initial_call` | has the account made their first call | `boolean()` | `false` | `false` |
`notifications.first_occurrence.sent_initial_registration` | has the account registered their first device | `boolean()` | `false` | `false` |
`notifications.first_occurrence` | send emails on these account-firsts | `object()` | | `false` |
`notifications.low_balance.enabled` | should the account be checked for this alert | `boolean()` | `true` | `false` |
`notifications.low_balance.last_notification` | Timestamp, in gregorian seconds, of when the last low_balance alert was sent | `integer()` | | `false` |
`notifications.low_balance.sent_low_balance` | has the alert been sent (avoids duplication/spamming) | `boolean()` | | `false` |
`notifications.low_balance.threshold` | account balance to send alert on | `number()` | | `false` |
`notifications.low_balance` | Low balance settings | `object()` | | `false` |
`notifications` | account notification settings | `object()` | | `false` |
`org` | Full legal name of the organization | `string()` | | `false` |
`preflow.always` | The ID of a callflow to always execute prior to processing the callflow with numbers/patterns matching the request | `string()` | | `false` |
`preflow` | Each property provides functionality that can be applied to calls using the callflow application | `object()` | `{}` | `false` |
Expand All @@ -42,9 +51,13 @@ Key | Description | Type | Default | Required | Support Level
`ringtones.internal` | The alert info SIP header added when the call is from external sources | `string(0..256)` | | `false` |
`ringtones` | Ringtone Parameters | `object()` | `{}` | `false` |
`timezone` | The default timezone | `string(5..32)` | | `false` |
`topup.threshold` | The account balance when topup occurs | `number()` | | `false` |
`topup` | Topup settings for the account | `object()` | | `false` |
`voicemail.notify.callback` | | [#/definitions/notify.callback](#notifycallback) | | `false` |
`voicemail.notify` | | `object()` | | `false` |
`voicemail` | | `object()` | | `false` |
`zones.home` | Which zone is considered the account's home zone | `string()` | | `false` |
`zones` | The zone(s) of an account | `object()` | | `false` |

##### call_recording

Expand Down
4 changes: 2 additions & 2 deletions applications/crossbar/doc/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Key | Description | Type | Default | Required | Support Level
`exclude_from_queues` | Do not ring this device when calling user/agent in queue | `boolean()` | `false` | `false` |
`formatters` | | [#/definitions/formatters](#formatters) | | `false` |
`language` | The language for the device | `string()` | | `false` |
`mac_address` | The MAC Address of the device (if applicable) | `string()` | | `false` |
`media` | Configure audio/video/etc media options for this device | [#/definitions/endpoint.media](#endpointmedia) | | `false` |
`metaflows` | The device metaflow parameters | [#/definitions/metaflows](#metaflows) | | `false` |
`music_on_hold.media_id` | The ID of a media object that should be used as the music on hold | `string(0..2048)` | | `false` |
`music_on_hold` | The music on hold parameters used if not a property of the device owner | `object()` | `{}` | `false` |
`mwi_unsolicitated_updates` | When true enables unsolicitated mwi notifications | `boolean()` | `true` | `false` |
`name` | A friendly name for the device | `string(1..128)` | | `true` |
`outbound_flags.[]` | | `string()` | | `false` |
`outbound_flags` | List of flags (features) this device requires when making outbound calls | `array(string())` | | `false` |
`outbound_flags` | List of flags (features) this device requires when making outbound calls | `array(string()) | object()` | | `false` |
`owner_id` | The ID of the user object that 'owns' the device | `string(32)` | | `false` |
`presence_id` | Static presence ID (used instead of SIP username) | `string()` | | `false` |
`provision.combo_keys./^[0-9]+$/.type` | Feature key type | `string('line' | 'presence' | 'parking' | 'personal_parking' | 'speed_dial')` | | `true` |
Expand Down
Loading

0 comments on commit ff2b2f6

Please sign in to comment.