Skip to content

Commit

Permalink
KAZOO-1729: allow the super admin to modify the limits at all times a…
Browse files Browse the repository at this point in the history
…nd sub-accounts of the master to change their own limits
  • Loading branch information
k-anderson committed Jan 27, 2015
1 parent e2eaac3 commit 42ca3de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
15 changes: 9 additions & 6 deletions applications/crossbar/src/modules_v1/cb_limits_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.">>,
Expand All @@ -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 ->
Expand All @@ -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'
Expand Down
19 changes: 17 additions & 2 deletions applications/crossbar/src/modules_v2/cb_limits_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 42ca3de

Please sign in to comment.