solidus_papertrail 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +21 -0
- data/Gemfile +18 -0
- data/LICENSE +26 -0
- data/README.md +45 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/admin/solidus_papertrail.js +1 -0
- data/app/assets/javascripts/spree/backend/solidus_papertrail.js +0 -0
- data/app/assets/javascripts/spree/frontend/solidus_papertrail.js +0 -0
- data/app/assets/javascripts/store/solidus_papertrail.js +1 -0
- data/app/assets/stylesheets/admin/solidus_papertrail.css +3 -0
- data/app/assets/stylesheets/spree/backend/solidus_papertrail.css +0 -0
- data/app/assets/stylesheets/spree/frontend/solidus_papertrail.css +0 -0
- data/app/assets/stylesheets/store/solidus_papertrail.css +3 -0
- data/app/controllers/spree/admin/base_controller_decorator.rb +5 -0
- data/app/controllers/spree/admin/orders_controller_decorator.rb +22 -0
- data/app/models/paper_trail/version_decorator.rb +5 -0
- data/app/models/spree/adjustment_decorator.rb +15 -0
- data/app/models/spree/adjustment_version.rb +5 -0
- data/app/models/spree/line_item_decorator.rb +15 -0
- data/app/models/spree/line_item_version.rb +5 -0
- data/app/models/spree/order_decorator.rb +15 -0
- data/app/models/spree/order_version.rb +5 -0
- data/app/models/spree/payment_decorator.rb +15 -0
- data/app/models/spree/payment_version.rb +5 -0
- data/app/models/spree/return_authorization_decorator.rb +15 -0
- data/app/models/spree/return_authorization_version.rb +5 -0
- data/app/models/spree/shipment_decorator.rb +15 -0
- data/app/models/spree/shipment_version.rb +5 -0
- data/app/overrides/add_order_history_to_order_menu.rb +8 -0
- data/app/services/versions_adapter.rb +24 -0
- data/app/services/yaml_adapter.rb +27 -0
- data/app/views/spree/admin/orders/_adjustment_versions.html.erb +48 -0
- data/app/views/spree/admin/orders/_line_item_versions.html.erb +52 -0
- data/app/views/spree/admin/orders/_object_changes.html.erb +41 -0
- data/app/views/spree/admin/orders/_order_versions.html.erb +45 -0
- data/app/views/spree/admin/orders/_payment_versions.html.erb +51 -0
- data/app/views/spree/admin/orders/_return_authorization_versions.html.erb +48 -0
- data/app/views/spree/admin/orders/_shipment_versions.html.erb +52 -0
- data/app/views/spree/admin/orders/versions.html.erb +25 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +21 -0
- data/config/locales/es.yml +5 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20160421221937_create_versions.rb +87 -0
- data/lib/generators/solidus_papertrail/install/install_generator.rb +31 -0
- data/lib/solidus_papertrail.rb +4 -0
- data/lib/solidus_papertrail/engine.rb +22 -0
- data/lib/solidus_papertrail/factories.rb +6 -0
- data/lib/solidus_papertrail/version.rb +3 -0
- data/solidus_papertrail.gemspec +36 -0
- data/spec/features/admin/order_history_spec.rb +94 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/capybara.rb +12 -0
- data/spec/support/database_cleaner.rb +24 -0
- data/spec/support/factory_girl.rb +8 -0
- data/spec/support/feature_helper.rb +10 -0
- data/spec/support/spree.rb +7 -0
- metadata +269 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f76131771daeafcb5091ed3aab30d981a3b6227b
|
4
|
+
data.tar.gz: 7363f77964e6871eae1622111658ec1ce5293ec1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b484d08640228250b6bd2604fb877d4a9f0fa16e42fe722c2ff687ab93dd57ec19b5eafd4e5934be6717760deecec9ceca753bf2ecd8336e9990f35ff465a941
|
7
|
+
data.tar.gz: 71f64c91bedb14f237f8435a7dfe0cb2baf8ffd510ba0add5b4389c97c0002b8da833e40e748bebd44d33f48fedbc4eedd5b6c42b7bf60b456feaae43d77aee5
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
sudo: false
|
2
|
+
cache: bundler
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- 2.3.1
|
6
|
+
env:
|
7
|
+
matrix:
|
8
|
+
- SOLIDUS_BRANCH=v1.0 DB=postgres
|
9
|
+
- SOLIDUS_BRANCH=v1.1 DB=postgres
|
10
|
+
- SOLIDUS_BRANCH=v1.2 DB=postgres
|
11
|
+
- SOLIDUS_BRANCH=v1.3 DB=postgres
|
12
|
+
- SOLIDUS_BRANCH=v1.4 DB=postgres
|
13
|
+
- SOLIDUS_BRANCH=v2.0 DB=postgres
|
14
|
+
- SOLIDUS_BRANCH=master DB=postgres
|
15
|
+
- SOLIDUS_BRANCH=v1.0 DB=mysql
|
16
|
+
- SOLIDUS_BRANCH=v1.1 DB=mysql
|
17
|
+
- SOLIDUS_BRANCH=v1.2 DB=mysql
|
18
|
+
- SOLIDUS_BRANCH=v1.3 DB=mysql
|
19
|
+
- SOLIDUS_BRANCH=v1.4 DB=mysql
|
20
|
+
- SOLIDUS_BRANCH=v2.0 DB=mysql
|
21
|
+
- SOLIDUS_BRANCH=master DB=mysql
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
|
4
|
+
gem "solidus", github: "solidusio/solidus", branch: branch
|
5
|
+
gem "solidus_auth_devise"
|
6
|
+
|
7
|
+
if branch == 'master' || branch >= "v2.0"
|
8
|
+
gem "rails-controller-testing", group: :test
|
9
|
+
end
|
10
|
+
|
11
|
+
gem 'pg'
|
12
|
+
gem 'mysql2'
|
13
|
+
|
14
|
+
group :development, :test do
|
15
|
+
gem "pry-rails"
|
16
|
+
end
|
17
|
+
|
18
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2014 [name of plugin creator]
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
SolidusPapertrail
|
2
|
+
===============
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/solidusio-contrib/solidus_papertrail.svg?branch=master)](https://travis-ci.org/solidusio-contrib/solidus_papertrail)
|
5
|
+
|
6
|
+
Introduction goes here.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Add solidus_papertrail to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'solidus_papertrail'
|
15
|
+
```
|
16
|
+
|
17
|
+
Bundle your dependencies and run the installation generator:
|
18
|
+
|
19
|
+
```shell
|
20
|
+
bundle
|
21
|
+
bundle exec rails g solidus_papertrail:install
|
22
|
+
```
|
23
|
+
|
24
|
+
Testing
|
25
|
+
-------
|
26
|
+
|
27
|
+
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
|
28
|
+
|
29
|
+
```shell
|
30
|
+
bundle
|
31
|
+
bundle exec rake test_app
|
32
|
+
bundle exec rspec spec
|
33
|
+
```
|
34
|
+
|
35
|
+
When testing your applications integration with this extension you may use it's factories.
|
36
|
+
Simply add this require statement to your spec_helper:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'solidus_papertrail/factories'
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
Copyright (c) 2014 [Acid Labs][acidlabs], released under the New BSD License
|
44
|
+
|
45
|
+
[acidlabs]: https://github.com/acidlabs
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/common_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
if Dir["spec/dummy"].empty?
|
11
|
+
Rake::Task[:test_app].invoke
|
12
|
+
Dir.chdir("../../")
|
13
|
+
end
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generates a dummy app for testing'
|
18
|
+
task :test_app do
|
19
|
+
ENV['LIB_NAME'] = 'solidus_papertrail'
|
20
|
+
Rake::Task['common:test_app'].invoke("Spree::User")
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
File without changes
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Spree::Admin::OrdersController.class_eval do
|
2
|
+
def versions
|
3
|
+
@order = Spree::Order.find_by_number params[:id]
|
4
|
+
|
5
|
+
@versions = VersionsAdapter.create([@order])
|
6
|
+
|
7
|
+
payments = @order.payments.order(updated_at: :asc)
|
8
|
+
@payment_versions = VersionsAdapter.create(payments)
|
9
|
+
|
10
|
+
shipments = @order.shipments.order(updated_at: :desc)
|
11
|
+
@shipment_versions = VersionsAdapter.create(shipments)
|
12
|
+
|
13
|
+
line_items = @order.line_items.order(updated_at: :desc)
|
14
|
+
@line_item_versions = VersionsAdapter.create(line_items)
|
15
|
+
|
16
|
+
adjustments = @order.all_adjustments.order(updated_at: :desc)
|
17
|
+
@adjustment_versions = VersionsAdapter.create(adjustments)
|
18
|
+
|
19
|
+
return_authorizations = @order.return_authorizations.order(updated_at: :desc)
|
20
|
+
@return_authorization_versions = VersionsAdapter.create(return_authorizations)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
Adjustment.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::AdjustmentVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = 'Unknown'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
LineItem.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::LineItemVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = 'Unknown'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
Order.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::OrderVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = 'Unknown'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
Payment.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::PaymentVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = ""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
ReturnAuthorization.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::ReturnAuthorizationVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = ""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
Shipment.class_eval do
|
3
|
+
has_paper_trail class_name: 'Spree::ShipmentVersion'
|
4
|
+
|
5
|
+
attr_accessor :who, :version_changes, :version_id, :version_event, :version_date
|
6
|
+
|
7
|
+
def who=(user_id)
|
8
|
+
begin
|
9
|
+
@who = Spree::User.find(user_id).full_name
|
10
|
+
rescue
|
11
|
+
@who = ""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Deface::Override.new( virtual_path: 'spree/admin/shared/_order_submenu',
|
2
|
+
name: 'order_history_menu',
|
3
|
+
insert_bottom: "[data-hook='admin_order_tabs']",
|
4
|
+
text: "
|
5
|
+
<li <%== 'class=\"active\"' if current == 'Order History' %>><%= link_to_with_icon 'icon-shopping-cart', Spree.t(:order_history), versions_admin_order_path(@order) %></li>
|
6
|
+
"
|
7
|
+
|
8
|
+
)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class VersionsAdapter
|
2
|
+
|
3
|
+
def self.create(elements)
|
4
|
+
collection = []
|
5
|
+
elements.each do |element|
|
6
|
+
if element.respond_to?(:versions)
|
7
|
+
versions = element.versions.order(:object, created_at: :asc)
|
8
|
+
versions.each do |version|
|
9
|
+
prototype = version.object.nil? ?
|
10
|
+
element.class.new :
|
11
|
+
YamlAdapter.new(version.object, element.class).deserialize
|
12
|
+
prototype.who = version.whodunnit
|
13
|
+
prototype.version_id = version.id
|
14
|
+
prototype.version_event = version.event
|
15
|
+
prototype.version_changes = version.object_changes
|
16
|
+
prototype.version_date = version.created_at
|
17
|
+
collection << prototype
|
18
|
+
end
|
19
|
+
collection << element
|
20
|
+
end
|
21
|
+
end
|
22
|
+
collection
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class YamlAdapter
|
2
|
+
attr_reader :payload, :klass
|
3
|
+
|
4
|
+
def initialize text, klass
|
5
|
+
@data = YAML.load(text)
|
6
|
+
@klass = klass
|
7
|
+
end
|
8
|
+
|
9
|
+
def deserialize
|
10
|
+
@klass.new(permitted_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# The below two methods prevent papertrail from
|
16
|
+
# attempting to instantiate models with attributes
|
17
|
+
# they do not have definitions for or do not have
|
18
|
+
# the corresponding columns in the database.
|
19
|
+
#
|
20
|
+
# Both cases are exceptional, so we filter this here.
|
21
|
+
def permitted_data
|
22
|
+
keys = @klass.column_names.to_set
|
23
|
+
@data.keep_if do |key, _|
|
24
|
+
keys.include?(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<fieldset class="no-border-bottom">
|
2
|
+
<legend align="center" class="" data-hook="">
|
3
|
+
<%= Spree::AdjustmentVersion.model_name.human %>
|
4
|
+
</legend>
|
5
|
+
</fieldset>
|
6
|
+
|
7
|
+
<table id="adjustment-history">
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("version_id") %></th>
|
11
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("id") %></th>
|
12
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("amount") %></th>
|
13
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("label") %></th>
|
14
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("event") %></th>
|
15
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("changes") %></th>
|
16
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("user") %></th>
|
17
|
+
<th><%= Spree::AdjustmentVersion.human_attribute_name("created") %></th>
|
18
|
+
</tr>
|
19
|
+
</thead>
|
20
|
+
|
21
|
+
<tbody>
|
22
|
+
<% @adjustment_versions.each do |adjustment| %>
|
23
|
+
<% if adjustment.version_id %>
|
24
|
+
<tr>
|
25
|
+
<td><%= adjustment.version_id %></td>
|
26
|
+
<td><%= adjustment.id %></td>
|
27
|
+
<td><%= number_to_currency adjustment.amount %></td>
|
28
|
+
<td><%= adjustment.label %></td>
|
29
|
+
<td><%= adjustment.version_event %></td>
|
30
|
+
<td class="align-center"><%= render partial: 'object_changes', locals: { object: adjustment } %></td>
|
31
|
+
<td><%= adjustment.who %></td>
|
32
|
+
<td><%= pretty_time(adjustment.version_date) %></td>
|
33
|
+
</tr>
|
34
|
+
<% else %>
|
35
|
+
<tr>
|
36
|
+
<td></td>
|
37
|
+
<td><%= adjustment.id %></td>
|
38
|
+
<td><%= number_to_currency adjustment.amount %></td>
|
39
|
+
<td><%= adjustment.label %></td>
|
40
|
+
<td></td>
|
41
|
+
<td></td>
|
42
|
+
<td></td>
|
43
|
+
<td><%= pretty_time(adjustment.updated_at) %></td>
|
44
|
+
</tr>
|
45
|
+
<% end %>
|
46
|
+
<% end %>
|
47
|
+
</tbody>
|
48
|
+
</table>
|