From 42ca3ded7abd566e0e79ab230c1d05cb06913d2e Mon Sep 17 00:00:00 2001 From: karl anderson Date: Tue, 27 Jan 2015 18:19:33 -0500 Subject: [PATCH] KAZOO-1729: allow the super admin to modify the limits at all times and sub-accounts of the master to change their own limits --- .../crossbar/src/modules_v1/cb_limits_v1.erl | 15 +++++++++------ .../crossbar/src/modules_v2/cb_limits_v2.erl | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/applications/crossbar/src/modules_v1/cb_limits_v1.erl b/applications/crossbar/src/modules_v1/cb_limits_v1.erl index f60df831b37..90a6041fc22 100644 --- a/applications/crossbar/src/modules_v1/cb_limits_v1.erl +++ b/applications/crossbar/src/modules_v1/cb_limits_v1.erl @@ -74,10 +74,7 @@ process_billing(Context, [{<<"limits">>, _}|_], ?HTTP_GET) -> Context; process_billing(Context, [{<<"limits">>, _}|_], _Verb) -> AccountId = cb_context:account_id(Context), - AuthAccountId = cb_context:auth_account_id(Context), - try wh_services:allow_updates(AccountId) - andalso authd_account_allowed_updates(AccountId, AuthAccountId) - of + try wh_services:allow_updates(AccountId) andalso is_allowed(Context) of 'true' -> Context; 'false' -> Message = <<"Please contact your phone provider to add limits.">>, @@ -88,8 +85,11 @@ process_billing(Context, [{<<"limits">>, _}|_], _Verb) -> end; process_billing(Context, _Nouns, _Verb) -> Context. --spec authd_account_allowed_updates(ne_binary(), ne_binary()) -> boolean(). -authd_account_allowed_updates(AccountId, AuthAccountId) -> +-spec is_allowed(cb_context:context()) -> boolean(). +is_allowed(Context) -> + AccountId = cb_context:account_id(Context), + AuthAccountId = cb_context:auth_account_id(Context), + IsSystemAdmin = wh_util:is_system_admin(AuthAccountId), {'ok', MasterAccount} = whapps_util:get_master_account_id(), case wh_services:find_reseller_id(AccountId) of AuthAccountId -> @@ -98,6 +98,9 @@ authd_account_allowed_updates(AccountId, AuthAccountId) -> MasterAccount -> lager:debug("allowing direct account to update limits"), 'true'; + _Else when IsSystemAdmin -> + lager:debug("allowing system admin to update limits"), + 'true'; _Else -> lager:debug("sub-accounts of non-master resellers must contact the reseller to change their limits"), 'false' diff --git a/applications/crossbar/src/modules_v2/cb_limits_v2.erl b/applications/crossbar/src/modules_v2/cb_limits_v2.erl index 1dd170bcacc..a7447219962 100644 --- a/applications/crossbar/src/modules_v2/cb_limits_v2.erl +++ b/applications/crossbar/src/modules_v2/cb_limits_v2.erl @@ -87,9 +87,24 @@ process_billing(Context, _Nouns, _Verb) -> Context. -spec is_allowed(cb_context:context()) -> boolean(). is_allowed(Context) -> - ResellerId = wh_services:find_reseller_id(cb_context:account_id(Context)), + AccountId = cb_context:account_id(Context), AuthAccountId = cb_context:auth_account_id(Context), - (AuthAccountId =:= ResellerId orelse wh_util:is_system_admin(AuthAccountId)). + IsSystemAdmin = wh_util:is_system_admin(AuthAccountId), + {'ok', MasterAccount} = whapps_util:get_master_account_id(), + case wh_services:find_reseller_id(AccountId) of + AuthAccountId -> + lager:debug("allowing reseller to update limits"), + 'true'; + MasterAccount -> + lager:debug("allowing direct account to update limits"), + 'true'; + _Else when IsSystemAdmin -> + lager:debug("allowing system admin to update limits"), + 'true'; + _Else -> + lager:debug("sub-accounts of non-master resellers must contact the reseller to change their limits"), + 'false' + end. %%-------------------------------------------------------------------- %% @private