Skip to content

Commit

Permalink
Merge pull request #473 from latis-sw/feature/fix-blank-whodunnits
Browse files Browse the repository at this point in the history
Make a new concern to handle the version user
  • Loading branch information
andersodt authored and GitHub Enterprise committed Aug 17, 2017
2 parents 046adad + 3f578a6 commit 8782e8e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/models/concerns/version_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module VersionUser
extend ActiveSupport::Concern

module ClassMethods
def version_user(version)
version.whodunnit.nil? ? 'N/A' : User.find(version.whodunnit).internet_id
end
end
end
3 changes: 2 additions & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# models/group.rb
class Group < ApplicationRecord
include VersionUser
has_paper_trail
after_save :version_history
before_destroy :version_history
Expand Down Expand Up @@ -65,7 +66,7 @@ def version_history
self.versions.each do |v|
g = v.reify unless v.event.equal? "create"
h.concat "<b>What Happened: </b> #{v.event} <br/>"
h.concat "<b>Who Made It: </b> #{User.find(v.whodunnit).internet_id}<br/>"
h.concat "<b>Who Made It: </b> #{self.class.version_user(v)}<br/>"
h.concat "<b>Previous Name: </b> #{g ? g.name : 'N/A'}<br/>"
h.concat "<b>Previous Description: </b> #{g ? g.description : 'N/A'}<br/>"
h.concat "<b>Date of Change: </b> #{g ? g.updated_at : 'N/A'}<br/>"
Expand Down
3 changes: 2 additions & 1 deletion app/models/transfer_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#

class TransferRequest < ApplicationRecord
include VersionUser
has_paper_trail
after_save :version_history
before_destroy :version_history
Expand Down Expand Up @@ -81,7 +82,7 @@ def version_history
self.versions.each do |v|
g = v.reify #unless v.event.equal? "create"
h.concat "<b>What Happened: </b> #{v.event} <br/>"
h.concat "<b>Who Made It: </b> #{User.find(v.whodunnit).internet_id}<br/>"
h.concat "<b>Who Made It: </b> #{self.class.version_user(v)}<br/>"
h.concat "<b>Previous Status: </b> #{g ? g.status : 'N/A'}<br/>"
h.concat "<br/><br/>"
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
require 'uri'
class Url < ApplicationRecord
include VersionUser
has_paper_trail :ignore => [:total_clicks]
after_save :version_history
before_destroy :version_history
Expand Down Expand Up @@ -124,7 +125,7 @@ def version_history
self.versions.each do |v|
g = v.reify unless v.event.equal? "create"
h.concat "<b>What Happened: </b> #{v.event} <br/>"
h.concat "<b>Who Made It: </b> #{User.find(v.whodunnit).internet_id}<br/>"
h.concat "<b>Who Made It: </b> #{self.class.version_user(v)}<br/>"
h.concat "<b>Previous URL: </b> #{g ? g.url : 'N/A'}<br/>"
h.concat "<b>Previous Keyword: </b> #{g ? g.keyword : 'N/A'}<br/>"
h.concat "<b>Previous Group Name: </b> #{g && g.group ? g.group.name : 'N/A(Group doesnt exist)'}<br/>"
Expand Down

0 comments on commit 8782e8e

Please sign in to comment.