-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
Current
model as attributes singleton
This uses `ActiveSupport::CurrentAttributes` to track the current user across the request.
- Loading branch information
Showing
4 changed files
with
15 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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
# Requires a user to be logged in through GDS SSO for any action. | ||
# Requires a user to be logged in through GDS SSO for any action, and keeps track of the current | ||
# user through `Current`. | ||
module Authentication | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include GDS::SSO::ControllerMethods | ||
|
||
before_action :authenticate_user! | ||
before_action :authenticate_user!, :set_current | ||
end | ||
|
||
private | ||
|
||
def set_current | ||
Current.user = current_user | ||
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,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user | ||
end |