solidus_papertrail 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +18 -0
  6. data/LICENSE +26 -0
  7. data/README.md +45 -0
  8. data/Rakefile +21 -0
  9. data/app/assets/javascripts/admin/solidus_papertrail.js +1 -0
  10. data/app/assets/javascripts/spree/backend/solidus_papertrail.js +0 -0
  11. data/app/assets/javascripts/spree/frontend/solidus_papertrail.js +0 -0
  12. data/app/assets/javascripts/store/solidus_papertrail.js +1 -0
  13. data/app/assets/stylesheets/admin/solidus_papertrail.css +3 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_papertrail.css +0 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_papertrail.css +0 -0
  16. data/app/assets/stylesheets/store/solidus_papertrail.css +3 -0
  17. data/app/controllers/spree/admin/base_controller_decorator.rb +5 -0
  18. data/app/controllers/spree/admin/orders_controller_decorator.rb +22 -0
  19. data/app/models/paper_trail/version_decorator.rb +5 -0
  20. data/app/models/spree/adjustment_decorator.rb +15 -0
  21. data/app/models/spree/adjustment_version.rb +5 -0
  22. data/app/models/spree/line_item_decorator.rb +15 -0
  23. data/app/models/spree/line_item_version.rb +5 -0
  24. data/app/models/spree/order_decorator.rb +15 -0
  25. data/app/models/spree/order_version.rb +5 -0
  26. data/app/models/spree/payment_decorator.rb +15 -0
  27. data/app/models/spree/payment_version.rb +5 -0
  28. data/app/models/spree/return_authorization_decorator.rb +15 -0
  29. data/app/models/spree/return_authorization_version.rb +5 -0
  30. data/app/models/spree/shipment_decorator.rb +15 -0
  31. data/app/models/spree/shipment_version.rb +5 -0
  32. data/app/overrides/add_order_history_to_order_menu.rb +8 -0
  33. data/app/services/versions_adapter.rb +24 -0
  34. data/app/services/yaml_adapter.rb +27 -0
  35. data/app/views/spree/admin/orders/_adjustment_versions.html.erb +48 -0
  36. data/app/views/spree/admin/orders/_line_item_versions.html.erb +52 -0
  37. data/app/views/spree/admin/orders/_object_changes.html.erb +41 -0
  38. data/app/views/spree/admin/orders/_order_versions.html.erb +45 -0
  39. data/app/views/spree/admin/orders/_payment_versions.html.erb +51 -0
  40. data/app/views/spree/admin/orders/_return_authorization_versions.html.erb +48 -0
  41. data/app/views/spree/admin/orders/_shipment_versions.html.erb +52 -0
  42. data/app/views/spree/admin/orders/versions.html.erb +25 -0
  43. data/bin/rails +7 -0
  44. data/config/locales/en.yml +21 -0
  45. data/config/locales/es.yml +5 -0
  46. data/config/routes.rb +11 -0
  47. data/db/migrate/20160421221937_create_versions.rb +87 -0
  48. data/lib/generators/solidus_papertrail/install/install_generator.rb +31 -0
  49. data/lib/solidus_papertrail.rb +4 -0
  50. data/lib/solidus_papertrail/engine.rb +22 -0
  51. data/lib/solidus_papertrail/factories.rb +6 -0
  52. data/lib/solidus_papertrail/version.rb +3 -0
  53. data/solidus_papertrail.gemspec +36 -0
  54. data/spec/features/admin/order_history_spec.rb +94 -0
  55. data/spec/spec_helper.rb +32 -0
  56. data/spec/support/capybara.rb +12 -0
  57. data/spec/support/database_cleaner.rb +24 -0
  58. data/spec/support/factory_girl.rb +8 -0
  59. data/spec/support/feature_helper.rb +10 -0
  60. data/spec/support/spree.rb +7 -0
  61. metadata +269 -0
@@ -0,0 +1,52 @@
1
+ <fieldset class="no-border-bottom">
2
+ <legend align="center" class="" data-hook="">
3
+ <%= Spree::LineItemVersion.model_name.human %>
4
+ </legend>
5
+ </fieldset>
6
+
7
+ <table id="line-item-history">
8
+ <thead>
9
+ <tr>
10
+ <th><%= Spree::LineItemVersion.human_attribute_name("version_id") %></th>
11
+ <th><%= Spree::LineItemVersion.human_attribute_name("id") %></th>
12
+ <th><%= Spree::LineItemVersion.human_attribute_name("product") %></th>
13
+ <th><%= Spree::LineItemVersion.human_attribute_name("quantity") %></th>
14
+ <th><%= Spree::LineItemVersion.human_attribute_name("price") %></th>
15
+ <th><%= Spree::LineItemVersion.human_attribute_name("event") %></th>
16
+ <th><%= Spree::LineItemVersion.human_attribute_name("changes") %></th>
17
+ <th><%= Spree::LineItemVersion.human_attribute_name("user") %></th>
18
+ <th><%= Spree::LineItemVersion.human_attribute_name("created") %></th>
19
+ </tr>
20
+ </thead>
21
+
22
+ <tbody>
23
+ <% @line_item_versions.each do |line_item| %>
24
+ <% if line_item.version_id %>
25
+ <tr>
26
+ <td><%= line_item.version_id %></td>
27
+ <td><%= line_item.id %></td>
28
+ <td><%= line_item.name if line_item.variant %></td>
29
+ <td><%= line_item.quantity %></td>
30
+ <td><%= number_to_currency line_item.price %></td>
31
+ <td><%= line_item.version_event %></td>
32
+ <td class="align-center"><%= render partial: 'object_changes', locals: { object: line_item } %></td>
33
+ <td><%= line_item.who %></td>
34
+ <td><%= pretty_time(line_item.version_date) %></td>
35
+ </tr>
36
+ <% else %>
37
+ <tr>
38
+ <td></td>
39
+ <td></td>
40
+ <td><%= line_item.name if line_item.variant %></td>
41
+ <td><%= line_item.quantity %></td>
42
+ <td><%= number_to_currency line_item.price %></td>
43
+ <td></td>
44
+ <td></td>
45
+ <td></td>
46
+ <td><%= pretty_time(line_item.updated_at) %></td>
47
+ </tr>
48
+ <% end %>
49
+
50
+ <% end %>
51
+ </tbody>
52
+ </table>
@@ -0,0 +1,41 @@
1
+ <a href="javascript:$('#<%=object.class.name.demodulize.underscore%>-<%=object.version_id%>').show();" class="fa fa-search"></a>
2
+ <div id="<%=object.class.name.demodulize.underscore%>-<%=object.version_id%>" class="object-changes" style="display:none;
3
+ position: absolute;
4
+ width: 700px;
5
+ left: 50%;
6
+ margin-left: -350px;
7
+ border: 1px solid rgb(153, 153, 153);
8
+ display: none;
9
+ background: white;
10
+ z-index: 1;
11
+ padding: 10px;
12
+ margin-top: 20px;
13
+ ">
14
+ <table>
15
+ <colgroup>
16
+ <col style="width: 30%" />
17
+ <col style="width: 35%" />
18
+ <col style="width: 35%" />
19
+ </colgroup>
20
+ <thead>
21
+ <tr>
22
+ <th>Property</th>
23
+ <th>Old</th>
24
+ <th>New</th>
25
+ </tr>
26
+ </thead>
27
+ <tbody>
28
+ <% if object.version_changes %>
29
+ <% changes = YAML.load(object.version_changes) %>
30
+ <% changes.keys.each do |key| %>
31
+ <% next if ['created_at', 'updated_at'].include?(key) %>
32
+ <tr>
33
+ <td><%= key %></td>
34
+ <td><%= changes[key][0] %></td>
35
+ <td><%= changes[key][1] %></td>
36
+ </tr>
37
+ <% end %>
38
+ <% end %>
39
+ </tbody>
40
+ </table>
41
+ </div>
@@ -0,0 +1,45 @@
1
+ <fieldset class="no-border-bottom">
2
+ <legend align="center" class="" data-hook="">
3
+ <%= Spree::OrderVersion.model_name.human %>
4
+ </legend>
5
+ </fieldset>
6
+
7
+ <table id="order-history">
8
+ <thead>
9
+ <tr>
10
+ <th><%= Spree::OrderVersion.human_attribute_name("version_id") %></th>
11
+ <th><%= Spree::OrderVersion.human_attribute_name("status") %></th>
12
+ <th><%= Spree::OrderVersion.human_attribute_name("payment_state") %></th>
13
+ <th><%= Spree::OrderVersion.human_attribute_name("event") %></th>
14
+ <th><%= Spree::OrderVersion.human_attribute_name("changes") %></th>
15
+ <th><%= Spree::OrderVersion.human_attribute_name("user") %></th>
16
+ <th><%= Spree::OrderVersion.human_attribute_name("created") %></th>
17
+ </tr>
18
+ </thead>
19
+
20
+ <tbody>
21
+ <% @versions.each do |order| %>
22
+ <% if order.version_id %>
23
+ <tr>
24
+ <td><%= order.version_id %></td>
25
+ <td><%= order.state %></td>
26
+ <td><%= order.payment_state %></td>
27
+ <td><%= order.version_event %></td>
28
+ <td class="align-center"><%= render partial: 'object_changes', locals: { object: order } %></td>
29
+ <td><%= order.who %></td>
30
+ <td><%= pretty_time(order.version_date) %></td>
31
+ </tr>
32
+ <% else %>
33
+ <tr>
34
+ <td></td>
35
+ <td><%= order.state %></td>
36
+ <td><%= order.payment_state %></td>
37
+ <td></td>
38
+ <td></td>
39
+ <td></td>
40
+ <td><%= pretty_time(order.updated_at) %></td>
41
+ </tr>
42
+ <% end %>
43
+ <% end %>
44
+ </tbody>
45
+ </table>
@@ -0,0 +1,51 @@
1
+ <fieldset class="no-border-bottom">
2
+ <legend align="center" class="" data-hook="">
3
+ <%= Spree::PaymentVersion.model_name.human %>
4
+ </legend>
5
+ </fieldset>
6
+
7
+ <table id="payment-history">
8
+ <thead>
9
+ <tr>
10
+ <th><%= Spree::PaymentVersion.human_attribute_name("version_id") %></th>
11
+ <th><%= Spree::PaymentVersion.human_attribute_name("id") %></th>
12
+ <th><%= Spree::PaymentVersion.human_attribute_name("amount") %></th>
13
+ <th><%= Spree::PaymentVersion.human_attribute_name("payment_state") %></th>
14
+ <th><%= Spree::PaymentVersion.human_attribute_name("payment_method") %></th>
15
+ <th><%= Spree::PaymentVersion.human_attribute_name("event") %></th>
16
+ <th><%= Spree::PaymentVersion.human_attribute_name("changes") %></th>
17
+ <th><%= Spree::PaymentVersion.human_attribute_name("user") %></th>
18
+ <th><%= Spree::PaymentVersion.human_attribute_name("created") %></th>
19
+ </tr>
20
+ </thead>
21
+
22
+ <tbody>
23
+ <% @payment_versions.each do |payment| %>
24
+ <% if payment.version_id %>
25
+ <tr>
26
+ <td><%= payment.version_id %></td>
27
+ <td><%= payment.id %></td>
28
+ <td><%= number_to_currency payment.amount %></td>
29
+ <td><%= payment.state if payment.id %></td>
30
+ <td><%= payment_method_name(payment) if payment.id %></td>
31
+ <td><%= payment.version_event %></td>
32
+ <td class="align-center"><%= render partial: 'object_changes', locals: { object: payment } %></td>
33
+ <td><%= payment.who %></td>
34
+ <td><%= pretty_time(payment.version_date) %></td>
35
+ </tr>
36
+ <% else %>
37
+ <td></td>
38
+ <td><%= payment.id %></td>
39
+ <td><%= number_to_currency payment.amount %></td>
40
+ <td><%= payment.state if payment.id %></td>
41
+ <td><%= payment_method_name(payment) if payment.id %></td>
42
+ <td></td>
43
+ <td></td>
44
+ <td></td>
45
+ <td><%= pretty_time(payment.updated_at) %></td>
46
+ <% end %>
47
+ <% end %>
48
+ <tr>
49
+ </tr>
50
+ </tbody>
51
+ </table>
@@ -0,0 +1,48 @@
1
+ <fieldset class="no-border-bottom">
2
+ <legend align="center" class="" data-hook="">
3
+ <%= Spree::ReturnAuthorizationVersion.model_name.human %>
4
+ </legend>
5
+ </fieldset>
6
+
7
+ <table id="returns-history">
8
+ <thead>
9
+ <tr>
10
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("version_id") %></th>
11
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("number") %></th>
12
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("status") %></th>
13
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("pre_tax_total") %></th>
14
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("event") %></th>
15
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("changes") %></th>
16
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("user") %></th>
17
+ <th><%= Spree::ReturnAuthorizationVersion.human_attribute_name("created") %></th>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody>
22
+ <% @return_authorization_versions.each do |return_authorization| %>
23
+ <% if return_authorization.version_id %>
24
+ <tr>
25
+ <td><%= return_authorization.version_id %></td>
26
+ <td><%= return_authorization.number %></td>
27
+ <td><%= return_authorization.state %></td>
28
+ <td><%= return_authorization.order && return_authorization.display_pre_tax_total %></td>
29
+ <td><%= return_authorization.version_event %></td>
30
+ <td class="align-center"><%= render partial: 'object_changes', locals: { object: return_authorization } %></td>
31
+ <td><%= return_authorization.who %></td>
32
+ <td><%= pretty_time(return_authorization.version_date) %></td>
33
+ </tr>
34
+ <% else %>
35
+ <tr>
36
+ <td></td>
37
+ <td><%= return_authorization.number %></td>
38
+ <td><%= return_authorization.state %></td>
39
+ <td><%= return_authorization.order && return_authorization.display_pre_tax_total %></td>
40
+ <td></td>
41
+ <td></td>
42
+ <td></td>
43
+ <td><%= pretty_time(return_authorization.updated_at) %></td>
44
+ </tr>
45
+ <% end %>
46
+ <% end %>
47
+ </tbody>
48
+ </table>
@@ -0,0 +1,52 @@
1
+ <fieldset class="no-border-bottom">
2
+ <legend align="center" class="" data-hook="">
3
+ <%= Spree::ShipmentVersion.model_name.human %>
4
+ </legend>
5
+ </fieldset>
6
+
7
+ <table id="shipment-history">
8
+ <thead>
9
+ <tr>
10
+ <th><%= Spree::ShipmentVersion.human_attribute_name("version_id") %></th>
11
+ <th><%= Spree::ShipmentVersion.human_attribute_name("id") %></th>
12
+ <th><%= Spree::ShipmentVersion.human_attribute_name("tracking_number") %></th>
13
+ <th><%= Spree::ShipmentVersion.human_attribute_name("shipment_state") %></th>
14
+ <th><%= Spree::ShipmentVersion.human_attribute_name("shipping_method") %></th>
15
+ <th><%= Spree::ShipmentVersion.human_attribute_name("event") %></th>
16
+ <th><%= Spree::ShipmentVersion.human_attribute_name("changes") %></th>
17
+ <th><%= Spree::ShipmentVersion.human_attribute_name("user") %></th>
18
+ <th><%= Spree::ShipmentVersion.human_attribute_name("created") %></th>
19
+ </tr>
20
+ </thead>
21
+
22
+ <tbody>
23
+ <% @shipment_versions.each do |shipment| %>
24
+ <% if shipment.version_id %>
25
+ <tr>
26
+ <td><%= shipment.version_id %></td>
27
+ <td><%= shipment.id %></td>
28
+ <td><%= shipment.tracking %></td>
29
+ <td><%= shipment.state %></td>
30
+ <td><%= shipment.shipping_method.name if shipment.shipping_method %></td>
31
+ <td><%= shipment.version_event %></td>
32
+ <td class="align-center"><%= render partial: 'object_changes', locals: { object: shipment } %></td>
33
+ <td><%= shipment.who %></td>
34
+ <td><%= pretty_time(shipment.version_date) %></td>
35
+ </tr>
36
+ <% else %>
37
+ <tr>
38
+ <td></td>
39
+ <td><%= shipment.id %></td>
40
+ <td><%= shipment.tracking %></td>
41
+ <td><%= shipment.state %></td>
42
+ <td><%= shipment.shipping_method.name if shipment.shipping_method %></td>
43
+ <td></td>
44
+ <td></td>
45
+ <td></td>
46
+ <td><%= pretty_time(shipment.updated_at) %></td>
47
+ </tr>
48
+ <% end %>
49
+
50
+ <% end %>
51
+ </tbody>
52
+ </table>
@@ -0,0 +1,25 @@
1
+ <% content_for :page_actions do %>
2
+ <li><%= button_link_to Spree.t(:back), spree.edit_admin_order_path(@order), :icon => 'icon-arrow-left' %></li>
3
+ <% end %>
4
+
5
+ <%= render partial: 'spree/admin/shared/order_tabs', locals: { current: 'Audit Trail'} %>
6
+
7
+ <%= render partial: 'order_versions' %>
8
+
9
+ <%= render partial: 'line_item_versions' %>
10
+
11
+ <%= render partial: 'adjustment_versions' %>
12
+
13
+ <%= render partial: 'payment_versions' %>
14
+
15
+ <%= render partial: 'shipment_versions' %>
16
+
17
+ <%= render partial: 'return_authorization_versions' %>
18
+
19
+ <script>
20
+ $(function(){
21
+ $(document).on('click', 'body', function(){
22
+ $('.object-changes').hide();
23
+ });
24
+ });
25
+ </script>
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/solidus_papertrail/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,21 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ spree/adjustmentversion::
5
+ one: Adjustment Version
6
+ other: Adjustment History
7
+ spree/line_item_version::
8
+ one: Line Item Version
9
+ other: Line Item History
10
+ spree/orderversion::
11
+ one: Order Version
12
+ other: Order History
13
+ spree/paymentversion::
14
+ one: Payment Version
15
+ other: Payment History
16
+ spree/return_authorization_version:
17
+ one: Return Authorization Version
18
+ other: Return Authorization History
19
+ spree/shipmentversion::
20
+ one: Shipment Version
21
+ other: Shipment History
@@ -0,0 +1,5 @@
1
+ es:
2
+ spree:
3
+ payment_history: Historial de Pago
4
+ order_history: Historial de la Orden
5
+ shipment_history: Historial del Envío
@@ -0,0 +1,11 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ namespace :admin do
4
+ resources :orders do
5
+ member do
6
+ get :versions
7
+ end
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,87 @@
1
+ class CreateVersions < ActiveRecord::Migration
2
+ # The largest text column available in all supported RDBMS is
3
+ # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
4
+ # so that MySQL will use `longtext` instead of `text`. Otherwise,
5
+ # when serializing very large objects, `text` might not be big enough.
6
+ TEXT_BYTES = 1_073_741_823
7
+
8
+ def change
9
+ if !table_exists?(:spree_order_versions)
10
+ create_table :spree_order_versions do |t|
11
+ t.string :item_type, :null => false
12
+ t.integer :item_id, :null => false
13
+ t.string :event, :null => false
14
+ t.string :whodunnit
15
+ t.text :object, :limit => TEXT_BYTES
16
+ t.text :object_changes, :limit => TEXT_BYTES
17
+ t.datetime :created_at
18
+ end
19
+ add_index :spree_order_versions, [:item_type, :item_id]
20
+ end
21
+
22
+ if !table_exists?(:spree_payment_versions)
23
+ create_table :spree_payment_versions do |t|
24
+ t.string :item_type, :null => false
25
+ t.integer :item_id, :null => false
26
+ t.string :event, :null => false
27
+ t.string :whodunnit
28
+ t.text :object, :limit => TEXT_BYTES
29
+ t.text :object_changes, :limit => TEXT_BYTES
30
+ t.datetime :created_at
31
+ end
32
+ add_index :spree_payment_versions, [:item_type, :item_id]
33
+ end
34
+
35
+ if !table_exists?(:spree_shipment_versions)
36
+ create_table :spree_shipment_versions do |t|
37
+ t.string :item_type, :null => false
38
+ t.integer :item_id, :null => false
39
+ t.string :event, :null => false
40
+ t.string :whodunnit
41
+ t.text :object, :limit => TEXT_BYTES
42
+ t.text :object_changes, :limit => TEXT_BYTES
43
+ t.datetime :created_at
44
+ end
45
+ add_index :spree_shipment_versions, [:item_type, :item_id]
46
+ end
47
+
48
+ if !table_exists?(:spree_return_authorization_versions)
49
+ create_table :spree_return_authorization_versions do |t|
50
+ t.string :item_type, :null => false
51
+ t.integer :item_id, :null => false
52
+ t.string :event, :null => false
53
+ t.string :whodunnit
54
+ t.text :object, :limit => TEXT_BYTES
55
+ t.text :object_changes, :limit => TEXT_BYTES
56
+ t.datetime :created_at
57
+ end
58
+ add_index :spree_return_authorization_versions, [:item_type, :item_id], name: 'spree_return_auth_versions'
59
+ end
60
+
61
+ if !table_exists?(:spree_line_item_versions)
62
+ create_table :spree_line_item_versions do |t|
63
+ t.string :item_type, :null => false
64
+ t.integer :item_id, :null => false
65
+ t.string :event, :null => false
66
+ t.string :whodunnit
67
+ t.text :object, :limit => TEXT_BYTES
68
+ t.text :object_changes, :limit => TEXT_BYTES
69
+ t.datetime :created_at
70
+ end
71
+ add_index :spree_line_item_versions, [:item_type, :item_id]
72
+ end
73
+
74
+ if !table_exists?(:spree_adjustment_versions)
75
+ create_table :spree_adjustment_versions do |t|
76
+ t.string :item_type, :null => false
77
+ t.integer :item_id, :null => false
78
+ t.string :event, :null => false
79
+ t.string :whodunnit
80
+ t.text :object, :limit => TEXT_BYTES
81
+ t.text :object_changes, :limit => TEXT_BYTES
82
+ t.datetime :created_at
83
+ end
84
+ add_index :spree_adjustment_versions, [:item_type, :item_id]
85
+ end
86
+ end
87
+ end