Merge pull request #28 from exstake/add-paper-trail

add paper trail
This commit is contained in:
João Geonizeli
2021-08-17 23:17:29 -03:00
committed by GitHub
10 changed files with 84 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ gem "image_processing", "~> 1.12"
gem "devise" gem "devise"
gem "devise-i18n" gem "devise-i18n"
gem "paper_trail"
gem "slack-notifier" gem "slack-notifier"
gem "administrate-field-active_storage" gem "administrate-field-active_storage"
gem "administrate-field-enumerize" gem "administrate-field-enumerize"

View File

@@ -175,6 +175,9 @@ GEM
mini_portile2 (~> 2.6.1) mini_portile2 (~> 2.6.1)
racc (~> 1.4) racc (~> 1.4)
orm_adapter (0.5.0) orm_adapter (0.5.0)
paper_trail (12.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.20.1) parallel (1.20.1)
parser (3.0.2.0) parser (3.0.2.0)
ast (~> 2.4.1) ast (~> 2.4.1)
@@ -235,6 +238,8 @@ GEM
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
regexp_parser (2.1.1) regexp_parser (2.1.1)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.1) responders (3.0.1)
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
@@ -354,6 +359,7 @@ DEPENDENCIES
image_processing (~> 1.12) image_processing (~> 1.12)
listen (~> 3.3) listen (~> 3.3)
money-rails money-rails
paper_trail
pg (~> 1.1) pg (~> 1.1)
pry-byebug pry-byebug
puma (~> 5.0) puma (~> 5.0)

View File

@@ -2,5 +2,12 @@
module Admin module Admin
class ApplicationController < Administrate::ApplicationController class ApplicationController < Administrate::ApplicationController
before_action :authenticate_admin_user! before_action :authenticate_admin_user!
before_action :set_paper_trail_whodunnit
# used by #set_paper_trail_whodunnit
def current_user
# add admin prefix to differentiate from a customer
"admin/#{current_admin_user.id}"
end
end end
end end

View File

@@ -1,5 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
before_action :configure_devise_permitted_parameters, if: :devise_controller? before_action :configure_devise_permitted_parameters, if: :devise_controller?
protected protected

View File

@@ -22,6 +22,8 @@
# fk_rails_... (user_id => users.id) # fk_rails_... (user_id => users.id)
# #
class Balance < ApplicationRecord class Balance < ApplicationRecord
include Trackable
belongs_to :user belongs_to :user
belongs_to :currency belongs_to :currency

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
module Trackable
extend ActiveSupport::Concern
included do
has_paper_trail
end
end

View File

@@ -20,6 +20,8 @@
# fk_rails_... (user_id => users.id) # fk_rails_... (user_id => users.id)
# #
class FiatBalance < ApplicationRecord class FiatBalance < ApplicationRecord
include Trackable
belongs_to :user belongs_to :user
monetize :amount_cents monetize :amount_cents

View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
# This migration creates the `versions` table, the only schema PT requires.
# All other migrations PT provides are optional.
class CreateVersions < ActiveRecord::Migration[6.1]
# The largest text column available in all supported RDBMS is
# 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
# so that MySQL will use `longtext` instead of `text`. Otherwise,
# when serializing very large objects, `text` might not be big enough.
TEXT_BYTES = 1_073_741_823
def change
create_table(:versions) do |t|
t.string(:item_type, { null: false })
t.bigint(:item_id, null: false)
t.string(:event, null: false)
t.string(:whodunnit)
t.text(:object, limit: TEXT_BYTES)
t.datetime(:created_at)
end
add_index(:versions, [:item_type, :item_id])
end
end

12
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_08_16_174637) do ActiveRecord::Schema.define(version: 2021_08_17_233439) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -138,6 +138,16 @@ ActiveRecord::Schema.define(version: 2021_08_16_174637) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end end
create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.bigint "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "balances", "currencies" add_foreign_key "balances", "currencies"

29
erd.svg
View File

@@ -69,8 +69,8 @@
<!-- m_Currency&#45;&gt;m_Balance --> <!-- m_Currency&#45;&gt;m_Balance -->
<g id="edge9" class="edge"> <g id="edge9" class="edge">
<title>m_Currency&#45;&gt;m_Balance</title> <title>m_Currency&#45;&gt;m_Balance</title>
<path fill="none" stroke="black" d="M98.77,-441.41C119.93,-468.12 158.38,-513.63 198,-545.5 201.86,-548.61 205.95,-551.65 210.15,-554.6"/> <path fill="none" stroke="black" d="M142.18,-441.08C149.45,-445.41 156.3,-450.52 162,-456.5 191.43,-487.4 170.07,-513.24 198,-545.5 200.55,-548.44 203.32,-551.25 206.25,-553.93"/>
<polygon fill="black" stroke="black" points="208.6,-557.35 217.82,-559.79 212.14,-552.14 208.6,-557.35"/> <polygon fill="black" stroke="black" points="204.45,-556.54 213.36,-559.94 208.52,-551.73 204.45,-556.54"/>
</g> </g>
<!-- m_Currency&#45;&gt;m_BuyCryptoOrder --> <!-- m_Currency&#45;&gt;m_BuyCryptoOrder -->
<g id="edge6" class="edge"> <g id="edge6" class="edge">
@@ -79,7 +79,7 @@
<polygon fill="black" stroke="black" points="188.23,-456.27 197.76,-455.97 190.13,-450.26 188.23,-456.27"/> <polygon fill="black" stroke="black" points="188.23,-456.27 197.76,-455.97 190.13,-450.26 188.23,-456.27"/>
</g> </g>
<!-- m_SellCryptoOrder --> <!-- m_SellCryptoOrder -->
<g id="node6" class="node"> <g id="node7" class="node">
<title>m_SellCryptoOrder</title> <title>m_SellCryptoOrder</title>
<path fill="none" stroke="black" d="M214.5,-310C214.5,-310 351.5,-310 351.5,-310 357.5,-310 363.5,-316 363.5,-322 363.5,-322 363.5,-393 363.5,-393 363.5,-399 357.5,-405 351.5,-405 351.5,-405 214.5,-405 214.5,-405 208.5,-405 202.5,-399 202.5,-393 202.5,-393 202.5,-322 202.5,-322 202.5,-316 208.5,-310 214.5,-310"/> <path fill="none" stroke="black" d="M214.5,-310C214.5,-310 351.5,-310 351.5,-310 357.5,-310 363.5,-316 363.5,-322 363.5,-322 363.5,-393 363.5,-393 363.5,-399 357.5,-405 351.5,-405 351.5,-405 214.5,-405 214.5,-405 208.5,-405 202.5,-399 202.5,-393 202.5,-393 202.5,-322 202.5,-322 202.5,-316 208.5,-310 214.5,-310"/>
<text text-anchor="start" x="238" y="-392.2" font-family="Arial Bold" font-size="11.00">SellCryptoOrder</text> <text text-anchor="start" x="238" y="-392.2" font-family="Arial Bold" font-size="11.00">SellCryptoOrder</text>
@@ -102,7 +102,7 @@
<polygon fill="black" stroke="black" points="194.78,-387.84 202.45,-382.16 192.92,-381.82 194.78,-387.84"/> <polygon fill="black" stroke="black" points="194.78,-387.84 202.45,-382.16 192.92,-381.82 194.78,-387.84"/>
</g> </g>
<!-- m_StakeOrder --> <!-- m_StakeOrder -->
<g id="node7" class="node"> <g id="node8" class="node">
<title>m_StakeOrder</title> <title>m_StakeOrder</title>
<path fill="none" stroke="black" d="M223,-185C223,-185 343,-185 343,-185 349,-185 355,-191 355,-197 355,-197 355,-268 355,-268 355,-274 349,-280 343,-280 343,-280 223,-280 223,-280 217,-280 211,-274 211,-268 211,-268 211,-197 211,-197 211,-191 217,-185 223,-185"/> <path fill="none" stroke="black" d="M223,-185C223,-185 343,-185 343,-185 349,-185 355,-191 355,-197 355,-197 355,-268 355,-268 355,-274 349,-280 343,-280 343,-280 223,-280 223,-280 217,-280 211,-274 211,-268 211,-268 211,-197 211,-197 211,-191 217,-185 223,-185"/>
<text text-anchor="start" x="251" y="-267.2" font-family="Arial Bold" font-size="11.00">StakeOrder</text> <text text-anchor="start" x="251" y="-267.2" font-family="Arial Bold" font-size="11.00">StakeOrder</text>
@@ -137,8 +137,25 @@
<text text-anchor="start" x="218" y="-95.5" font-family="Arial" font-size="10.00">user_id </text> <text text-anchor="start" x="218" y="-95.5" font-family="Arial" font-size="10.00">user_id </text>
<text text-anchor="start" x="253" y="-95.5" font-family="Arial Italic" font-size="10.00" fill="#999999">integer (8) FK</text> <text text-anchor="start" x="253" y="-95.5" font-family="Arial Italic" font-size="10.00" fill="#999999">integer (8) FK</text>
</g> </g>
<!-- m_PaperTrail::Version -->
<g id="node6" class="node">
<title>m_PaperTrail::Version</title>
<path fill="none" stroke="black" d="M21,-471C21,-471 141,-471 141,-471 147,-471 153,-477 153,-483 153,-483 153,-554 153,-554 153,-560 147,-566 141,-566 141,-566 21,-566 21,-566 15,-566 9,-560 9,-554 9,-554 9,-483 9,-483 9,-477 15,-471 21,-471"/>
<text text-anchor="start" x="28.5" y="-553.2" font-family="Arial Bold" font-size="11.00">PaperTrail::Version</text>
<polyline fill="none" stroke="black" points="9,-546 153,-546 "/>
<text text-anchor="start" x="16" y="-532.5" font-family="Arial" font-size="10.00">event </text>
<text text-anchor="start" x="44" y="-532.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string</text>
<text text-anchor="start" x="16" y="-519.5" font-family="Arial" font-size="10.00">item_id </text>
<text text-anchor="start" x="51" y="-519.5" font-family="Arial Italic" font-size="10.00" fill="#999999">integer (8)</text>
<text text-anchor="start" x="16" y="-506.5" font-family="Arial" font-size="10.00">item_type </text>
<text text-anchor="start" x="62" y="-506.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string</text>
<text text-anchor="start" x="16" y="-493.5" font-family="Arial" font-size="10.00">object </text>
<text text-anchor="start" x="46" y="-493.5" font-family="Arial Italic" font-size="10.00" fill="#999999">text</text>
<text text-anchor="start" x="16" y="-480.5" font-family="Arial" font-size="10.00">whodunnit </text>
<text text-anchor="start" x="64" y="-480.5" font-family="Arial Italic" font-size="10.00" fill="#999999">string</text>
</g>
<!-- m_User --> <!-- m_User -->
<g id="node8" class="node"> <g id="node9" class="node">
<title>m_User</title> <title>m_User</title>
<path fill="none" stroke="black" d="M12,-172C12,-172 150,-172 150,-172 156,-172 162,-178 162,-184 162,-184 162,-281 162,-281 162,-287 156,-293 150,-293 150,-293 12,-293 12,-293 6,-293 0,-287 0,-281 0,-281 0,-184 0,-184 0,-178 6,-172 12,-172"/> <path fill="none" stroke="black" d="M12,-172C12,-172 150,-172 150,-172 156,-172 162,-178 162,-184 162,-184 162,-281 162,-281 162,-287 156,-293 150,-293 150,-293 12,-293 12,-293 6,-293 0,-287 0,-281 0,-281 0,-184 0,-184 0,-178 6,-172 12,-172"/>
<text text-anchor="start" x="66.5" y="-280.2" font-family="Arial Bold" font-size="11.00">User</text> <text text-anchor="start" x="66.5" y="-280.2" font-family="Arial Bold" font-size="11.00">User</text>
@@ -188,7 +205,7 @@
<polygon fill="black" stroke="black" points="201.83,-235.65 210.83,-232.5 201.83,-229.35 201.83,-235.65"/> <polygon fill="black" stroke="black" points="201.83,-235.65 210.83,-232.5 201.83,-229.35 201.83,-235.65"/>
</g> </g>
<!-- m_UserDocument --> <!-- m_UserDocument -->
<g id="node9" class="node"> <g id="node10" class="node">
<title>m_UserDocument</title> <title>m_UserDocument</title>
<path fill="none" stroke="black" d="M223,-0.5C223,-0.5 343,-0.5 343,-0.5 349,-0.5 355,-6.5 355,-12.5 355,-12.5 355,-44.5 355,-44.5 355,-50.5 349,-56.5 343,-56.5 343,-56.5 223,-56.5 223,-56.5 217,-56.5 211,-50.5 211,-44.5 211,-44.5 211,-12.5 211,-12.5 211,-6.5 217,-0.5 223,-0.5"/> <path fill="none" stroke="black" d="M223,-0.5C223,-0.5 343,-0.5 343,-0.5 349,-0.5 355,-6.5 355,-12.5 355,-12.5 355,-44.5 355,-44.5 355,-50.5 349,-56.5 343,-56.5 343,-56.5 223,-56.5 223,-56.5 217,-56.5 211,-50.5 211,-44.5 211,-44.5 211,-12.5 211,-12.5 211,-6.5 217,-0.5 223,-0.5"/>
<text text-anchor="start" x="241.5" y="-43.7" font-family="Arial Bold" font-size="11.00">UserDocument</text> <text text-anchor="start" x="241.5" y="-43.7" font-family="Arial Bold" font-size="11.00">UserDocument</text>

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB