Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

fix(hasRoleOrRestrict): usage w/ get method returns correct result #28

Merged

Conversation

meatwallace
Copy link
Contributor

@meatwallace meatwallace commented Sep 18, 2017

previously the hasRoleOrRestrict hook failed to return data in the expected format when used on a Service#get method due to incorrect handling of the result of the hook's internal call to Service#find. as Service#find returns an object with a "data" property that is always an array, we can safely check the nested value and correctly determine if the pseudo-get method call was successful.

any application code hacking around the issue by knowingly pulling the nested "data" prop from the result will now break.

previously the hasRoleOrRestrict hook failed to return data in the expected format when used on a
Service#get method due to incorrect handling of the result of the internal call to Service#find. as
Service#find returns an object with a "data" property that is always an array, we can safely check
the nested value and correctly determine if the pseudo-get method call was successful.

any application code hacking around the issue by knowingly pulling the nested "data" prop from the
result will now break.
daffl
daffl previously requested changes Oct 11, 2017
Copy link
Member

@daffl daffl left a comment

Choose a reason for hiding this comment

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

Thank you @meatwallace. One thing that I think has to be changed, otherwise this makes sense.

@@ -54,8 +54,8 @@ export default function (options = {}) {
}

return hook.service.find({ query }, params).then(results => {
if (hook.method === 'get' && Array.isArray(results) && results.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

This can still also be an Array (e.g. if pagination is disabled), so I think we need to handle both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, it's been so long and I'm not all that familiar with Feathers' internals - do you mean that both results can be an array as well as results.data? Does this need to be handled in both this case and the case on line #135?

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is that the result can be either a plain array or a pagination object.

@daffl daffl dismissed their stale review April 20, 2018 05:27

Fixed manually

@daffl daffl merged commit 5286bb8 into feathersjs-ecosystem:master Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants