kaui 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/kaui/kaui.js +118 -11
  3. data/app/assets/stylesheets/kaui/common.less +91 -6
  4. data/app/assets/stylesheets/kaui/payment.less +1 -0
  5. data/app/controllers/kaui/account_children_controller.rb +1 -4
  6. data/app/controllers/kaui/accounts_controller.rb +4 -7
  7. data/app/controllers/kaui/admin_allowed_users_controller.rb +24 -7
  8. data/app/controllers/kaui/admin_tenants_controller.rb +59 -20
  9. data/app/controllers/kaui/audit_logs_controller.rb +3 -2
  10. data/app/controllers/kaui/charges_controller.rb +1 -1
  11. data/app/controllers/kaui/credits_controller.rb +1 -1
  12. data/app/controllers/kaui/home_controller.rb +273 -10
  13. data/app/controllers/kaui/invoice_items_controller.rb +1 -1
  14. data/app/controllers/kaui/invoices_controller.rb +3 -3
  15. data/app/controllers/kaui/payments_controller.rb +5 -3
  16. data/app/controllers/kaui/refunds_controller.rb +2 -2
  17. data/app/controllers/kaui/subscriptions_controller.rb +2 -1
  18. data/app/helpers/kaui/object_helper.rb +4 -0
  19. data/app/helpers/kaui/plugin_helper.rb +36 -20
  20. data/app/helpers/kaui/uuid_helper.rb +9 -0
  21. data/app/models/kaui/admin.rb +3 -1
  22. data/app/models/kaui/admin_tenant.rb +58 -10
  23. data/app/models/kaui/allowed_user.rb +1 -0
  24. data/app/models/kaui/catalog.rb +2 -2
  25. data/app/models/kaui/credit.rb +0 -2
  26. data/app/models/kaui/overdue.rb +5 -5
  27. data/app/views/kaui/account_children/index.html.erb +3 -3
  28. data/app/views/kaui/accounts/_account_info.html.erb +45 -91
  29. data/app/views/kaui/accounts/_billing_info.html.erb +12 -8
  30. data/app/views/kaui/accounts/_parent.html.erb +1 -1
  31. data/app/views/kaui/accounts/_payment_methods.html.erb +1 -1
  32. data/app/views/kaui/accounts/_personal_info.html.erb +74 -0
  33. data/app/views/kaui/accounts/index.html.erb +4 -4
  34. data/app/views/kaui/accounts/show.html.erb +9 -3
  35. data/app/views/kaui/admin_allowed_users/_form.html.erb +38 -10
  36. data/app/views/kaui/admin_tenants/_form_plugin_config.erb +82 -17
  37. data/app/views/kaui/admin_tenants/_show_catalog_simple.erb +11 -3
  38. data/app/views/kaui/admin_tenants/_show_overdue.erb +4 -4
  39. data/app/views/kaui/admin_tenants/_tenant_details.html.erb +7 -1
  40. data/app/views/kaui/admin_tenants/new_overdue_config.html.erb +1 -1
  41. data/app/views/kaui/audit_logs/_show_history_modal.html.erb +1 -1
  42. data/app/views/kaui/audit_logs/index.html.erb +4 -0
  43. data/app/views/kaui/home/_advanced_search_modal.html.erb +80 -0
  44. data/app/views/kaui/home/index.html.erb +18 -5
  45. data/app/views/kaui/invoices/show.html.erb +7 -1
  46. data/app/views/kaui/layouts/kaui_flash.html.erb +14 -3
  47. data/app/views/kaui/layouts/kaui_navbar.html.erb +11 -9
  48. data/app/views/kaui/payments/_form.html.erb +8 -10
  49. data/app/views/kaui/payments/_payment_table.html.erb +40 -37
  50. data/app/views/kaui/payments/index.html.erb +1 -0
  51. data/app/views/kaui/payments/show.html.erb +5 -7
  52. data/app/views/kaui/queues/index.html.erb +22 -4
  53. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +1 -1
  54. data/app/views/kaui/tag_definitions/index.html.erb +1 -1
  55. data/config/routes.rb +2 -0
  56. data/lib/kaui/version.rb +1 -1
  57. data/test/functional/kaui/accounts_controller_test.rb +35 -0
  58. data/test/functional/kaui/admin_allowed_users_controller_test.rb +55 -2
  59. data/test/functional/kaui/admin_tenants_controller_test.rb +67 -6
  60. data/test/functional/kaui/home_controller_test.rb +389 -15
  61. data/test/functional/kaui/subscriptions_controller_test.rb +1 -1
  62. data/test/killbill_test_helper.rb +2 -2
  63. data/test/unit/helpers/kaui/uuid_helper_test.rb +16 -0
  64. data/test/unit/kaui/admin_tenant_test.rb +49 -0
  65. metadata +6 -4
  66. data/test/unit/kaui/uuid_helper_test.rb +0 -10
@@ -6,5 +6,14 @@ module Kaui
6
6
  split = uuid.split('-')
7
7
  split[0] + '-...-' + split[4]
8
8
  end
9
+
10
+ def object_id_popover(object_id, placement = 'right', title = nil)
11
+ content_tag(:span, truncate_uuid(object_id),
12
+ id: "#{object_id}-popover", class: 'object-id-popover', title: title,
13
+ data: {
14
+ id: object_id,
15
+ placement: placement,
16
+ } )
17
+ end
9
18
  end
10
19
  end
@@ -15,7 +15,9 @@ class Kaui::Admin < KillBillClient::Model::Resource
15
15
  :minDate => options[:minDate],
16
16
  :maxDate => options[:maxDate]
17
17
  },
18
- options
18
+ {
19
+ :accept => 'application/octet-stream'
20
+ }.merge(options)
19
21
  JSON.parse res.body
20
22
  end
21
23
 
@@ -63,19 +63,23 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
63
63
 
64
64
  # Extract killbill key for oss plugins based on convention 'killbill-KEY'
65
65
  plugin_key = killbill_key.gsub(/killbill-/, '') if killbill_key.start_with?('killbill-')
66
+
66
67
  # hack:: rewrite key, to allow the ui to find the right configuration inputs
67
- plugin_key = rewrite_plugin_key(plugin_key)
68
- # If such key exists, lookup in plugin directory
69
- plugin_repo_entry = plugin_directory[plugin_key.to_sym] unless plugin_key.nil?
70
- # Extract plugin_type based on plugin_directory entry if exists
71
- plugin_type = plugin_repo_entry.nil? ? :unknown : plugin_repo_entry[:type].to_sym
72
-
73
- # Deserialize config based on type
74
- if plugin_type == :ruby
68
+ plugin_key = rewrite_plugin_key(plugin_key) unless plugin_key.nil?
69
+ # If such key exists, lookup in plugin directory to see if is an official plugin
70
+ is_an_official_plugin = !plugin_key.nil? && !plugin_directory[plugin_key.to_sym].blank?
71
+ # Deserialize config based on string possible format, if exist in the official repository
72
+ if is_an_official_plugin && is_yaml?(e.values[0])
75
73
  yml = YAML.load(e.values[0])
76
74
  # Hash of properties
77
- hsh[plugin_key] = yml[plugin_key.to_sym]
78
- elsif plugin_type == :java
75
+ # is plugin key part of the yaml?
76
+ if yml[plugin_key.to_sym].blank?
77
+ # if not set it as raw
78
+ hsh[plugin_key] = {:raw_config => e.values[0]}
79
+ else
80
+ hsh[plugin_key] = yml[plugin_key.to_sym]
81
+ end
82
+ elsif is_an_official_plugin && is_kv?(e.values[0])
79
83
  # Construct hash of properties based on java properties (k1=v1\nk2=v2\n...)
80
84
  hsh[plugin_key] = e.values[0].split("\n").inject({}) do |h, p0|
81
85
  k, v = p0.split('=');
@@ -107,6 +111,7 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
107
111
  return nil unless props.present?
108
112
  if plugin_type == 'ruby'
109
113
  require 'yaml'
114
+ props = reformat_plugin_config(plugin_type, props)
110
115
  hsh = {}
111
116
  hsh[plugin_key.to_sym] = {}
112
117
  props.each do |k,v|
@@ -115,6 +120,7 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
115
120
  hsh[plugin_key.to_sym]
116
121
  hsh.to_yaml
117
122
  elsif plugin_type == 'java'
123
+ props = reformat_plugin_config(plugin_type, props)
118
124
  res = ""
119
125
  props.each do |k, v|
120
126
  res = "#{res}#{k.to_s}=#{v.to_s}\n"
@@ -125,6 +131,20 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
125
131
  end
126
132
  end
127
133
 
134
+ def reformat_plugin_config(plugin_type, props)
135
+ unless props['raw_config'].blank?
136
+ new_props = {}
137
+ props['raw_config'].split("\n").each do |p|
138
+ line = p.split('=')
139
+ new_props[line[0]] = line[1].blank? ? '' : line[1].delete("\r")
140
+ end
141
+
142
+ return new_props
143
+ end
144
+
145
+ props
146
+ end
147
+
128
148
  # hack when the plugin name after killbill is not the same as the plugin key, this mainly affects ruby plugin configuration,
129
149
  # as it use the key to retrieve the configuration.
130
150
  def rewrite_plugin_key(plugin_key)
@@ -132,9 +152,37 @@ class Kaui::AdminTenant < KillBillClient::Model::Tenant
132
152
  'paypal_express'
133
153
  elsif plugin_key.start_with?('firstdata')
134
154
  'firstdata_e4'
155
+ elsif plugin_key.start_with?('bridge')
156
+ 'payment_bridge'
157
+ elsif plugin_key.start_with?('payu-latam')
158
+ 'payu_latam'
135
159
  else
136
160
  "#{plugin_key}"
137
161
  end
138
162
  end
163
+
164
+ # checks if string could be parse as yaml
165
+ def is_yaml?(candidate_string)
166
+ is_yaml = false
167
+ return is_yaml if candidate_string.blank?
168
+
169
+ begin
170
+ is_yaml = !!YAML::load(candidate_string)
171
+ is_yaml = is_yaml && YAML.load(candidate_string).instance_of?(Hash)
172
+ rescue
173
+ is_yaml = false
174
+ end
175
+
176
+ is_yaml
177
+ end
178
+
179
+ # checks if string could be parse as key value pair
180
+ def is_kv?(candidate_string)
181
+ return false if candidate_string.blank? || is_yaml?(candidate_string)
182
+ lines = candidate_string.split("\n")
183
+ return false if lines.blank?
184
+
185
+ lines.all? { |kv| kv.split('=').count >= 1 }
186
+ end
139
187
  end
140
188
  end
@@ -30,6 +30,7 @@ module Kaui
30
30
 
31
31
  # Update the user locally and in Kill Bill (if needed)
32
32
  def update_in_kb!(password, roles, user = nil, reason = nil, comment = nil, options = {})
33
+
33
34
  user_role = KillBillClient::Model::UserRoles.new
34
35
  user_role.username = kb_username
35
36
 
@@ -6,7 +6,7 @@ class Kaui::Catalog < KillBillClient::Model::Catalog
6
6
 
7
7
  def get_catalog_json(latest, requested_date, options)
8
8
 
9
- catalogs = KillBillClient::Model::Catalog.get_tenant_catalog('json', requested_date, options)
9
+ catalogs = KillBillClient::Model::Catalog.get_tenant_catalog_json(requested_date, options)
10
10
  return catalogs.length > 0 ? catalogs[catalogs.length - 1] : nil if latest
11
11
 
12
12
  # Order by latest
@@ -38,7 +38,7 @@ class Kaui::Catalog < KillBillClient::Model::Catalog
38
38
 
39
39
  def get_catalog_xml(requested_date, options)
40
40
 
41
- catalog_xml = KillBillClient::Model::Catalog.get_tenant_catalog('xml', requested_date, options)
41
+ catalog_xml = KillBillClient::Model::Catalog.get_tenant_catalog_xml(requested_date, options)
42
42
 
43
43
  parsed_catalog = parse_catalog_xml(catalog_xml)
44
44
 
@@ -1,5 +1,3 @@
1
1
  class Kaui::Credit < KillBillClient::Model::Credit
2
2
 
3
- # See https://github.com/killbill/killbill/issues/262
4
- attr_accessor :currency
5
3
  end
@@ -14,12 +14,12 @@ class Kaui::Overdue < KillBillClient::Model::Overdue
14
14
  state.auto_reevaluation_interval_days = nil
15
15
  state.external_message = state_model["external_message"]
16
16
  state.is_clear_state = state_model["is_clear_state"].nil? ? false : state_model["is_clear_state"]
17
- state.block_changes = state_model["block_changes"]
17
+ state.is_block_changes = state_model["is_block_changes"]
18
18
  if state_model["subscription_cancellation_policy"] == :NONE.to_s
19
- state.disable_entitlement = false
19
+ state.is_disable_entitlement = false
20
20
  state.subscription_cancellation_policy = nil
21
21
  else
22
- state.disable_entitlement = true
22
+ state.is_disable_entitlement = true
23
23
  state.subscription_cancellation_policy = state_model["subscription_cancellation_policy"].blank? ? :NONE : state_model["subscription_cancellation_policy"].to_s.gsub!(/POLICY_/, '')
24
24
  end
25
25
 
@@ -45,7 +45,7 @@ class Kaui::Overdue < KillBillClient::Model::Overdue
45
45
  end
46
46
 
47
47
  def get_overdue_json(options)
48
- result = KillBillClient::Model::Overdue.get_tenant_overdue_config('json', options)
48
+ result = KillBillClient::Model::Overdue.get_tenant_overdue_config_json(options)
49
49
  class << result
50
50
  attr_accessor :has_states
51
51
  end
@@ -55,7 +55,7 @@ class Kaui::Overdue < KillBillClient::Model::Overdue
55
55
  class << state
56
56
  attr_accessor :subscription_cancellation
57
57
  end
58
- if state.disable_entitlement
58
+ if state.is_disable_entitlement
59
59
  state.subscription_cancellation = state.subscription_cancellation_policy ? "POLICY_#{state.subscription_cancellation_policy}".to_sym : :NONE
60
60
  else
61
61
  state.subscription_cancellation = :NONE
@@ -7,12 +7,9 @@
7
7
  <table id="account-children-table" class="table table-condensed mobile-data">
8
8
  <thead>
9
9
  <tr>
10
- <th>Name</th>
11
10
  <th>ID</th>
12
11
  <th>External key</th>
13
12
  <th>Balance</th>
14
- <th>City</th>
15
- <th>Country</th>
16
13
  </tr>
17
14
  </thead>
18
15
  <tbody>
@@ -41,6 +38,9 @@ $(document).ready(function() {
41
38
  "infoCallback": function( settings, start, end, max, total, pre ) {
42
39
 
43
40
  return pre.replace('TOTAL',settings.json.data.length);
41
+ },
42
+ drawCallback: function() {
43
+ setObjectIdPopover();
44
44
  }
45
45
  });
46
46
  });
@@ -1,4 +1,4 @@
1
- <div class="col-md-12">
1
+ <div class="col-md-6 col-xs-12">
2
2
 
3
3
  <div class="column-block">
4
4
 
@@ -39,106 +39,60 @@
39
39
 
40
40
  <div class="tag-bar tag-bar-breathe">
41
41
 
42
- <div class="tag-select" onclick="void(0)">
43
- <span><i class="fa fa-tag"></i><i class="fa fa-caret-down"></i></span>
42
+ <% unless @available_tags.blank? %>
43
+ <div class="tag-select" onclick="void(0)">
44
+ <span><i class="fa fa-tag"></i><i class="fa fa-caret-down"></i></span>
44
45
 
45
- <div class="tag-select-box">
46
- <strong>Tag As:</strong>
47
- <%= render :partial => 'kaui/account_tags/form_bar',
48
- :locals => {:account_id => @account.account_id,
49
- :tag_names => @tags.map { |tag| tag.tag_definition_name },
50
- :available_tags => @available_tags} %>
46
+ <div class="tag-select-box">
47
+ <strong>Tag As:</strong>
48
+ <%= render :partial => 'kaui/account_tags/form_bar',
49
+ :locals => {:account_id => @account.account_id,
50
+ :tag_names => @tags.map { |tag| tag.tag_definition_name },
51
+ :available_tags => @available_tags} %>
52
+ </div>
51
53
  </div>
52
- </div>
54
+ <% end %>
53
55
 
54
56
  <%= render :partial => 'kaui/custom_fields/list_bar',
55
57
  :locals => {:custom_fields => @custom_fields} %>
56
58
  </div>
57
59
 
58
60
  <div class="row">
59
- <div class="col-md-5">
61
+ <div class="col-sm-12">
60
62
  <div class="fix-position">
61
- <table class="transparent">
62
- <tr>
63
- <th>Name</th>
64
- <td><%= @account.name %></td>
65
- </tr>
66
- <tr>
67
- <th>ID</th>
68
- <td><%= @account.account_id %></td>
69
- </tr>
70
- <tr>
71
- <th>External Key</th>
72
- <td><%= @account.external_key %></td>
73
- </tr>
74
- <tr>
75
- <th>Currency</th>
76
- <td><%= @account.currency %></td>
77
- </tr>
78
- <tr>
79
- <th>Timezone</th>
80
- <td><%= @account.time_zone %></td>
81
- </tr>
82
- <tr>
83
- <th>Locale</th>
84
- <td><%= @account.locale %></td>
85
- </tr>
86
- <tr>
87
- <th>Notes</th>
88
- <% if @account.notes %>
89
- <td><textarea rows="3" class="form-control" readonly="true"><%= @account.notes %></textarea></td>
90
- <% else %>
91
- <td>N/A</td>
92
- <% end %>
93
- </tr>
94
- <%= render :partial => 'parent',
95
- :locals => {:account_parent => @account_parent} %>
96
- </table>
97
- </div>
63
+ <table class="transparent">
64
+ <tr>
65
+ <th>ID</th>
66
+ <td><%= @account.account_id %></td>
67
+ </tr>
68
+ <tr>
69
+ <th>External Key</th>
70
+ <td><%= @account.external_key %></td>
71
+ </tr>
72
+ <tr>
73
+ <th>Currency</th>
74
+ <td><%= @account.currency %></td>
75
+ </tr>
76
+ <tr>
77
+ <th>Timezone</th>
78
+ <td><%= @account.time_zone %></td>
79
+ </tr>
80
+ <tr>
81
+ <th>Locale</th>
82
+ <td><%= @account.locale %></td>
83
+ </tr>
84
+ <tr>
85
+ <th>Notes</th>
86
+ <% if @account.notes %>
87
+ <td><textarea rows="3" class="form-control" readonly="true"><%= @account.notes %></textarea></td>
88
+ <% else %>
89
+ <td>N/A</td>
90
+ <% end %>
91
+ </tr>
92
+ <%= render :partial => 'parent',
93
+ :locals => {:account_parent => @account_parent} %>
94
+ </table>
98
95
  </div>
99
- <div class="col-md-5 col-md-offset-1">
100
- <div class="fix-position">
101
- <table class="transparent">
102
- <tr>
103
- <th>Address1</th>
104
- <td><%= @account.address1 %></td>
105
- </tr>
106
- <tr>
107
- <th>Address2</th>
108
- <td><%= @account.address2 %></td>
109
- </tr>
110
- <tr>
111
- <th>City</th>
112
- <td><%= @account.city %></td>
113
- </tr>
114
- <tr>
115
- <th>State</th>
116
- <td><%= @account.state %></td>
117
- </tr>
118
- <tr>
119
- <th>Country</th>
120
- <td><%= @account.country %></td>
121
- </tr>
122
- <tr>
123
- <th>Postal Code</th>
124
- <td><%= @account.postal_code %></td>
125
- </tr>
126
- <tr>
127
- <th>Phone</th>
128
- <td><%= @account.phone %></td>
129
- </tr>
130
- <tr>
131
- <th>Company</th>
132
- <td><%= @account.company %></td>
133
- </tr>
134
- <tr>
135
- <th>Primary email</th>
136
- <td><%= @account.email %></td>
137
- </tr>
138
- <%= render :partial => 'kaui/account_emails/account_emails_table',
139
- :locals => {:account_emails => @account_emails} %>
140
- </table>
141
- </div>
142
96
  </div>
143
97
  </div>
144
98
 
@@ -1,4 +1,4 @@
1
- <div class="col-md-6">
1
+ <div class="col-md-6 col-xs-12">
2
2
 
3
3
  <div class="column-block">
4
4
 
@@ -32,6 +32,7 @@
32
32
  <% end %>
33
33
 
34
34
  <div class="row">
35
+ <div class="col-sm-12">
35
36
  <div class="fix-position">
36
37
  <table class="transparent" <%= billing_info_margin.html_safe %>>
37
38
  <tr>
@@ -63,7 +64,7 @@
63
64
  <td>
64
65
  <% if @overdue_state.nil? %>
65
66
  <span class='label'>N/A</span>
66
- <% elsif @overdue_state.clear_state %>
67
+ <% elsif @overdue_state.is_clear_state %>
67
68
  <span class='label label-success'>Good</span>
68
69
  <% else %>
69
70
  <span class='label label-danger'><%= @overdue_state.name %></span>
@@ -73,7 +74,7 @@
73
74
  <tr>
74
75
  <th>Bill cycle day</th>
75
76
  <td>
76
- <% if @account.bill_cycle_day_local %>
77
+ <% if @account.bill_cycle_day_local > 0 %>
77
78
  <span class='label'><%= @account.bill_cycle_day_local %> (user timezone)</span>
78
79
  <% else %>
79
80
  <span class='label'>N/A</span>
@@ -113,11 +114,13 @@
113
114
  <div class="col-sm-3">
114
115
  <input class="form-control" name="target_date" type="text" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-today-highlight="true">
115
116
  </div>
116
- <div style="width: 14.5%; float: left; padding: 0;">
117
- <%= label_tag :dry_run do %>
118
- <%= check_box_tag :dry_run, '1', true %>&nbsp;<small>Dry-run</small>
119
- <% end %>
120
- </div>
117
+ <% if can? :dry_run, Kaui::Invoice %>
118
+ <div style="width: 14.5%; float: left; padding: 0;">
119
+ <%= label_tag :dry_run do %>
120
+ <%= check_box_tag :dry_run, '1', true %>&nbsp;<small>Dry-run</small>
121
+ <% end %>
122
+ </div>
123
+ <% end %>
121
124
  <div class="col-xs-1" style="padding: 0;">
122
125
  <%= button_tag '<i class="fa fa-magic"></i>'.html_safe, :class => 'btn btn-xs' %>
123
126
  </div>
@@ -126,6 +129,7 @@
126
129
  </div>
127
130
  <% end %>
128
131
  </div>
132
+ </div>
129
133
  </div>
130
134
 
131
135
  </div>
@@ -2,7 +2,7 @@
2
2
  <th>Parent</th>
3
3
  <td>
4
4
  <% if account_parent.present? %>
5
- <%= link_to account_parent.name, kaui_engine.account_path(@account.parent_account_id) %>
5
+ <%= link_to account_parent.account_id, kaui_engine.account_path(@account.parent_account_id) %>
6
6
  <% if can? :update, Kaui::Account %>
7
7
  <%= link_to '&nbsp;<i class="fa fa-times"></i>'.html_safe, kaui_engine.unlink_to_parent_path(@account.account_id), :method => :delete %>
8
8
  <% end %>&nbsp;