Skip to content

Commit

Permalink
show which account is changed (2600hz#5445)
Browse files Browse the repository at this point in the history
  • Loading branch information
icehess authored and k-anderson committed Jan 23, 2019
1 parent e9f3ab7 commit 18572f9
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 56 deletions.
22 changes: 19 additions & 3 deletions applications/teletype/priv/templates/service_added.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="x-apple-disable-message-reformatting">
<title>Service change invoice for account '{{affected.name}}'</title>
<title>Service change invoice for account '{% firstof cascade.name affected.name %}'</title>
<!--[if !mso]><link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'><![endif]-->
<style>
/* CSS Reset */
Expand All @@ -18,7 +18,7 @@
<body width="100%" bgcolor="#eaeaea" style="margin:0;mso-line-height-rule:exactly;background-color:#eaeaea">
<center style="padding:40px 0;width:100%;background:#eaeaea;text-align:left;">
<div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family:sans-serif;">
Invoice for changes to VoIP services in '{{affected.name}}' -
Invoice for changes to VoIP services in '{% firstof cascade.name affected.name %}' -
</div>
<div style="max-width:600px; margin:auto;" class="email-container">
<!--[if mso]>
Expand All @@ -43,7 +43,7 @@ <h2 style="margin:0;padding:0;text-align:center;font-family:'Open Sans',sans-ser
</tr>
<tr>
<td bgcolor="#ffffff" style="padding:20px;font-family:'Open Sans',sans-serif;color:#555555;">
<p style="margin-top:0;font-family:'Open Sans',sans-serif;color:#555555;">There have been some changes to your VoIP services in account <b>{{affected.name}}</b>.</p>
<p style="margin-top:0;font-family:'Open Sans',sans-serif;color:#555555;">There have been some changes to your VoIP services in account <b>{% firstof cascade.name affected.name %}</b>.</p>
<p style="font-family:'Open Sans',sans-serif;color:#555555;">Here is the invoice based on the service plan applied to your account. Your account will be billed at the start of each month.</p>
</td>
</tr>
Expand Down Expand Up @@ -128,6 +128,22 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
</td>
</tr>
</table>
{% if cascade %}
<table role="presentation" cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="border-color:#dedede;border-width:1px;border-left-style:solid;border-right-style:solid;max-width:600px;">
<tr>
<td bgcolor="#e2e2e2" style="padding:0 20px;background-color:#e2e2e2;color:#555555;border-bottom:2px solid #ffffff">
<h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans',sans-serif;color:#555555;">Cascade Account Information</h4>
<p style="margin:13px;padding:0;font-family:'Open Sans',sans-serif;color:#555555;font-size:11px;line-height:18px;">
Changes to your services is result of the changes to this account:
<p style="margin:13px;padding:0;font-family:'Open Sans',sans-serif;color:#555555;font-size:11px;line-height:18px;">
<b>-&nbsp;&nbsp;&nbsp;Account ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{cascade.id}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;Account Name:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{cascade.name}}</span><br>
<b>-&nbsp;&nbsp;&nbsp;Account Realm:</b>&nbsp;&nbsp;<span style="font-family:monospace;">{{cascade.realm}}</span>
</p>
</td>
</tr>
</table>
{% endif %}
<!-- Email Footer -->
<table role="presentation" cellspacing="0" cellpadding="0" border="0" bgcolor="#202029" align="center" width="100%" style="background-color:#202029;border-color:#202029;border-width:1px;border-left-style:solid;border-right-style:solid;max-width:600px;">
<tr><td style="font-size:50px;line-height:50px;" height="50">&nbsp;</td></tr>
Expand Down
13 changes: 11 additions & 2 deletions applications/teletype/priv/templates/service_added.text
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Date: {{ timestamp.local | date:"l, F j, Y H:i" }}

There have been some changes to your VoIP services in account {{affected.name}}.
There have been some changes to your VoIP services in account {% firstof cascade.name affected.name %}.

Here is the invoice based on the service plan applied to your account. Your account
will be billed at the start of each month.
Expand Down Expand Up @@ -43,7 +43,16 @@ Thank you for your business!

Account ID: {{affected.id}}
Account Name: {{affected.name}}
Account Realm: {{affected.realm}}
Account Realm: {{affected.realm}}{% if cascade %}

Cascade Account Information
Changes to your services is result of the changes to this account:

Account ID: {{cascade.id}}
Account Name: {{cascade.name}}
Account Realm: {{cascade.realm}}

{% endif %}



Expand Down
58 changes: 46 additions & 12 deletions applications/teletype/src/templates/teletype_service_added.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ macros() ->
,?MACRO_VALUE(<<"affected.realm">>, <<"affected_realm">>, <<"Affected Account Realm">>, <<"Affected Account Realm">>)
,?MACRO_VALUE(<<"affected.language">>, <<"affected_language">>, <<"Affected Account Language">>, <<"Affected Account Language">>)
,?MACRO_VALUE(<<"affected.timezone">>, <<"affected_timezone">>, <<"Affected Account Timezone">>, <<"Affected Account Timezone">>)
,?MACRO_VALUE(<<"authentication.type">>, <<"authentication_type">>, <<"Authentication Type">>, <<"Type of authentication used by user">>)
,?MACRO_VALUE(<<"authentication.account_id">>, <<"authentication_account_id">>, <<"Authentication Account ID">>, <<"Account ID of authentication">>)
,?MACRO_VALUE(<<"authentication.account_name">>, <<"authentication_account_name">>, <<"Authentication Account Name">>, <<"Account name of authentication">>)
,?MACRO_VALUE(<<"cascade.id">>, <<"cascade_id">>, <<"cascade Account ID">>, <<"Changes cascaded from Account ID">>)
,?MACRO_VALUE(<<"cascade.name">>, <<"cascade_name">>, <<"cascade Account Name">>, <<"Changes cascaded from Account Name">>)
,?MACRO_VALUE(<<"cascade.realm">>, <<"cascade_realm">>, <<"cascade Account Realm">>, <<"Changes cascaded from Account Realm">>)
,?MACRO_VALUE(<<"cascade.language">>, <<"cascade_language">>, <<"cascade Account Language">>, <<"Changes cascaded from Account Language">>)
,?MACRO_VALUE(<<"cascade.timezone">>, <<"cascade_timezone">>, <<"cascade Account Timezone">>, <<"Changes cascaded from Timezone">>)
,?MACRO_VALUE(<<"invoice.items.[item_name].category">>, <<"invoice_item_category">>, <<"Invoice Item Category">>, <<"Ccategory name that the item belongs to">>)
,?MACRO_VALUE(<<"invoice.items.[item_name].changes.type">>, <<"invoice_item_change_type">>, <<"Invoice Item Change Type">>, <<"The type of change to the item">>)
,?MACRO_VALUE(<<"invoice.items.[item_name].changes.quantity">>, <<"invoice_item_change_quantity">>, <<"Invoice Item Change Quantity">>, <<"Quantity amount affected the item">>)
Expand Down Expand Up @@ -105,7 +113,7 @@ maybe_handle_req(DataJObj, 'false') ->

-spec process_req(kz_json:object()) -> template_response().
process_req(DataJObj) ->
Macros = macros(DataJObj),
Macros = props:filter_undefined(macros(DataJObj)),

%% Load templates
RenderedTemplates = teletype_templates:render(id(), Macros, DataJObj),
Expand Down Expand Up @@ -135,15 +143,23 @@ macros(DataJObj, 'true') ->
,{<<"language">>, kzd_accounts:language(AccountJObj)}
,{<<"timezone">>, kzd_accounts:timezone(AccountJObj)}
],
Auth = [{<<"type">>, <<"x-auth-token">>}
,{<<"account_id">>, kz_doc:id(AccountJObj)}
,{<<"account_name">>, kzd_accounts:name(AccountJObj)}
],
Request = [{<<"id">>, <<"qweasdzxc123456">>}
,{<<"client_ip">>, <<"192.168.0.1">>}
,{<<"method">>, <<"PUT">>}
,{<<"path">>, <<"/v2/accounts/example_account_id/">>}
],
{'ok', UserJObj} = teletype_util:read_preview_doc(<<"user">>),
[{<<"account">>, Account} %% backward compatibility
,{<<"affected">>, Account}
[{<<"affected">>, Account}
,{<<"authentication">>, Auth}
,{<<"cascade">>, Account}
,{<<"invoice">>, kz_json:recursive_to_proplist(Invoice)}
,{<<"reseller">>, Account}
,{<<"service_changes">>, kz_json:recursive_to_proplist(Invoice)} %% backward compatibility
,{<<"sub_account">>, Account} %% backward compatibility
,{<<"request">>, Request}
,{<<"system">>, teletype_util:system_params()}
,{<<"time_stamp">>, teletype_util:fix_timestamp(kz_time:now_s(), DataJObj)} %% backward compatibility
,{<<"timestamp">>, teletype_util:fix_timestamp(kz_time:now_s(), DataJObj)}
,{<<"user">>, teletype_util:user_params(UserJObj)}
];
Expand All @@ -152,14 +168,14 @@ macros(DataJObj, 'false') ->
Invoice = invoice_data(DataJObj),
Reseller = reseller_info_data(DataJObj),
Affected = affected_account_data(DataJObj),
[{<<"account">>, Reseller} %% backward compatibility
,{<<"affected">>, Affected}
Cascade = cascade_account_data(DataJObj, Affected),
[{<<"affected">>, Affected}
,{<<"authentication">>, authentication_data(DataJObj)}
,{<<"cascade">>, Cascade}
,{<<"invoice">>, Invoice}
,{<<"reseller">>, Reseller}
,{<<"service_changes">>, Invoice} %% backward compatibility
,{<<"sub_account">>, Affected} %% backward compatibility
,{<<"request">>, request_data(DataJObj)}
,{<<"system">>, teletype_util:system_params()}
,{<<"time_stamp">>, Timestamp} %% backward compatibility
,{<<"timestamp">>, Timestamp}
,{<<"user">>, agent_user_data(DataJObj)}
].
Expand All @@ -180,16 +196,34 @@ affected_account_data(DataJObj) ->
AccountId = kz_json:get_ne_binary_value(<<"account_id">>, DataJObj),
teletype_util:find_account_params(AccountId).

-spec authentication_data(kz_json:object()) -> kz_term:proplist().
authentication_data(DataJObj) ->
kz_json:to_proplist(kz_json:get_json_value([<<"audit_log">>, <<"audit">>, <<"authentication">>], DataJObj, kz_json:new())).

-spec cascade_account_data(kz_json:object(), kz_term:api_proplist()) -> kz_term:proplist().
cascade_account_data(DataJObj, Affected) ->
AffectedId = props:get_ne_binary_value(<<"id">>, Affected),
AccountId = kz_json:get_ne_binary_value([<<"audit_log">>, <<"audit">>, <<"changes">>, <<"account_id">>], DataJObj),
case AffectedId =:= AccountId of
'true' -> 'undefined';
'false' ->
teletype_util:find_account_params(AccountId)
end.

-spec agent_user_data(kz_json:object()) -> kz_term:proplist().
agent_user_data(DataJObj) ->
AgentJObj = kz_json:get_json_value([<<"audit_log">>, <<"agent">>], DataJObj, kz_json:new()),
AgentJObj = kz_json:get_json_value([<<"audit_log">>, <<"audit">>, <<"agent">>], DataJObj, kz_json:new()),
AccountId = kz_json:get_ne_binary_value(<<"account_id">>, AgentJObj),
UserId = kz_json:get_ne_binary_value(<<"type_id">>, AgentJObj),
case kzd_user:fetch(AccountId, UserId) of
{'ok', UserJObj} -> teletype_util:user_params(UserJObj);
{'error', _} -> []
end.

-spec request_data(kz_json:object()) -> kz_term:proplist().
request_data(DataJObj) ->
kz_json:to_proplist(kz_json:get_json_value([<<"audit_log">>, <<"audit">>, <<"request">>], DataJObj, kz_json:new())).

-spec invoice_data(kz_json:object()) -> kz_term:proplist().
invoice_data(DataJObj) ->
case kz_json:get_list_value(<<"items">>, DataJObj) of
Expand Down
26 changes: 21 additions & 5 deletions applications/teletype/test/rendered-templates/service_added.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="x-apple-disable-message-reformatting">
<title>Service change invoice for account 'Sub Account'</title>
<title>Service change invoice for account 'Sub-Sub Account'</title>
<!--[if !mso]><link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'><![endif]-->
<style>
/* CSS Reset */
Expand All @@ -18,7 +18,7 @@
<body width="100%" bgcolor="#eaeaea" style="margin:0;mso-line-height-rule:exactly;background-color:#eaeaea">
<center style="padding:40px 0;width:100%;background:#eaeaea;text-align:left;">
<div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family:sans-serif;">
Invoice for changes to VoIP services in 'Sub Account' -
Invoice for changes to VoIP services in 'Sub-Sub Account' -
</div>
<div style="max-width:600px; margin:auto;" class="email-container">
<!--[if mso]>
Expand All @@ -43,7 +43,7 @@ <h2 style="margin:0;padding:0;text-align:center;font-family:'Open Sans',sans-ser
</tr>
<tr>
<td bgcolor="#ffffff" style="padding:20px;font-family:'Open Sans',sans-serif;color:#555555;">
<p style="margin-top:0;font-family:'Open Sans',sans-serif;color:#555555;">There have been some changes to your VoIP services in account <b>Sub Account</b>.</p>
<p style="margin-top:0;font-family:'Open Sans',sans-serif;color:#555555;">There have been some changes to your VoIP services in account <b>Sub-Sub Account</b>.</p>
<p style="font-family:'Open Sans',sans-serif;color:#555555;">Here is the invoice based on the service plan applied to your account. Your account will be billed at the start of each month.</p>
</td>
</tr>
Expand Down Expand Up @@ -196,8 +196,8 @@ <h4 style="margin:0 0 5px;padding:0;"><small style="font-family:'Open Sans',sans
<td bgcolor="#e2e2e2" style="padding:0 20px;background-color:#e2e2e2;color:#555555;border-bottom:2px solid #ffffff">
<h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans',sans-serif;color:#555555;">Agent Information</h4>
<p style="margin:13px;padding:0;font-family:'Open Sans',sans-serif;color:#555555;font-size:11px;line-height:18px;">
<b>-&nbsp;&nbsp;&nbsp;Name:</b>&nbsp;&nbsp;<span style="font-family:monospace;">User Two</span><br>
<b>-&nbsp;&nbsp;&nbsp;Email:</b>&nbsp;&nbsp;<span style="font-family:monospace;">user-2001@2600hz.local</span><br>
<b>-&nbsp;&nbsp;&nbsp;Name:</b>&nbsp;&nbsp;<span style="font-family:monospace;">User Three</span><br>
<b>-&nbsp;&nbsp;&nbsp;Email:</b>&nbsp;&nbsp;<span style="font-family:monospace;">user-3001@2600hz.local</span><br>
</p>
</td>
</tr>
Expand All @@ -215,6 +215,22 @@ <h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans
</td>
</tr>
</table>

<table role="presentation" cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="border-color:#dedede;border-width:1px;border-left-style:solid;border-right-style:solid;max-width:600px;">
<tr>
<td bgcolor="#e2e2e2" style="padding:0 20px;background-color:#e2e2e2;color:#555555;border-bottom:2px solid #ffffff">
<h4 style="font-weight:100;line-height:20px;margin:13px 0;font-family:'Open Sans',sans-serif;color:#555555;">Cascade Account Information</h4>
<p style="margin:13px;padding:0;font-family:'Open Sans',sans-serif;color:#555555;font-size:11px;line-height:18px;">
Changes to your services is result of the changes to this account:
<p style="margin:13px;padding:0;font-family:'Open Sans',sans-serif;color:#555555;font-size:11px;line-height:18px;">
<b>-&nbsp;&nbsp;&nbsp;Account ID:</b>&nbsp;&nbsp;<span style="font-family:monospace;">account0000000000000000000000003</span><br>
<b>-&nbsp;&nbsp;&nbsp;Account Name:</b>&nbsp;&nbsp;<span style="font-family:monospace;">Sub-Sub Account</span><br>
<b>-&nbsp;&nbsp;&nbsp;Account Realm:</b>&nbsp;&nbsp;<span style="font-family:monospace;">paustu8.sip.2600hz.local</span>
</p>
</td>
</tr>
</table>

<!-- Email Footer -->
<table role="presentation" cellspacing="0" cellpadding="0" border="0" bgcolor="#202029" align="center" width="100%" style="background-color:#202029;border-color:#202029;border-width:1px;border-left-style:solid;border-right-style:solid;max-width:600px;">
<tr><td style="font-size:50px;line-height:50px;" height="50">&nbsp;</td></tr>
Expand Down
15 changes: 12 additions & 3 deletions applications/teletype/test/rendered-templates/service_added.text
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Date: Monday, July 17, 2017 10:17

There have been some changes to your VoIP services in account Sub Account.
There have been some changes to your VoIP services in account Sub-Sub Account.

Here is the invoice based on the service plan applied to your account. Your account
will be billed at the start of each month.
Expand Down Expand Up @@ -70,15 +70,24 @@ Thank you for your business!

Agent Information

Name: User Two
Email: user-2001@2600hz.local
Name: User Three
Email: user-3001@2600hz.local

Account Information

Account ID: account0000000000000000000000002
Account Name: Sub Account
Account Realm: 3237c8.sip.2600hz.local

Cascade Account Information
Changes to your services is result of the changes to this account:

Account ID: account0000000000000000000000003
Account Name: Sub-Sub Account
Account Realm: paustu8.sip.2600hz.local





Sent from 6rdR7MIUnpFLhBvGwVZO1g
60 changes: 31 additions & 29 deletions core/kazoo_amqp/test/fixtures-api/notifications/service_added.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
"App-Name": "crossbar",
"App-Version": "4.0.0",
"Audit-Log": {
"account": {
"id": "account0000000000000000000000002",
"name": "admin"
},
"agent": {
"account_id": "account0000000000000000000000002",
"first_name": "User",
"last_name": "Two",
"type": "user",
"type_id": "user0000000000000000000000000002"
},
"authentication": {
"account_id": "account0000000000000000000000002",
"account_name": "admin",
"type": "x-auth-token"
},
"changes": {
"account_id": "account0000000000000000000000002",
"account_name": "admin",
"type": [
"account"
]
},
"crossbar_request": true,
"request": {
"client_ip": "192.168.0.1",
"id": "14da1b3f58411d9324d8a7b40b516b61",
"method": "DELETE",
"path": "/v2/accounts/account0000000000000000000000002/devices/device00000000000000000000000002"
"audit": {
"account": {
"id": "account0000000000000000000000003",
"name": "admin"
},
"agent": {
"account_id": "account0000000000000000000000003",
"first_name": "User",
"last_name": "Two",
"type": "user",
"type_id": "user0000000000000000000000000003"
},
"authentication": {
"account_id": "account0000000000000000000000003",
"account_name": "admin",
"type": "x-auth-token"
},
"changes": {
"account_id": "account0000000000000000000000003",
"account_name": "admin",
"type": [
"account"
]
},
"crossbar_request": true,
"request": {
"client_ip": "192.168.0.1",
"id": "14da1b3f58411d9324d8a7b40b516b61",
"method": "DELETE",
"path": "/v2/accounts/account0000000000000000000000003/devices/device00000000000000000000000003"
}
}
},
"Event-Category": "notification",
Expand Down
Loading

0 comments on commit 18572f9

Please sign in to comment.