-
Notifications
You must be signed in to change notification settings - Fork 895
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 #556 from airblade/set_paper_trail_whodunnit
Control the order of `set_paper_trail_whodunnit` callback
- Loading branch information
Showing
5 changed files
with
74 additions
and
20 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
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,20 +1,36 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
|
||
# Some applications and libraries modify `current_user`. Their changes need | ||
# to be reflected in `whodunnit`, so the `set_paper_trail_whodunnit` below | ||
# must happen after this. | ||
before_filter :modify_current_user | ||
|
||
# Going forward, we'll no longer add this `before_filter`, requiring people | ||
# to do so themselves, allowing them to control the order in which this filter | ||
# happens. | ||
before_filter :set_paper_trail_whodunnit | ||
|
||
def rescue_action(e) | ||
raise e | ||
end | ||
|
||
# Returns id of hypothetical current user | ||
def current_user | ||
@current_user ||= OpenStruct.new(:id => 153).tap do |obj| | ||
# Invoking `id` returns the `object_id` value in Ruby18 unless specifically overwritten | ||
def obj.id; 153; end if RUBY_VERSION < '1.9' | ||
end | ||
@current_user | ||
end | ||
|
||
def info_for_paper_trail | ||
{:ip => request.remote_ip, :user_agent => request.user_agent} | ||
end | ||
|
||
|
||
private | ||
|
||
def modify_current_user | ||
@current_user = OpenStruct.new(:id => 153).tap do |obj| | ||
# Support ruby 1.8, in which `id` returns the `object_id` | ||
# unless specifically overwritten. | ||
def obj.id; 153; end if RUBY_VERSION < '1.9' | ||
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