-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/customable authorized users only error response #869
Changes from 1 commit
5f8e4db
6b1da15
82590f9
fef2bf8
68facd4
ed4ebc3
9dcc414
5ae32a8
1b141ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ module ClassMethods | |
# blogger_signed_in? # Checks whether there is either a user or an admin signed in | ||
# current_blogger # Currently signed in user or admin | ||
# current_bloggers # Currently signed in user and admin | ||
# render_authenticate_blogger_error # Render error unless user or admin are signed in | ||
# render_authenticate_error # Render error unless user or admin are signed in | ||
# | ||
# Use: | ||
# before_action :authenticate_blogger! # Redirects unless either a user or an admin are authenticated | ||
|
@@ -39,7 +39,7 @@ def authenticate_#{group_name}!(favourite=nil, opts={}) | |
end | ||
|
||
unless current_#{group_name} | ||
render_authenticate_#{group_name}_error | ||
render_authenticate_error | ||
end | ||
end | ||
end | ||
|
@@ -66,14 +66,14 @@ def current_#{group_name.to_s.pluralize} | |
end.compact | ||
end | ||
|
||
def render_authenticate_#{group_name}_error | ||
def render_authenticate_error | ||
return render json: { | ||
errors: [I18n.t('devise.failure.unauthenticated')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have resolved conflict about error message. |
||
}, status: 401 | ||
end | ||
|
||
if respond_to?(:helper_method) | ||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?", "render_authenticate_#{group_name}_error" | ||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?", "render_authenticate_error" | ||
end | ||
METHODS | ||
end | ||
|
@@ -103,8 +103,7 @@ def log_process_action(payload) | |
# current_admin # Current signed in admin | ||
# user_session # Session data available only to the user scope | ||
# admin_session # Session data available only to the admin scope | ||
# render_authenticate_user_error # Render error unless user is signed in | ||
# render_authenticate_admin_error # Render error unless admin is signed in | ||
# render_authenticate_error # Render error unless user or admin is signed in | ||
# | ||
# Use: | ||
# before_action :authenticate_user! # Tell devise to use :user map | ||
|
@@ -116,7 +115,7 @@ def self.define_helpers(mapping) #:nodoc: | |
class_eval <<-METHODS, __FILE__, __LINE__ + 1 | ||
def authenticate_#{mapping}! | ||
unless current_#{mapping} | ||
render_authenticate_#{mapping}_error | ||
render_authenticate_error | ||
end | ||
end | ||
|
||
|
@@ -132,7 +131,7 @@ def #{mapping}_session | |
current_#{mapping} && warden.session(:#{mapping}) | ||
end | ||
|
||
def render_authenticate_#{mapping}_error | ||
def render_authenticate_error | ||
return render json: { | ||
errors: [I18n.t('devise.failure.unauthenticated')] | ||
}, status: 401 | ||
|
@@ -141,7 +140,7 @@ def render_authenticate_#{mapping}_error | |
|
||
ActiveSupport.on_load(:action_controller) do | ||
if respond_to?(:helper_method) | ||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session", "render_authenticate_#{mapping}_error" | ||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session", "render_authenticate_error" | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,15 +76,15 @@ class DemoGroupControllerTest < ActionDispatch::IntegrationTest | |
end | ||
|
||
it 'should define render_authenticate_user_error' do | ||
assert @controller.methods.include?(:render_authenticate_user_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
end | ||
|
||
it 'should define render_authenticate_mang_error' do | ||
assert @controller.methods.include?(:render_authenticate_mang_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
end | ||
|
||
it 'should define render_authenticate_member_error' do | ||
assert @controller.methods.include?(:render_authenticate_member_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These three tests now make less sense: their |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,11 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest | |
end | ||
|
||
it 'should define render_authenticate_user_error' do | ||
assert @controller.methods.include?(:render_authenticate_user_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
end | ||
|
||
it 'should define render_authenticate_mang_error' do | ||
assert @controller.methods.include?(:render_authenticate_mang_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here: The same note about "tests' contents do not match their descriptions". |
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,11 +49,11 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest | |
end | ||
|
||
it 'should define render_authenticate_user_error' do | ||
assert @controller.methods.include?(:render_authenticate_user_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
end | ||
|
||
it 'should define render_authenticate_mang_error' do | ||
assert @controller.methods.include?(:render_authenticate_mang_error) | ||
assert @controller.methods.include?(:render_authenticate_error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (And here, too.) Perhaps there's more investigation to be made? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Or, rather, renaming some tests?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry 😱 |
||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the method name to
render_authenticate_error
.Exists error-render methods are using simple method name like
render_create_error
.They don't include #{group_name} and #{mapping} like
render_create_error
.So new method name also don't include these.
https://github.com/lynndylanhurley/devise_token_auth#registrations-controller