Merge pull request #3394 from mkllnk/3021-update-soft-delete

[Spree upgrade] 3021 update soft delete
This commit is contained in:
Pau Pérez Fabregat
2019-02-25 11:58:41 +01:00
committed by GitHub
18 changed files with 67 additions and 85 deletions

View File

@@ -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.

View File

@@ -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]) }

View File

@@ -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

View File

@@ -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