This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from SumOfUs/add-papertrail
Adding paper_trail auditing to a number of models for change tracking.
- Loading branch information
Showing
35 changed files
with
221 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
ActiveAdmin.register Action do | ||
actions :all, except: [:new, :edit] | ||
|
||
sidebar 'Previous Versions', only: :show do | ||
attributes_table_for action do | ||
row :versions do | ||
render '/versions/versions_link', model: action, model_name: 'action' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
ActiveAdmin.register Image do | ||
actions :all, except: [:new, :edit, :destroy] | ||
|
||
sidebar 'Previous Versions', only: :show do | ||
attributes_table_for image do | ||
row :versions do | ||
render '/versions/versions_link', model: image, model_name: 'image' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
ActiveAdmin.register Language do | ||
permit_params :code, :name | ||
|
||
sidebar 'Previous Versions', only: :show do | ||
attributes_table_for language do | ||
row :versions do | ||
render '/versions/versions_link', model: language, model_name: 'language' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
ActiveAdmin.register Link do | ||
permit_params :url, :title, :date, :source, :page_id | ||
permit_params :url, :title, :date, :source, :link_id | ||
|
||
sidebar 'Previous Versions', only: :show do | ||
attributes_table_for link do | ||
row :versions do | ||
render '/versions/versions_link', model: link, model_name: 'link' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
ActiveAdmin.register Member do | ||
permit_params :email, :country, :first_name, :last_name, :city, :postal, :title, :address1, :address2, :actionkit_user_id | ||
permit_params :email, :country, :first_name, :last_name, :city, :postal, :title, :address1, :address2, :actionkit_member_id | ||
actions :all, except: [:destroy] | ||
|
||
sidebar 'Previous Versions', only: :show do | ||
attributes_table_for member do | ||
row :versions do | ||
render '/versions/versions_link', model: member, model_name: 'member' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class VersionsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def show | ||
@versions = Versions::VersionFinder.find_versions(model: params[:model], id: params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class ActionkitPage < ActiveRecord::Base | ||
belongs_to :page | ||
has_paper_trail | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Image < ActiveRecord::Base | ||
has_paper_trail | ||
|
||
has_attached_file :content, | ||
styles: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
span.changeset | ||
- if changes.respond_to? :each_key | ||
- changes.each_key do |key| | ||
- if key != 'updated_at' | ||
table.table-striped.table | ||
thead | ||
th colspan=2 = key.titleize | ||
tr | ||
td From | ||
td To | ||
tr | ||
td.versions__changeset-removed | ||
= changes[key][0] | ||
td.versions__changeset-added | ||
= changes[key][1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= link_to "There are #{model.versions.length} total versions of this #{model_name}. Click here to view.", controller: '/versions', action: 'show', model: model_name, id: model.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.row | ||
.col-md-12 | ||
h2 = t('versions.shown_below', {count: @versions.length, model_name: params[:model]}) | ||
|
||
table.table-striped.table | ||
thead | ||
tr | ||
th Version ID | ||
th Version created at | ||
th Differences from previous version | ||
th Who made the change? | ||
tbody | ||
- @versions.each do |version| | ||
tr | ||
td=version.index + 1 | ||
td=version.created_at | ||
td=version.event == 'create' ? 'Created' : render('versions/changeset', changes: version.changeset) | ||
td | ||
- if version.whodunnit | ||
= User.find(version.whodunnit).email | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20151124153734_add_object_changes_to_versions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AddObjectChangesToVersions < ActiveRecord::Migration | ||
|
||
# The largest text column available in all supported RDBMS. | ||
# See `create_versions.rb` for details. | ||
TEXT_BYTES = 1_073_741_823 | ||
|
||
def change | ||
add_column :versions, :object_changes, :text, limit: TEXT_BYTES | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Versions | ||
class VersionFinder | ||
class << self | ||
def find_versions(model:, id:) | ||
versioned_models[model.to_sym].find(id.to_i).versions | ||
end | ||
|
||
def versioned_models | ||
{ | ||
action: Action, | ||
actionkit_page: ActionkitPage, | ||
campaign: Campaign, | ||
form: Form, | ||
form_element: FormElement, | ||
image: Image, | ||
language: Language, | ||
link: Link, | ||
liquid_layout: LiquidLayout, | ||
liquid_partial: LiquidPartial, | ||
member: Member, | ||
page: Page, | ||
tag: Tag, | ||
user: User | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters