-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Respect current ability in users controllers #3732
Respect current ability in users controllers #3732
Conversation
Admin user's index was displaying a list with all users even if current ability states it shouldn't be accessible Now only users that are allowed to be accessed will be displayed on the list
Admins users able to create and update a user could inject any stock location id to user params, and the user would have it assigned to it even if the admin don't have the ability to manage it.
Admins users able to create and update a user could inject any role id to user params, and the user would have it assigned to it even if the admin don't have the ability to manage it.
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.
@igorbp thanks for these fixes 🎉
It looks good to me, I left only one question about a change that I'm not 100% sure about.
if user_params[:stock_location_ids] | ||
@user.stock_locations = | ||
Spree::StockLocation.accessible_by(current_ability).where(id: user_params[:stock_location_ids]) | ||
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 think the behavior was slightly changed. The old code always set the user stock locations, also when the parameter was not present, in that case by stock locations to an empty array. This does not happen anymore here. Is this change wanted?
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.
This is a good question. I took this decision because with these changes admins that can't manage stock locations would remove user's stock locations since the params wouldn't be there.
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.
Thanks so much @igorbp, looks great!
Description
Admin users were able to see users, roles, and stock locations that they don't have permission to manage in admin users index and form. This fixes those authorization inconsistencies reported in issue #3668.
:spree_role_ids
and:stock_locations_ids
params were still being assigned to the user.Checklist: