mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
- Add JS controller to send delete requests. - Add resource controller to destroy items. - Add authorisation check to abilities. - Update fees after removing line item.
25 lines
541 B
Ruby
25 lines
541 B
Ruby
class LineItemsController < Spree::BaseController
|
|
respond_to :json
|
|
|
|
def destroy
|
|
item = Spree::LineItem.find(params[:id])
|
|
authorize! :destroy, item
|
|
destroy_with_lock item
|
|
respond_with(item)
|
|
end
|
|
|
|
# Override default which just redirects
|
|
# See Spree::BaseController and Spree::Core::ControllerHelpers::Auth
|
|
def unauthorized
|
|
render text: '', status: 403
|
|
end
|
|
|
|
def destroy_with_lock(item)
|
|
order = item.order
|
|
order.with_lock do
|
|
item.destroy
|
|
order.update_distribution_charge!
|
|
end
|
|
end
|
|
end
|