mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Merge pull request #3394 from mkllnk/3021-update-soft-delete
[Spree upgrade] 3021 update soft delete
This commit is contained in:
@@ -78,8 +78,13 @@ Spree::Admin::ProductsController.class_eval do
|
||||
params[:q][:deleted_at_null] ||= "1"
|
||||
|
||||
params[:q][:s] ||= "name asc"
|
||||
|
||||
@search = Spree::Product.ransack(params[:q]) # this line is modified - hit Spree::Product instead of super, avoiding cancan error for fetching records with block permissions via accessible_by
|
||||
# The next line is modified.
|
||||
# Hit Spree::Product instead of super, avoiding cancan error for fetching
|
||||
# records with block permissions via accessible_by.
|
||||
@collection = Spree::Product
|
||||
@collection = @collection.with_deleted if params[:q].delete(:deleted_at_null).blank?
|
||||
# @search needs to be defined as this is passed to search_form_for
|
||||
@search = @collection.ransack(params[:q])
|
||||
@collection = @search.result.
|
||||
managed_by(spree_current_user). # this line is added to the original spree code!!!!!
|
||||
group_by_products_id.
|
||||
|
||||
@@ -10,8 +10,11 @@ Spree::Admin::VariantsController.class_eval do
|
||||
|
||||
def destroy
|
||||
@variant = Spree::Variant.find(params[:id])
|
||||
@variant.delete # This line changed, as well as removal of following conditional
|
||||
flash[:success] = I18n.t('notice_messages.variant_deleted')
|
||||
if VariantDeleter.new.delete(@variant) # This line changed
|
||||
flash[:success] = Spree.t('notice_messages.variant_deleted')
|
||||
else
|
||||
flash[:success] = Spree.t('notice_messages.variant_not_deleted')
|
||||
end
|
||||
|
||||
respond_with(@variant) do |format|
|
||||
format.html { redirect_to admin_product_variants_url(params[:product_id]) }
|
||||
|
||||
@@ -33,7 +33,7 @@ Spree::Api::ProductsController.class_eval do
|
||||
authorize! :delete, Spree::Product
|
||||
@product = find_product(params[:product_id])
|
||||
authorize! :delete, @product
|
||||
@product.delete
|
||||
@product.destroy
|
||||
respond_with(@product, :status => 204)
|
||||
end
|
||||
|
||||
@@ -56,8 +56,8 @@ Spree::Api::ProductsController.class_eval do
|
||||
def product_scope
|
||||
if current_api_user.has_spree_role?("admin") || current_api_user.enterprises.present? # This line modified
|
||||
scope = Spree::Product
|
||||
unless params[:show_deleted]
|
||||
scope = scope.not_deleted
|
||||
if params[:show_deleted]
|
||||
scope = scope.with_deleted
|
||||
end
|
||||
else
|
||||
scope = Spree::Product.active
|
||||
|
||||
@@ -3,7 +3,7 @@ Spree::Api::VariantsController.class_eval do
|
||||
@variant = scope.find(params[:variant_id])
|
||||
authorize! :delete, @variant
|
||||
|
||||
@variant.delete
|
||||
VariantDeleter.new.delete(@variant)
|
||||
respond_with @variant, status: 204
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user