Skip to content
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

Conversation

abeyuya
Copy link
Contributor

@abeyuya abeyuya commented Apr 14, 2017

I have added new methods for customize error response when "Authorized users only".

# 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_#{mapping}_error # Render error if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this docs line needs to be 2 lines (one for each generated mapping).

And the comment at the end of the line seems unfinished.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean: have two lines, with ending comments like these:

  • # Render error unless user is signed in
  • # Render error unless admin is signed in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olleolleolle Thank you for your review.
You are right. I will modify the comment soom.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was fast.

@abeyuya
Copy link
Contributor Author

abeyuya commented May 29, 2017

When will this PR be merged? 🤔

@booleanbetrayal
Copy link
Collaborator

@abeyuya - There are conflicts and there is also an issue where the error response is not pluralized to match the prior string. Ie - "user" vs "users" (expected).

@@ -68,7 +68,7 @@ def current_#{group_name.to_s.pluralize}

def render_authenticate_#{group_name}_error
return render json: {
errors: ["Authorized #{group_name} only."]
errors: [I18n.t('devise.failure.unauthenticated')]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have resolved conflict about error message.

end

it 'should define render_authenticate_member_error' do
assert @controller.methods.include?(:render_authenticate_member_error)
assert @controller.methods.include?(:render_authenticate_error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three tests now make less sense: their it descriptions talk about method names that are not checked for existence.

@@ -66,14 +66,14 @@ def current_#{group_name.to_s.pluralize}
end.compact
end

def render_authenticate_#{group_name}_error
def render_authenticate_error
Copy link
Contributor Author

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

end

it 'should define render_authenticate_mang_error' do
assert @controller.methods.include?(:render_authenticate_mang_error)
assert @controller.methods.include?(:render_authenticate_error)
Copy link
Contributor

Choose a reason for hiding this comment

The 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

it 'should define render_authenticate_mang_error' do
assert @controller.methods.include?(:render_authenticate_mang_error)
assert @controller.methods.include?(:render_authenticate_error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And here, too.)

Perhaps there's more investigation to be made?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Or, rather, renaming some tests?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry 😱
I will modify bad tests.

@zachfeldman
Copy link
Contributor

@booleanbetrayal have a moment to finish review of this PR? All tests pass and no conflicts :)

Copy link
Contributor

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks grand.

@zachfeldman
Copy link
Contributor

Going to merge it then!

@zachfeldman zachfeldman merged commit 9fe98a9 into lynndylanhurley:master Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants