Skip to content

Commit

Permalink
HELP-44059: flush registration when device is deleted using api_v1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
icehess authored and lazedo committed May 31, 2019
1 parent ccf681e commit 75f062a
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions applications/crossbar/src/modules_v1/cb_devices_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,24 @@ validate_device(Context, DeviceId, ?HTTP_DELETE) ->

-spec post(cb_context:context(), path_token()) -> cb_context:context().
post(Context, DeviceId) ->
_ = kz_util:spawn(fun crossbar_util:flush_registration/1, [Context]),
case changed_mac_address(Context) of
'true' ->
_ = crossbar_util:maybe_refresh_fs_xml('device', Context),
Context1 = cb_modules_util:take_sync_field(Context),
Context2 = crossbar_doc:save(Context1),
_ = maybe_aggregate_device(DeviceId, Context2),
_ = kz_util:spawn(
fun() ->
_ = provisioner_util:maybe_provision(Context2),
_ = provisioner_util:maybe_sync_sip_data(Context1, 'device')
end),
Context2;
case cb_context:resp_status(Context2) of
'success' ->
_ = kz_util:spawn(fun crossbar_util:flush_registration/1, [Context2]),
_ = crossbar_util:maybe_refresh_fs_xml('device', Context2),
_ = maybe_aggregate_device(DeviceId, Context2),
_ = kz_util:spawn(fun() ->
_ = provisioner_util:maybe_provision(Context2),
_ = provisioner_util:maybe_sync_sip_data(Context2, 'device')
end
),
Context2;
_ ->
Context2
end;
'false' ->
error_used_mac_address(Context)
end.
Expand All @@ -190,12 +195,17 @@ put(Context, DeviceId) ->

-spec delete(cb_context:context(), path_token()) -> cb_context:context().
delete(Context, DeviceId) ->
_ = crossbar_util:refresh_fs_xml(Context),
Context1 = crossbar_doc:delete(Context),
_ = crossbar_util:flush_registration(Context),
_ = kz_util:spawn(fun provisioner_util:maybe_delete_provision/1, [Context]),
_ = maybe_remove_aggregate(DeviceId, Context),
Context1.
case cb_context:resp_status(Context) of
'success' ->
_ = crossbar_util:flush_registration(Context1),
_ = crossbar_util:refresh_fs_xml(Context1),
_ = kz_util:spawn(fun provisioner_util:maybe_delete_provision/1, [Context1]),
_ = maybe_remove_aggregate(DeviceId, Context1),
Context1;
_ ->
Context1
end.

%%%=============================================================================
%%% Internal functions
Expand Down

0 comments on commit 75f062a

Please sign in to comment.