Replies: 2 comments
-
|
My findings:
Here's a working example batch_action :publish, confirm: "Are you sure?", if: proc { authorized? :publish, Payments::Product } do |ids, *args|
Payments::Product.transaction do
Payments::Product.accessible_by(active_admin_authorization.cancan_ability, :publish).where(id: ids).
find_each(batch_size: 10) { |product| product.update!(published: true) }
end
redirect_back fallback_location: collection_path(params.permit(q: {})), alert: "Published successdfully!"
endThe docs are misleading https://activeadmin.info/9-batch-actions.html#creating-your-own |
Beta Was this translation helpful? Give feedback.
-
|
@heaven thank you. Fixing this as a bug and/or a documentation update will be dependent on your contribution. We are open to a PR to resolve it. Using I'm not familiar with CanCanCan, sorry. I use Pundit. I don't see any issue doing that without the helper since that is valid. I've done both. I don't think the documentation is misleading in that it's meant to handle every possibility either. I would suggest adding an example to use a manual query as another option in the docs. The other would be for you to review what the issue is with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the initializer, we set the ability class explicitly, which is used to authorize most of the UI
But when adding bulk actions, the ability is "Ability", which is wrong. And the actions don't work properly. The
current_abilityisAbilityin both places. Therefore, neithercan?norbatch_action_collectionworks properly (the latter adds this to the queryAND (TRUE=FALSE) AND).Expected behavior
Should use the ability defined in the initializer.
Actual behavior
The action runs in the wrong context, improperly authorized.
How to reproduce
Add a batch action in an application that has multiple ability classes, where the
Abilityone is not intended for Admin users.Beta Was this translation helpful? Give feedback.
All reactions