kaui 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +51 -37
  4. data/README.md +5 -0
  5. data/Rakefile +1 -1
  6. data/app/controllers/kaui/account_emails_controller.rb +26 -44
  7. data/app/controllers/kaui/account_tags_controller.rb +26 -38
  8. data/app/controllers/kaui/account_timelines_controller.rb +47 -50
  9. data/app/controllers/kaui/accounts_controller.rb +68 -148
  10. data/app/controllers/kaui/bundle_tags_controller.rb +32 -21
  11. data/app/controllers/kaui/bundles_controller.rb +44 -69
  12. data/app/controllers/kaui/chargebacks_controller.rb +31 -61
  13. data/app/controllers/kaui/charges_controller.rb +19 -21
  14. data/app/controllers/kaui/credits_controller.rb +22 -36
  15. data/app/controllers/kaui/custom_fields_controller.rb +15 -13
  16. data/app/controllers/kaui/engine_controller.rb +8 -10
  17. data/app/controllers/kaui/invoice_items_controller.rb +24 -41
  18. data/app/controllers/kaui/invoices_controller.rb +36 -46
  19. data/app/controllers/kaui/payment_methods_controller.rb +84 -28
  20. data/app/controllers/kaui/payments_controller.rb +64 -26
  21. data/app/controllers/kaui/refunds_controller.rb +27 -107
  22. data/app/controllers/kaui/subscriptions_controller.rb +88 -132
  23. data/app/controllers/kaui/tag_definitions_controller.rb +32 -79
  24. data/app/controllers/kaui/tags_controller.rb +16 -14
  25. data/app/controllers/kaui/transactions_controller.rb +25 -0
  26. data/app/helpers/kaui/money_helper.rb +8 -0
  27. data/app/helpers/kaui/subscription_helper.rb +115 -0
  28. data/app/helpers/kaui/uuid_helper.rb +9 -0
  29. data/app/models/kaui/ability.rb +2 -2
  30. data/app/models/kaui/account.rb +25 -42
  31. data/app/models/kaui/account_email.rb +11 -48
  32. data/app/models/kaui/account_timeline.rb +1 -5
  33. data/app/models/kaui/audit_log.rb +1 -15
  34. data/app/models/kaui/base.rb +1 -126
  35. data/app/models/kaui/bundle.rb +47 -14
  36. data/app/models/kaui/catalog.rb +2 -0
  37. data/app/models/kaui/chargeback.rb +24 -36
  38. data/app/models/kaui/credit.rb +5 -20
  39. data/app/models/kaui/custom_field.rb +9 -5
  40. data/app/models/kaui/invoice.rb +9 -53
  41. data/app/models/kaui/invoice_item.rb +8 -18
  42. data/app/models/kaui/invoice_payment.rb +24 -0
  43. data/app/models/kaui/payment.rb +14 -32
  44. data/app/models/kaui/payment_method.rb +36 -0
  45. data/app/models/kaui/rails_methods.rb +7 -9
  46. data/app/models/kaui/refund.rb +5 -20
  47. data/app/models/kaui/subscription.rb +7 -27
  48. data/app/models/kaui/tag.rb +10 -6
  49. data/app/models/kaui/tag_definition.rb +26 -34
  50. data/app/models/kaui/transaction.rb +30 -0
  51. data/app/models/kaui/user.rb +2 -0
  52. data/app/views/kaui/account_emails/_form.html.erb +8 -28
  53. data/app/views/kaui/account_emails/show.html.erb +10 -10
  54. data/app/views/kaui/account_tags/_account_tags_table.html.erb +20 -18
  55. data/app/views/kaui/account_tags/_form.html.erb +42 -0
  56. data/app/views/kaui/account_tags/edit.html.erb +1 -41
  57. data/app/views/kaui/account_tags/show.html.erb +6 -3
  58. data/app/views/kaui/account_timelines/show.html.erb +273 -302
  59. data/app/views/kaui/accounts/_form.html.erb +116 -0
  60. data/app/views/kaui/accounts/index.html.erb +13 -11
  61. data/app/views/kaui/accounts/new.html.erb +5 -0
  62. data/app/views/kaui/accounts/show.html.erb +101 -99
  63. data/app/views/kaui/bundle_tags/_bundle_tags_table.html.erb +29 -9
  64. data/app/views/kaui/bundle_tags/_form.html.erb +41 -0
  65. data/app/views/kaui/bundle_tags/edit.html.erb +2 -34
  66. data/app/views/kaui/bundle_tags/show.html.erb +6 -0
  67. data/app/views/kaui/bundles/index.html.erb +9 -9
  68. data/app/views/kaui/bundles/show.html.erb +17 -15
  69. data/app/views/kaui/bundles/transfer.html.erb +25 -24
  70. data/app/views/kaui/chargebacks/_form.html.erb +44 -0
  71. data/app/views/kaui/chargebacks/new.html.erb +3 -115
  72. data/app/views/kaui/charges/_form.html.erb +73 -0
  73. data/app/views/kaui/charges/new.html.erb +2 -91
  74. data/app/views/kaui/credits/_form.html.erb +73 -0
  75. data/app/views/kaui/credits/new.html.erb +2 -85
  76. data/app/views/kaui/invoice_items/edit.html.erb +77 -78
  77. data/app/views/kaui/invoices/show.html.erb +3 -10
  78. data/app/views/kaui/layouts/kaui_application.html.erb +0 -2
  79. data/app/views/kaui/payment_methods/_form.html.erb +30 -0
  80. data/app/views/kaui/payment_methods/_new_creditcard_payment_method.html.erb +19 -18
  81. data/app/views/kaui/payment_methods/_payment_methods_table.html.erb +8 -5
  82. data/app/views/kaui/payment_methods/index.html.erb +10 -10
  83. data/app/views/kaui/payment_methods/new.html.erb +2 -20
  84. data/app/views/kaui/payment_methods/show.html.erb +2 -1
  85. data/app/views/kaui/payments/_payments_table.html.erb +30 -22
  86. data/app/views/kaui/payments/index.html.erb +1 -1
  87. data/app/views/kaui/payments/new.html.erb +5 -5
  88. data/app/views/kaui/payments/show.html.erb +3 -0
  89. data/app/views/kaui/refunds/new.html.erb +96 -104
  90. data/app/views/kaui/subscriptions/_form.html.erb +36 -0
  91. data/app/views/kaui/subscriptions/_subscriptions_table.html.erb +39 -44
  92. data/app/views/kaui/subscriptions/edit.html.erb +24 -35
  93. data/app/views/kaui/subscriptions/index.html.erb +13 -12
  94. data/app/views/kaui/subscriptions/new.html.erb +6 -43
  95. data/app/views/kaui/subscriptions/show.html.erb +32 -25
  96. data/app/views/kaui/tag_definitions/_form.html.erb +10 -37
  97. data/app/views/kaui/tag_definitions/index.html.erb +3 -5
  98. data/app/views/kaui/tag_definitions/show.html.erb +1 -2
  99. data/app/views/kaui/transactions/_form.html.erb +77 -0
  100. data/app/views/kaui/transactions/new.html.erb +3 -0
  101. data/config/initializers/kilbill-client-init.rb +1 -1
  102. data/config/routes.rb +4 -15
  103. data/kaui.gemspec +8 -6
  104. data/lib/kaui/engine.rb +4 -1
  105. data/lib/kaui/version.rb +1 -1
  106. data/lib/kaui.rb +2 -2
  107. data/test/functional/kaui/account_emails_controller_test.rb +28 -0
  108. data/test/functional/kaui/account_tags_controller_test.rb +29 -0
  109. data/test/functional/kaui/account_timelines_controller_test.rb +21 -0
  110. data/test/functional/kaui/accounts_controller_test.rb +56 -50
  111. data/test/functional/kaui/bundle_tags_controller_test.rb +29 -0
  112. data/test/functional/kaui/bundles_controller_test.rb +58 -13
  113. data/test/functional/kaui/chargebacks_controller_test.rb +16 -5
  114. data/test/functional/kaui/charges_controller_test.rb +39 -0
  115. data/test/functional/kaui/credits_controller_test.rb +35 -0
  116. data/test/functional/kaui/custom_fields_controller_test.rb +21 -0
  117. data/test/functional/kaui/functional_test_helper.rb +61 -0
  118. data/test/functional/kaui/invoice_items_controller_test.rb +24 -10
  119. data/test/functional/kaui/invoices_controller_test.rb +41 -13
  120. data/test/functional/kaui/payment_methods_controller_test.rb +49 -0
  121. data/test/functional/kaui/payments_controller_test.rb +32 -5
  122. data/test/functional/kaui/refunds_controller_test.rb +40 -5
  123. data/test/functional/kaui/subscriptions_controller_test.rb +82 -0
  124. data/test/functional/kaui/tag_definitions_controller_test.rb +27 -53
  125. data/test/functional/kaui/tags_controller_test.rb +21 -0
  126. data/test/functional/kaui/transactions_controller_test.rb +32 -0
  127. data/test/integration/kaui/integration_test_helper.rb +31 -0
  128. data/test/integration/kaui/navigation_test.rb +43 -0
  129. data/test/killbill_test_helper.rb +143 -0
  130. data/test/test_helper.rb +10 -227
  131. data/test/unit/kaui/account_email_test.rb +19 -0
  132. data/test/unit/kaui/account_test.rb +7 -35
  133. data/test/unit/kaui/base_test.rb +5 -46
  134. data/test/unit/kaui/date_helper_test.rb +6 -5
  135. data/test/unit/kaui/invoice_item_test.rb +5 -17
  136. data/test/unit/kaui/invoice_payment_test.rb +42 -0
  137. data/test/unit/kaui/invoice_test.rb +15 -15
  138. data/test/unit/kaui/money_helper_test.rb +10 -0
  139. data/test/unit/kaui/payment_test.rb +42 -0
  140. data/test/unit/kaui/tag_definition_test.rb +5 -28
  141. data/test/unit/kaui/uuid_helper_test.rb +10 -0
  142. metadata +134 -159
  143. data/app/controllers/kaui/analytics_controller.rb +0 -28
  144. data/app/helpers/kaui/killbill_helper.rb +0 -611
  145. data/app/models/kaui/analytics.rb +0 -19
  146. data/app/models/kaui/analytics_sanity.rb +0 -7
  147. data/app/models/kaui/business_account.rb +0 -12
  148. data/app/models/kaui/business_field.rb +0 -6
  149. data/app/models/kaui/business_invoice.rb +0 -31
  150. data/app/models/kaui/business_invoice_item.rb +0 -17
  151. data/app/models/kaui/business_invoice_payment.rb +0 -25
  152. data/app/models/kaui/business_overdue_status.rb +0 -8
  153. data/app/models/kaui/business_snapshot.rb +0 -9
  154. data/app/models/kaui/business_subscription_transition.rb +0 -53
  155. data/app/models/kaui/business_tag.rb +0 -5
  156. data/app/models/kaui/charge.rb +0 -14
  157. data/app/models/kaui/entitlement.rb +0 -2
  158. data/app/models/kaui/event.rb +0 -13
  159. data/app/models/kaui/external_payment.rb +0 -15
  160. data/app/models/kaui/overdue_state.rb +0 -10
  161. data/app/models/kaui/payment_attempt.rb +0 -27
  162. data/app/models/kaui/product.rb +0 -24
  163. data/app/models/kaui/time_series_data.rb +0 -8
  164. data/app/views/kaui/analytics/account_snapshot.html.erb +0 -211
  165. data/app/views/kaui/analytics/index.html.erb +0 -17
  166. data/app/views/kaui/chargebacks/index.html.erb +0 -14
  167. data/app/views/kaui/chargebacks/show.html.erb +0 -19
  168. data/app/views/kaui/credits/index.html.erb +0 -14
  169. data/app/views/kaui/credits/show.html.erb +0 -19
  170. data/app/views/kaui/invoice_items/index.html.erb +0 -20
  171. data/app/views/kaui/invoice_items/show.html.erb +0 -31
  172. data/app/views/kaui/refunds/_refunds_table.html.erb +0 -31
  173. data/app/views/kaui/refunds/index.html.erb +0 -43
  174. data/app/views/kaui/refunds/show.html.erb +0 -33
  175. data/app/views/kaui/tag_definitions/edit.html.erb +0 -3
  176. data/test/dummy/test/fixtures/accounts.yml +0 -32
  177. data/test/dummy/test/fixtures/bill_cycle_days.yml +0 -3
  178. data/test/dummy/test/fixtures/bundles.yml +0 -4
  179. data/test/dummy/test/fixtures/invoice_items.yml +0 -13
  180. data/test/dummy/test/fixtures/invoices.yml +0 -11
  181. data/test/dummy/test/fixtures/overdue_states.yml +0 -8
  182. data/test/dummy/test/fixtures/payment_methods.yml +0 -5
  183. data/test/dummy/test/fixtures/plugin_info_properties.yml +0 -59
  184. data/test/dummy/test/fixtures/plugin_infos.yml +0 -2
  185. data/test/dummy/test/fixtures/refunds.yml +0 -9
  186. data/test/dummy/test/fixtures/tag_definitions.yml +0 -20
  187. data/test/functional/kaui/account_timeline_controller_test.rb +0 -9
  188. data/test/functional/kaui/extpayments_controller_test.rb +0 -9
  189. data/test/functional/kaui/home_controller_test.rb +0 -11
  190. data/test/integration/navigation_test.rb +0 -10
  191. data/test/kaui_test.rb +0 -7
  192. data/test/unit/helpers/kaui/account_timeline_helper_test.rb +0 -6
  193. data/test/unit/helpers/kaui/bundles_helper_test.rb +0 -6
  194. data/test/unit/helpers/kaui/chargebacks_helper_test.rb +0 -6
  195. data/test/unit/helpers/kaui/extpayments_helper_test.rb +0 -6
  196. data/test/unit/helpers/kaui/home_helper_test.rb +0 -6
  197. data/test/unit/helpers/kaui/invoices_helper_test.rb +0 -6
  198. data/test/unit/helpers/kaui/payments_helper_test.rb +0 -6
  199. data/test/unit/helpers/kaui/refunds_helper_test.rb +0 -6
  200. data/test/unit/kaui/overdue_state_test.rb +0 -18
  201. data/test/unit/kaui/refund_test.rb +0 -20
  202. data/test/unit/model_test.rb +0 -151
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dfe42ad2548ff670bed0e9282f8b311156d2e5e
4
+ data.tar.gz: 9b06404c20ea0f49392971aa3c93eb75ce51e5de
5
+ SHA512:
6
+ metadata.gz: a1039d8c8b644990de6ac798aa5ebea4e8f0cda5d548d742103eba5ff2a9bcc34d353f5299d48afa080f699cb212816d822f2758fe08046542da726062bcec15
7
+ data.tar.gz: 67b84718f67dda80b67de237483d406fee007b9f1baca451d79836d624e3633dcae3bf325af25509b8db2286fa2b7dddd8bc81dcd382e19d551f0d0f70767200
data/.gitignore CHANGED
@@ -10,3 +10,5 @@ sandbox
10
10
  foo
11
11
  # Local testing credentials
12
12
  config/initializers/killbill_client.rb
13
+ coverage
14
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaui (0.6.6)
4
+ kaui (0.7.0)
5
5
  cancan (~> 1.6.10)
6
+ carmen-rails (~> 1.0.0)
6
7
  d3_rails (~> 3.2.8)
7
8
  devise (~> 3.0.2)
8
9
  jquery-rails (~> 3.0.4)
9
- killbill-client (~> 0.6.1)
10
+ killbill-client (~> 0.7.3)
10
11
  money-rails (~> 0.8.1)
11
12
  rails (~> 3.2.14)
12
- rest-client (~> 1.6.7)
13
13
 
14
14
  GEM
15
15
  remote: http://rubygems.org/
16
16
  specs:
17
- actionmailer (3.2.16)
18
- actionpack (= 3.2.16)
17
+ actionmailer (3.2.19)
18
+ actionpack (= 3.2.19)
19
19
  mail (~> 2.5.4)
20
- actionpack (3.2.16)
21
- activemodel (= 3.2.16)
22
- activesupport (= 3.2.16)
20
+ actionpack (3.2.19)
21
+ activemodel (= 3.2.19)
22
+ activesupport (= 3.2.19)
23
23
  builder (~> 3.0.0)
24
24
  erubis (~> 2.7.0)
25
25
  journey (~> 1.0.4)
@@ -27,24 +27,31 @@ GEM
27
27
  rack-cache (~> 1.2)
28
28
  rack-test (~> 0.6.1)
29
29
  sprockets (~> 2.2.1)
30
- activemodel (3.2.16)
31
- activesupport (= 3.2.16)
30
+ activemodel (3.2.19)
31
+ activesupport (= 3.2.19)
32
32
  builder (~> 3.0.0)
33
- activerecord (3.2.16)
34
- activemodel (= 3.2.16)
35
- activesupport (= 3.2.16)
33
+ activerecord (3.2.19)
34
+ activemodel (= 3.2.19)
35
+ activesupport (= 3.2.19)
36
36
  arel (~> 3.0.2)
37
37
  tzinfo (~> 0.3.29)
38
- activeresource (3.2.16)
39
- activemodel (= 3.2.16)
40
- activesupport (= 3.2.16)
41
- activesupport (3.2.16)
38
+ activeresource (3.2.19)
39
+ activemodel (= 3.2.19)
40
+ activesupport (= 3.2.19)
41
+ activesupport (3.2.19)
42
42
  i18n (~> 0.6, >= 0.6.4)
43
43
  multi_json (~> 1.0)
44
44
  arel (3.0.3)
45
- bcrypt-ruby (3.1.2)
45
+ bcrypt (3.1.7)
46
+ bcrypt-ruby (3.1.5)
47
+ bcrypt (>= 3.1.3)
46
48
  builder (3.0.4)
47
49
  cancan (1.6.10)
50
+ carmen (1.0.1)
51
+ unicode_utils (~> 1.4.0)
52
+ carmen-rails (1.0.1)
53
+ carmen (~> 1.0.0)
54
+ rails
48
55
  d3_rails (3.2.8)
49
56
  railties (>= 3.1.0)
50
57
  devise (3.0.4)
@@ -52,16 +59,17 @@ GEM
52
59
  orm_adapter (~> 0.1)
53
60
  railties (>= 3.2.6, < 5)
54
61
  warden (~> 1.2.3)
62
+ docile (1.1.5)
55
63
  erubis (2.7.0)
56
64
  fakeweb (1.3.0)
57
65
  hike (1.2.3)
58
- i18n (0.6.9)
66
+ i18n (0.6.11)
59
67
  journey (1.0.4)
60
68
  jquery-rails (3.0.4)
61
69
  railties (>= 3.0, < 5.0)
62
70
  thor (>= 0.14, < 2.0)
63
71
  json (1.8.1)
64
- killbill-client (0.6.1)
72
+ killbill-client (0.7.3)
65
73
  json (~> 1.8.0)
66
74
  mail (2.5.4)
67
75
  mime-types (~> 1.16)
@@ -73,28 +81,28 @@ GEM
73
81
  activesupport (>= 3.0)
74
82
  money (~> 5.1.0)
75
83
  railties (>= 3.0)
76
- multi_json (1.8.4)
84
+ multi_json (1.9.2)
77
85
  mysql2 (0.3.13)
78
86
  orm_adapter (0.5.0)
79
- polyglot (0.3.3)
87
+ polyglot (0.3.5)
80
88
  rack (1.4.5)
81
89
  rack-cache (1.2)
82
90
  rack (>= 0.4)
83
- rack-ssl (1.3.3)
91
+ rack-ssl (1.3.4)
84
92
  rack
85
93
  rack-test (0.6.2)
86
94
  rack (>= 1.0)
87
- rails (3.2.16)
88
- actionmailer (= 3.2.16)
89
- actionpack (= 3.2.16)
90
- activerecord (= 3.2.16)
91
- activeresource (= 3.2.16)
92
- activesupport (= 3.2.16)
95
+ rails (3.2.19)
96
+ actionmailer (= 3.2.19)
97
+ actionpack (= 3.2.19)
98
+ activerecord (= 3.2.19)
99
+ activeresource (= 3.2.19)
100
+ activesupport (= 3.2.19)
93
101
  bundler (~> 1.0)
94
- railties (= 3.2.16)
95
- railties (3.2.16)
96
- actionpack (= 3.2.16)
97
- activesupport (= 3.2.16)
102
+ railties (= 3.2.19)
103
+ railties (3.2.19)
104
+ actionpack (= 3.2.19)
105
+ activesupport (= 3.2.19)
98
106
  rack-ssl (~> 1.3.2)
99
107
  rake (>= 0.8.7)
100
108
  rdoc (~> 3.4)
@@ -102,20 +110,24 @@ GEM
102
110
  rake (10.1.1)
103
111
  rdoc (3.12.2)
104
112
  json (~> 1.4)
105
- rest-client (1.6.7)
106
- mime-types (>= 1.16)
113
+ simplecov (0.9.0)
114
+ docile (~> 1.1.0)
115
+ multi_json
116
+ simplecov-html (~> 0.8.0)
117
+ simplecov-html (0.8.0)
107
118
  sprockets (2.2.2)
108
119
  hike (~> 1.2)
109
120
  multi_json (~> 1.0)
110
121
  rack (~> 1.0)
111
122
  tilt (~> 1.1, != 1.3.0)
112
123
  sqlite3 (1.3.8)
113
- thor (0.18.1)
124
+ thor (0.19.1)
114
125
  tilt (1.4.1)
115
126
  treetop (1.4.15)
116
127
  polyglot
117
128
  polyglot (>= 0.3.1)
118
- tzinfo (0.3.38)
129
+ tzinfo (0.3.40)
130
+ unicode_utils (1.4.0)
119
131
  warden (1.2.3)
120
132
  rack (>= 1.0)
121
133
 
@@ -126,4 +138,6 @@ DEPENDENCIES
126
138
  fakeweb (~> 1.3)
127
139
  kaui!
128
140
  mysql2
141
+ rake (>= 0.8.7)
142
+ simplecov
129
143
  sqlite3
data/README.md CHANGED
@@ -28,6 +28,9 @@ name of the logged-in user. This is used by Killbill for auditing purposes.
28
28
 
29
29
  Finally, Killbill server needs to be running for Kaui to fetch its information. Set the `KILLBILL_URL`
30
30
  variable to point to your existing Killbill installation (e.g. http://killbill.company.com:8080).
31
+ The default login credentials are admin/password. Users, Credentials, Roles and Permissions are
32
+ passed through to Kill Bill. It uses Basic Auth by default, but the backend is pluggable (LDAP,
33
+ ActiveDirectory, etc.).
31
34
 
32
35
 
33
36
  Multi-Tenancy
@@ -36,6 +39,7 @@ Multi-Tenancy
36
39
  If you are using Kaui against a single tenant, specify your api key and secret in ```config/initializers/killbill_client.rb```:
37
40
 
38
41
  ```
42
+ KillBillClient.url = 'http://127.0.0.1:8080/'
39
43
  KillBillClient.api_key = 'bob'
40
44
  KillBillClient.api_secret = 'lazar'
41
45
  ```
@@ -59,6 +63,7 @@ Run the tests:
59
63
  > cd ../..
60
64
  > rake test
61
65
 
66
+ Note: functional and integration tests require an instance of Kill Bill to test against.
62
67
 
63
68
  Development
64
69
  ===========
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
7
 
8
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
8
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
9
9
  load 'rails/tasks/engine.rake'
10
10
 
11
11
  Bundler::GemHelper.install_tasks
@@ -1,54 +1,36 @@
1
- module Kaui
2
- class AccountEmailsController < EngineController
3
- # GET /account_emails/1
4
- # GET /account_emails/1.json
5
- def show
6
- @account_id = params[:id]
7
- @account_emails = AccountEmail.where({ :account_id => @account_id }, options_for_klient)
1
+ class Kaui::AccountEmailsController < Kaui::EngineController
8
2
 
9
- respond_to do |format|
10
- format.html # show.html.erb
11
- format.json { render :json => @account_email }
12
- end
13
- end
14
-
15
- # GET /account_emails/new
16
- # GET /account_emails/new.json
17
- def new
18
- @account_email = AccountEmail.new(:account_id => params[:account_id])
3
+ def show
4
+ @account_id = params[:id]
5
+ @account_emails = Kaui::AccountEmail.find_all_sorted_by_account_id(@account_id, 'NONE', options_for_klient)
6
+ end
19
7
 
20
- respond_to do |format|
21
- format.html # new.html.erb
22
- format.json { render :json => @account_email }
23
- end
24
- end
8
+ def new
9
+ @account_email = Kaui::AccountEmail.new(:account_id => params[:account_id])
10
+ end
25
11
 
26
- # POST /account_emails
27
- # POST /account_emails.json
28
- def create
29
- @account_email = AccountEmail.new(params[:account_email])
12
+ def create
13
+ @account_email = Kaui::AccountEmail.new(params[:account_email])
30
14
 
31
- respond_to do |format|
32
- if @account_email.save(current_user, params[:reason], params[:comment], options_for_klient)
33
- format.html { redirect_to kaui_engine.account_email_path(@account_email), :notice => 'Account email was successfully created.' }
34
- format.json { render :json => @account_email, :status => :created, :location => @account_email }
35
- else
36
- format.html { render :action => "new" }
37
- format.json { render :json => @account_email.errors, :status => :unprocessable_entity }
38
- end
39
- end
15
+ account = Kaui::Account.new(:account_id => @account_email.account_id)
16
+ begin
17
+ account.add_email(@account_email.email, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
18
+ redirect_to account_email_path(account.account_id), :notice => 'Account email was successfully added'
19
+ rescue => e
20
+ flash.now[:error] = "Error while adding the email: #{as_string(e)}"
21
+ render :action => :new
40
22
  end
23
+ end
41
24
 
42
- # DELETE /account_emails/1
43
- # DELETE /account_emails/1.json
44
- def destroy
45
- @account_email = AccountEmail.where({ :account_id => params[:id], :email => params[:email] }, options_for_klient)
46
- @account_email.destroy(current_user, params[:reason], params[:comment], options_for_klient)
25
+ def destroy
26
+ account = Kaui::Account.new(:account_id => params[:id])
47
27
 
48
- respond_to do |format|
49
- format.html { redirect_to kaui_engine.account_email_path(params[:id]) }
50
- format.json { head :no_content }
51
- end
28
+ begin
29
+ account.remove_email(params[:email], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
30
+ redirect_to account_email_path(account.account_id), :notice => 'Account email was successfully deleted'
31
+ rescue => e
32
+ flash.now[:error] = "Error while deleting account email: #{as_string(e)}"
33
+ render :action => :show, :id => account.account_id
52
34
  end
53
35
  end
54
36
  end
@@ -1,59 +1,47 @@
1
1
  class Kaui::AccountTagsController < Kaui::EngineController
2
2
 
3
3
  def show
4
- account_id = params[:account_id]
4
+ account_id_or_key = params[:account_id]
5
5
 
6
- if account_id.present?
7
- begin
8
- @tags = Kaui::KillbillHelper::get_tags_for_account(account_id, true, "FULL", options_for_klient)
9
- @account = Kaui::KillbillHelper::get_account(account_id, false, false, options_for_klient)
10
- rescue => e
11
- flash.now[:error] = "Error while getting tags: #{as_string(e)}"
12
- end
13
- else
14
- flash.now[:error] = "No account id given"
6
+ begin
7
+ @account = Kaui::Account::find_by_id_or_key(account_id_or_key, false, false, options_for_klient)
8
+ @tags = @account.tags(true, 'FULL', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
9
+ rescue => e
10
+ flash[:error] = "Error while getting tags: #{as_string(e)}"
11
+ redirect_to :back
15
12
  end
16
13
  end
17
14
 
18
15
  def edit
19
- @account_id = params[:account_id]
16
+ account_id_or_key = params[:account_id]
17
+
20
18
  begin
21
- @available_tags = Kaui::TagDefinition.all_for_account(options_for_klient).sort
22
- @account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
23
- @tag_names = Kaui::KillbillHelper::get_tags_for_account(@account.account_id, false, "NONE", options_for_klient).map { |tag| tag.tag_definition_name }
19
+ @account = Kaui::Account::find_by_id_or_key(account_id_or_key, false, false, options_for_klient)
20
+ @tag_names = (@account.tags(false, 'NONE', options_for_klient).map { |tag| tag.tag_definition_name }).sort
21
+ @available_tags = Kaui::TagDefinition.all_for_account(options_for_klient)
24
22
  rescue => e
25
- flash.now[:error] = "Error while editing tags: #{as_string(e)}"
23
+ flash[:error] = "Error while editing tags: #{as_string(e)}"
24
+ redirect_to kaui_engine.account_tags_path(:account_id => account_id_or_key)
26
25
  end
27
26
  end
28
27
 
29
28
  def update
30
- begin
31
- current_tags = Kaui::KillbillHelper::get_tags_for_account(params[:account_id], false, "NONE", options_for_klient).map { |tag| tag.tag_definition_id }
32
-
33
- new_tags = []
34
- params.each do |tag, tag_name|
35
- tag_info = tag.split('_')
36
- next if tag_info.size != 2 or tag_info[0] != 'tag'
37
- new_tags << tag_info[1]
38
- end
39
-
40
- # Find tags to remove
41
- tags_to_remove = []
42
- current_tags.each do |current_tag_definition_id|
43
- tags_to_remove << current_tag_definition_id unless new_tags.include?(current_tag_definition_id)
44
- end
29
+ account_id = params[:account_id]
45
30
 
46
- # Find tags to add
47
- tags_to_add = []
48
- new_tags.each do |new_tag_definition_id|
49
- tags_to_add << new_tag_definition_id unless current_tags.include?(new_tag_definition_id)
50
- end
31
+ tags = []
32
+ params.each do |tag, tag_name|
33
+ tag_info = tag.split('_')
34
+ next if tag_info.size != 2 or tag_info[0] != 'tag'
35
+ tags << tag_info[1]
36
+ end
51
37
 
52
- Kaui::KillbillHelper::remove_tags_for_account(params[:account_id], tags_to_remove, current_user, params[:reason], params[:comment], options_for_klient) unless tags_to_remove.empty?
53
- Kaui::KillbillHelper::add_tags_for_account(params[:account_id], tags_to_add, current_user, params[:reason], params[:comment], options_for_klient) unless tags_to_add.empty?
38
+ begin
39
+ account = Kaui::Account.new(:account_id => account_id)
40
+ account.set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
41
+ redirect_to kaui_engine.account_tags_path(:account_id => account_id), :notice => 'Account tags successfully set'
54
42
  rescue => e
55
43
  flash[:error] = "Error while updating tags: #{as_string(e)}"
44
+ redirect_to kaui_engine.account_tags_path(:account_id => account_id)
56
45
  end
57
- redirect_to kaui_engine.account_path(params[:account_id])
58
46
  end
59
47
  end
@@ -1,66 +1,63 @@
1
1
  class Kaui::AccountTimelinesController < Kaui::EngineController
2
+
2
3
  def index
3
- if params[:account_id].present?
4
- redirect_to kaui_engine.account_timeline_path(params[:account_id])
5
- end
6
4
  end
7
5
 
8
6
  def show
9
7
  @account_id = params[:id]
10
- unless @account_id.present?
11
- flash[:notice] = "No id given"
12
- redirect_to :back
13
- return
14
- end
8
+
15
9
  begin
16
- @account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
17
- @timeline = Kaui::KillbillHelper::get_account_timeline(@account_id, "MINIMAL", options_for_klient)
10
+ @account = Kaui::Account.find_by_id(@account_id, false, false, options_for_klient)
11
+ @timeline = Kaui::AccountTimeline.find_by_account_id(@account_id, 'MINIMAL', options_for_klient)
18
12
  rescue => e
19
13
  flash[:error] = "Could not load the account timeline for #{@account_id}: #{as_string(e)}"
20
- redirect_to :action => :index
21
- return
14
+ render :action => :index and return
22
15
  end
23
16
 
24
- @invoices_by_id = {}
25
- @bundle_names = {}
26
- unless @timeline.nil?
27
- @timeline.payments.each do |payment|
28
- if payment.invoice_id.present? && payment.payment_id.present?
29
- begin
30
- @invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id, true, "NONE", options_for_klient)
31
- rescue => e
32
- flash.now[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
33
- end
34
- payment.bundle_keys.split(",").each do |bundle_key|
35
- unless @bundle_names.has_key?(bundle_key)
36
- @bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
37
- end
38
- end
39
- end
40
- end
41
- @timeline.invoices.each do |invoice|
42
- if invoice.invoice_id.present? && !@invoices_by_id.has_key?(invoice.invoice_id)
43
- begin
44
- @invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id, true, "NONE", options_for_klient)
45
- rescue => e
46
- flash.now[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
47
- end
48
- invoice.bundle_keys.split(",").each do |bundle_key|
49
- unless @bundle_names.has_key?(bundle_key)
50
- @bundle_names[bundle_key] = Kaui.bundle_key_display_string.call(bundle_key)
51
- end
52
- end
53
- end
54
- end
55
- @timeline.bundles.each do |bundle|
56
- unless @bundle_names.has_key?(bundle.external_key)
57
- @bundle_names[bundle.external_key] = Kaui.bundle_key_display_string.call(bundle.external_key)
58
- end
17
+ # Lookup all bundle names
18
+ @bundle_names = {}
19
+ @bundle_names_by_invoice_id = {}
20
+ @bundle_keys_by_invoice_id = {}
21
+ @timeline.bundles.each do |bundle|
22
+ load_bundle_name_for_timeline(bundle.external_key)
23
+ end
24
+ @timeline.invoices.each do |invoice|
25
+ @bundle_names_by_invoice_id[invoice.invoice_id] = Set.new
26
+ @bundle_keys_by_invoice_id[invoice.invoice_id] = Set.new
27
+ (invoice.bundle_keys || '').split(',').each do |bundle_key|
28
+ load_bundle_name_for_timeline(bundle_key)
29
+ @bundle_names_by_invoice_id[invoice.invoice_id] << @bundle_names[bundle_key]
30
+ @bundle_keys_by_invoice_id[invoice.invoice_id] << bundle_key
59
31
  end
32
+ end
60
33
 
61
- if params.has_key?(:external_key)
62
- @selected_bundle = @bundle_names[params[:external_key]]
63
- end
34
+ # Lookup all invoices
35
+ @invoices_by_id = {}
36
+ @timeline.payments.each do |payment|
37
+ load_invoice_id_for_timeline(payment.target_invoice_id)
38
+ end
39
+ @timeline.invoices.each do |invoice|
40
+ load_invoice_id_for_timeline(invoice.invoice_id)
41
+ end
42
+
43
+ if params.has_key?(:external_key)
44
+ @selected_bundle = @bundle_names[params[:external_key]]
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def load_bundle_name_for_timeline(bundle_key)
51
+ @bundle_names[bundle_key] ||= Kaui.bundle_key_display_string.call(bundle_key)
52
+ end
53
+
54
+ def load_invoice_id_for_timeline(invoice_id)
55
+ return if invoice_id.blank? or @invoices_by_id.has_key?(invoice_id)
56
+
57
+ begin
58
+ @invoices_by_id[invoice_id] = Kaui::Invoice.find_by_id_or_number(invoice_id, true, 'NONE', options_for_klient)
59
+ rescue => e
60
+ flash.now[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
64
61
  end
65
62
  end
66
63
  end