-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: install papertrail * feat: add papertrail to models * fix: skip attributes set only by system * feat: Add audit cleaner worker to periodically clean DB * fix: structure.sql for tests
- Loading branch information
Showing
27 changed files
with
180 additions
and
5 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
2.5.7 |
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 |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
# | ||
|
||
class EntryRequest < ApplicationRecord | ||
has_paper_trail | ||
|
||
belongs_to :evaluation | ||
belongs_to :user | ||
|
||
|
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
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
# | ||
|
||
class Post < ApplicationRecord | ||
has_paper_trail | ||
belongs_to :post_type | ||
belongs_to :membership | ||
|
||
|
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
# | ||
|
||
class SviePostRequest < ApplicationRecord | ||
has_paper_trail | ||
|
||
belongs_to :user | ||
|
||
def inside_member? | ||
|
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,8 @@ | ||
class AuditCleanerWorker | ||
include Sidekiq::Worker | ||
|
||
def perform(*args) | ||
# Audit logs can blow up database so we only keep the last three months worth of logs | ||
PaperTrail::Version.where('created_at < ?', 3.months.ago).delete_all | ||
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,9 +1,15 @@ | ||
schedule_file = "config/schedule.yml" | ||
|
||
|
||
Sidekiq.configure_server do |config| | ||
config.redis = { url: ENV.fetch('REDIS_URL') } | ||
end | ||
|
||
if File.exists?(schedule_file) && Sidekiq.server? | ||
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file) | ||
config.on(:startup) do | ||
schedule_file = "config/schedule.yml" | ||
|
||
if File.exist?(schedule_file) | ||
schedule = YAML.load_file(schedule_file) | ||
|
||
Sidekiq::Cron::Job.load_from_hash!(schedule) | ||
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,9 @@ | ||
metascore: | ||
cron: "00 04 * * *" | ||
class: "MetascoreEveryone" | ||
|
||
audit_clean: | ||
cron: "0 0 * * *" | ||
class: "AuditCleanerWorker" | ||
description: "Cleans up audit log table so its not bloating the database" | ||
enabled: true |
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,31 @@ | ||
# This migration creates the `versions` table, the only schema PT requires. | ||
# All other migrations PT provides are optional. | ||
class CreateVersions < ActiveRecord::Migration[6.0] | ||
|
||
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.json :object | ||
t.json :object_changes | ||
|
||
# Known issue in MySQL: fractional second precision | ||
# ------------------------------------------------- | ||
# | ||
# MySQL timestamp columns do not support fractional seconds unless | ||
# defined with "fractional seconds precision". MySQL users should manually | ||
# add fractional seconds precision to this migration, specifically, to | ||
# the `created_at` column. | ||
# (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html) | ||
# | ||
# MySQL users should also upgrade to at least rails 4.2, which is the first | ||
# version of ActiveRecord with support for fractional seconds in MySQL. | ||
# (https://github.com/rails/rails/pull/14359) | ||
# | ||
t.datetime :created_at | ||
end | ||
add_index :versions, %i(item_type item_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
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,27 @@ | ||
require 'rails_helper' | ||
RSpec.describe AuditCleanerWorker, type: :worker do | ||
it 'deletes old versions' do | ||
with_versioning do | ||
Timecop.travel '2024-04-19' | ||
user = create(:user) | ||
user.update(nickname: 'asd') | ||
expect(PaperTrail::Version.count).to be > 2 | ||
|
||
Timecop.travel '2024-08-19' | ||
AuditCleanerWorker.new.perform | ||
expect(PaperTrail::Version.count).to be 0 | ||
end | ||
end | ||
|
||
it 'keeps versions younger than 3 months' do | ||
with_versioning do | ||
Timecop.travel '2024-04-19' | ||
user = create(:user) | ||
user.update(nickname: 'asd') | ||
expect(PaperTrail::Version.count).to be > 2 | ||
|
||
Timecop.travel '2024-05-19' | ||
expect { AuditCleanerWorker.new.perform }.not_to change { PaperTrail::Version.count } | ||
end | ||
end | ||
end |