Skip to content

Commit 4c62bd3

Browse files
authored
feat: Track history of model changes (#161)
* feat: Track history of model changes * Hound fixes
1 parent cd02405 commit 4c62bd3

22 files changed

+244
-49
lines changed

.rubocop-shared.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Style/Documentation:
5151
Style/GuardClause:
5252
Enabled: false
5353

54+
Style/HashSyntax:
55+
Exclude:
56+
- db/migrate/*
57+
5458
Style/PercentLiteralDelimiters:
5559
Enabled: false
5660

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ gem 'bootstrap', '~> 4.3.1'
6868
# Markdown parsing
6969
gem 'redcarpet'
7070

71-
# Model validation
71+
# Model extensions
7272
gem 'strip_attributes'
7373
gem 'validate_url'
74+
gem 'audited', '~> 4.7'
7475

7576
# Background job processing
7677
gem 'sidekiq', '< 6'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ GEM
5050
archive-zip (0.12.0)
5151
io-like (~> 0.3.0)
5252
arel (9.0.0)
53+
audited (4.8.0)
54+
activerecord (>= 4.0, < 5.3)
5355
autoprefixer-rails (9.5.1.1)
5456
execjs
5557
aws-eventstream (1.0.3)
@@ -457,6 +459,7 @@ PLATFORMS
457459

458460
DEPENDENCIES
459461
ajax-datatables-rails (~> 0.4.0)
462+
audited (~> 4.7)
460463
aws-sdk-s3
461464
better_errors
462465
binding_of_caller

app/helpers/audit_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module AuditHelper
2+
def display_audit_value(value, field)
3+
return "(none)" if value.blank?
4+
return Questionnaire::POSSIBLE_ACC_STATUS[value] if field == "acc_status"
5+
return BusList.find(value)&.name || value if field == "bus_list_id"
6+
return User.find(value)&.full_name || value if field == "checked_in_by_id"
7+
return value.join(", ") if value.is_a? Array
8+
return display_datetime(value, relative: false) if value.is_a? Time
9+
10+
value
11+
end
12+
end

app/helpers/hackathon_manager_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def acc_status_class(acc_status)
9292
end
9393

9494
def display_datetime(datetime, opts = {})
95+
opts[:relative] = true if opts[:relative].nil?
96+
9597
formatted = ""
96-
if Time.now - datetime < 5.hours
98+
if Time.now - datetime < 5.hours && opts[:relative]
9799
formatted << "#{time_ago_in_words(datetime, include_seconds: true)} ago"
98100
else
99101
format = datetime.year == Time.now.year ? "%b %-d <small>at %I:%M %P</small>" : "%b %-d, %Y <small>at %I:%M %P</small>"

app/models/bus_list.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class BusList < ApplicationRecord
2+
audited
3+
24
validates_presence_of :name, :capacity
35
validates_uniqueness_of :name
46

app/models/message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Message < ApplicationRecord
2+
audited
3+
24
self.inheritance_column = nil # To enable using "type" field
35

46
validates_presence_of :name, :subject, :template

app/models/questionnaire.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Questionnaire < ApplicationRecord
2+
audited
3+
24
include ActiveModel::Dirty
35
include DeletableAttachment
46

app/models/school.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class School < ApplicationRecord
2+
audited
3+
24
validates_presence_of :name
35

46
validates_uniqueness_of :name

app/models/trackable_tag.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class TrackableTag < ApplicationRecord
2+
audited
3+
24
validates_presence_of :name
35
validates_uniqueness_of :name
46
strip_attributes

0 commit comments

Comments
 (0)