Skip to content

Commit

Permalink
[master] fix removing comments when rejected->submitted (2600hz#5851)
Browse files Browse the repository at this point in the history
* maybe this is removing comments?

* format phonebook comments not context

* remove time info from requested port date since user can't choose the time anyway

* fix spec
  • Loading branch information
icehess authored and swysor committed Jun 14, 2019
1 parent dbb0321 commit 425d56d
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 30 deletions.
48 changes: 30 additions & 18 deletions applications/crossbar/src/modules/cb_port_requests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -568,19 +568,28 @@ handle_phonebook_error(Context, Code, Response) ->
-spec handle_phonebook_response(cb_context:context(), kz_json:object()) -> cb_context:context().
handle_phonebook_response(Context, Response) ->
Data = kz_json:get_value(<<"data">>, Response, kz_json:new()),
Comments = kz_json:get_list_value(<<"comments">>, Data, []),
{NewContext, NewData} = maybe_phonebook_comments(Context, Data, Comments),
NewDoc = kz_json:merge([cb_context:doc(NewContext), NewData]),
cb_context:set_doc(NewContext, NewDoc).

-spec maybe_phonebook_comments(cb_context:context(), kz_json:object(), kz_json:objects()) -> {cb_context:context(), kz_json:object()}.
maybe_phonebook_comments(Context, Data, []) ->
{Context, Data};
maybe_phonebook_comments(Context, Data, Comments) ->
PhonebookComments = [fix_phonebook_comments(Comment)
|| Comment <- kzd_port_requests:comments(Data, [])
],

Doc = cb_context:doc(Context),
CurrentComments = kz_json:get_value(<<"comments">>, Doc, []),
Doc1 = kz_json:set_value(<<"comments">>, CurrentComments ++ Comments, Doc),
{cb_context:set_doc(Context, Doc1), kz_json:delete_key(<<"comments">>, Data)}.
UpdatedComments = cb_comments:sort(kzd_port_requests:comments(Doc, []) ++ PhonebookComments),
Merged = kz_json:merge([kz_json:delete_key(<<"comments">>, Doc)
,kz_json:delete_key(<<"comments">>, Data)
]
),

cb_context:set_doc(Context, kzd_port_requests:set_comments(Merged, UpdatedComments)).

-spec fix_phonebook_comments(kz_json:object()) -> kz_json:object().
fix_phonebook_comments(Comment) ->
Setters = [{fun kzd_comment:set_action_required/2, kzd_comment:action_required(Comment, 'false')}
,{fun kzd_comment:set_author/2, kzd_comment:author(Comment, <<"phonebook">>)}
,{fun kzd_comment:set_content/2, kzd_comment:content(Comment, <<"phonebook comment">>)}
,{fun kzd_comment:set_is_private/2, kzd_comment:is_private(Comment, 'false')}
,{fun kzd_comment:set_timestamp/2, kzd_comment:timestamp(Comment, kz_time:now_s())}
],
kz_doc:setters(Comment, Setters).

%%%=============================================================================
%%% Internal functions
Expand Down Expand Up @@ -635,7 +644,7 @@ patch_then_validate_then_maybe_transition(Context, PortId, ToState) ->
validate_port_comments(Context, OnSuccess) ->
validate_port_comments(Context, OnSuccess, get_new_comments(Context)).

-spec validate_port_comments(cb_context:context(), fun((cb_context:context()) -> cb_context:context()), kz_json:objects()) -> cb_context:context().
-spec validate_port_comments(cb_context:context(), fun((cb_context:context()) -> cb_context:context()), kz_json:ojbects()) -> cb_context:context().
validate_port_comments(Context, OnSuccess, []) ->
Doc = cb_context:doc(Context),
Comments = kzd_port_requests:comments(Doc, []),
Expand Down Expand Up @@ -1461,7 +1470,8 @@ send_port_comment_notifications(Context, Id, NewComments) ->
_ = lists:foldl(fun send_port_comment_notification/2, {Context, Id, length(NewComments), 1}, NewComments),
'ok'.

-spec send_port_comment_notification(kz_json:object(), {cb_context:context(), kz_term:ne_binary(), non_neg_integer(), non_neg_integer()}) -> 'ok'.
-spec send_port_comment_notification(kz_json:object(), {cb_context:context(), kz_term:ne_binary(), non_neg_integer(), non_neg_integer()}) ->
{cb_context:context(), kz_term:ne_binary(), non_neg_integer(), non_neg_integer()}.
send_port_comment_notification(NewComment, {Context, Id, TotalNew, Index}) ->
Setters = [{fun kzd_comment:set_user_id/2, kzd_comment:user_id(NewComment, cb_context:auth_user_id(Context))}
,{fun kzd_comment:set_account_id/2, kzd_comment:account_id(NewComment, cb_context:auth_account_id(Context))}
Expand All @@ -1475,10 +1485,13 @@ send_port_comment_notification(NewComment, {Context, Id, TotalNew, Index}) ->
],
lager:debug("sending port comment notification ~b/~b", [Index, TotalNew]),
try kapps_notify_publisher:cast(Req, fun kapi_notifications:publish_port_comment/1) of
_ -> lager:debug("port comment notification sent ~b/~b", [Index, TotalNew])
_ ->
lager:debug("port comment notification sent ~b/~b", [Index, TotalNew]),
{Context, Id, TotalNew, Index+1}
catch
_E:_R ->
lager:error("failed to send the port comment notification ~b/~b: ~s:~p", [Index, TotalNew, _E, _R])
lager:error("failed to send the port comment notification ~b/~b: ~s:~p", [Index, TotalNew, _E, _R]),
{Context, Id, TotalNew, Index+1}
end.

%%------------------------------------------------------------------------------
Expand Down Expand Up @@ -1545,8 +1558,7 @@ authority_type(Context, Nouns) ->
Accounts = props:get_value(<<"accounts">>, Nouns),
authority_type(Context, Nouns, Accounts).

-spec authority_type(cb_context:context(), req_nouns(), path_tokens() | 'undefined') ->
{authority_type(), kz_term:ne_binary()}.
-spec authority_type(cb_context:context(), req_nouns(), path_tokens() | 'undefined') -> {authority_type(), kz_term:ne_binary()}.
authority_type(Context, _Nouns, 'undefined') ->
{'agent', cb_context:auth_account_id(Context)};
authority_type(Context, _Nouns, [_AccountId, ?DESCENDANTS]) ->
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
<b>-&nbsp;&nbsp;&nbsp;State:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_state}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.id}}</span><br>{% if port_request.port_scheduled_date %}
<b>-&nbsp;&nbsp;&nbsp;Scheduled Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}})</span><br>{% elif port_request.requested_port_date %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Numbers:</b><br><span style="font-family:monospace;">{{ port_request.numbers|join:", " }}</span>
</p>
</td>
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_cancel.text
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Port Request Information
State: {{port_request.port_state}}
ID: {{port_request.id}}{% if port_request.port_scheduled_date %}
Scheduled Date: {{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}}){% elif port_request.requested_port_date %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Numbers: {{ port_request.numbers|join:", "|stringformat:"s"|wordwrap:40 }}


Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_pending.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
<b>-&nbsp;&nbsp;&nbsp;State:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_state}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.id}}</span><br>{% if port_request.port_scheduled_date %}
<b>-&nbsp;&nbsp;&nbsp;Scheduled Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}})</span><br>{% elif port_request.requested_port_date %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Numbers:</b><br><span style="font-family:monospace;">{{ port_request.numbers|join:", " }}</span>
</p>
</td>
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_pending.text
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Port Request Information
State: {{port_request.port_state}}
ID: {{port_request.id}}{% if port_request.port_scheduled_date %}
Scheduled Date: {{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}}){% elif port_request.requested_port_date %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Numbers: {{ port_request.numbers|join:", "|stringformat:"s"|wordwrap:40 }}


Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_rejected.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
<b>-&nbsp;&nbsp;&nbsp;State:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_state}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.id}}</span><br>{% if port_request.port_scheduled_date %}
<b>-&nbsp;&nbsp;&nbsp;Scheduled Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}})</span><br>{% elif port_request.requested_port_date %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Numbers:</b><br><span style="font-family:monospace;">{{ port_request.numbers|join:", " }}</span>
</p>
</td>
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_rejected.text
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Port Request Information
State: {{port_request.port_state}}
ID: {{port_request.id}}{% if port_request.port_scheduled_date %}
Scheduled Date: {{port_request.port_scheduled_date.local|date:"l, F j, Y h:i A"}} ({{port_request.port_scheduled_date.timezone}}){% elif port_request.requested_port_date %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Numbers: {{ port_request.numbers|join:", "|stringformat:"s"|wordwrap:40 }}


Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
<b>-&nbsp;&nbsp;&nbsp;Name:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.name}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;State:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.port_state}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.id}}</span><br>{% if port_request.requested_port_date %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Requested Transfer Date:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}})</span><br>{% endif %}
<b>-&nbsp;&nbsp;&nbsp;Numbers:</b><br><span style="font-family:monospace;">{{ port_request.numbers|join:", " }}</span>
</p>
</td>
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/priv/templates/port_request.text
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Port Request Information
Name: {{port_request.name}}
State: {{port_request.port_state}}
ID: {{port_request.id}}{% if port_request.requested_port_date %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Requested Transfer Date: {{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% endif %}
Numbers: {{ port_request.numbers|join:", "|stringformat:"s"|wordwrap:40 }}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h3 style="margin:0;padding:0;font-family:'Open Sans',sans-serif;color:#555555;f
</tr>
<tr>
<td style="padding:10px;background-color:#f5f5f5;text-align:right;font-family:'Open Sans',sans-serif;color:#555555;font-size:13px;font-weight:400;line-height:20px;border-size:3px;border-color:#ffffff;border-right-style:solid;border-bottom-style:solid;" width="30%"><b>Requested Port Date</b></td>
<td style="padding:10px;background-color:#eaeaea;font-size:13px;font-family:'Open Sans',sans-serif;color:#555555;line-height:20px;border-size:3px;border-color:#ffffff;border-bottom-style:solid;" width="70%">{% if port_request.requested_port_date %}{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% else %}not scheduled yet{% endif %}</td>
<td style="padding:10px;background-color:#eaeaea;font-size:13px;font-family:'Open Sans',sans-serif;color:#555555;line-height:20px;border-size:3px;border-color:#ffffff;border-bottom-style:solid;" width="70%">{% if port_request.requested_port_date %}{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% else %}not scheduled yet{% endif %}</td>
</tr>
<tr>
<td style="padding:10px;background-color:#f5f5f5;text-align:right;font-family:'Open Sans',sans-serif;color:#555555;font-size:13px;font-weight:400;line-height:20px;border-size:3px;border-color:#ffffff;border-right-style:solid;border-bottom-style:solid;" width="30%"><b>Losing Carrier</b></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Request "{{port_request.name}}" to port numbers into account '{{account.name}}'
Port ID: {{port_request.id}}
State: {{port_request.port_state}}
Numbers: Numbers: {{ port_request.numbers|join:", "|stringformat:"s"|wordwrap:40 }}
Requested Port Date: {% if port_request.requested_port_date %}{{port_request.requested_port_date.local|date:"l, F j, Y h:i A"}} ({{port_request.requested_port_date.timezone}}){% else %}not scheduled yet{% endif %}
Requested Port Date: {% if port_request.requested_port_date %}{{port_request.requested_port_date.local|date:"l, F j, Y"}} ({{port_request.requested_port_date.timezone}}){% else %}not scheduled yet{% endif %}
Losing Carrier: {{port_request.losing_carrier}}
Winning Carrier: {{port_request.winning_carrier}}
Carrier Reference Number: {{port_request.reference_number}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</tr>
<tr>
<td style="padding:10px;background-color:#f5f5f5;text-align:right;font-family:'Open Sans',sans-serif;color:#555555;font-size:13px;font-weight:400;line-height:20px;border-size:3px;border-color:#ffffff;border-right-style:solid;border-bottom-style:solid;" width="30%"><b>Requested Port Date</b></td>
<td style="padding:10px;background-color:#eaeaea;font-size:13px;font-family:'Open Sans',sans-serif;color:#555555;line-height:20px;border-size:3px;border-color:#ffffff;border-bottom-style:solid;" width="70%">{{port_request.requested_port_date.local|date:"l, F j, Y H:i"}}</td>
<td style="padding:10px;background-color:#eaeaea;font-size:13px;font-family:'Open Sans',sans-serif;color:#555555;line-height:20px;border-size:3px;border-color:#ffffff;border-bottom-style:solid;" width="70%">{{port_request.requested_port_date.local|date:"l, F j, Y"}}</td>
</tr>
<tr>
<td style="padding:10px;background-color:#f5f5f5;text-align:right;font-family:'Open Sans',sans-serif;color:#555555;font-size:13px;font-weight:400;line-height:20px;border-size:3px;border-color:#ffffff;border-right-style:solid;border-bottom-style:solid;" width="30%"><b>Service Provider</b></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Request "{{port_request.name}}" to port numbers into account '{{account.name}}'
Name: {{port_request.name}}
Port ID: {{port_request.id}}
State: {{port_request.state}}
Requested Port Date: {{port_request.requested_port_date.local|date:"l, F j, Y H:i"}}
Requested Port Date: {{port_request.requested_port_date.local|date:"l, F j, Y"}}
Service Provider: {{port_request.service_provider}}
Customer Contact: {{port_request.customer_contact}}
Billing Name: {{port_request.billing_name}}
Expand Down

0 comments on commit 425d56d

Please sign in to comment.