solidus_backend 2.9.6 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_backend might be problematic. Click here for more details.

Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree/backend.js +5 -1
  3. data/app/assets/javascripts/spree/backend/adjustments.js +1 -1
  4. data/app/assets/javascripts/spree/backend/admin.js +18 -29
  5. data/app/assets/javascripts/spree/backend/collections/states.js +1 -1
  6. data/app/assets/javascripts/spree/backend/components/admin_nav.js +24 -0
  7. data/app/assets/javascripts/spree/backend/components/selectable_table.js +5 -0
  8. data/app/assets/javascripts/spree/backend/components/selectable_table/return_items.js +5 -0
  9. data/app/assets/javascripts/spree/backend/components/selectable_table/summary.js +7 -0
  10. data/app/assets/javascripts/spree/backend/components/sortable_table.js +31 -25
  11. data/app/assets/javascripts/spree/backend/components/tabs.js +1 -1
  12. data/app/assets/javascripts/spree/backend/models/order.js +11 -2
  13. data/app/assets/javascripts/spree/backend/models/payment.js +1 -1
  14. data/app/assets/javascripts/spree/backend/models/shipment.js +1 -1
  15. data/app/assets/javascripts/spree/backend/models/stock_item.js +1 -1
  16. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +2 -2
  17. data/app/assets/javascripts/spree/backend/option_value_picker.js +2 -2
  18. data/app/assets/javascripts/spree/backend/orders/cart.js +6 -0
  19. data/app/assets/javascripts/spree/backend/product_picker.js +2 -2
  20. data/app/assets/javascripts/spree/backend/routes.js +40 -21
  21. data/app/assets/javascripts/spree/backend/shipments.js +5 -67
  22. data/app/assets/javascripts/spree/backend/shipping_methods/stock_locations_picker.js +18 -0
  23. data/app/assets/javascripts/spree/backend/stock_management.js +4 -2
  24. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +2 -2
  25. data/app/assets/javascripts/spree/backend/taxons.js +3 -3
  26. data/app/assets/javascripts/spree/backend/templates/index.js +2 -1
  27. data/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs +2 -2
  28. data/app/assets/javascripts/spree/backend/templates/stock_items/stock_location_stock_item.hbs +5 -1
  29. data/app/assets/javascripts/spree/backend/templates/tables/return_item_sum_amount.hbs +7 -0
  30. data/app/assets/javascripts/spree/backend/templates/tables/selectable_label.hbs +6 -0
  31. data/app/assets/javascripts/spree/backend/user_picker.js +3 -4
  32. data/app/assets/javascripts/spree/backend/variant_autocomplete.js +2 -2
  33. data/app/assets/javascripts/spree/backend/views/cart/empty_cart_button.js +29 -0
  34. data/app/assets/javascripts/spree/backend/views/cart/line_item_table.js +5 -0
  35. data/app/assets/javascripts/spree/backend/views/index.js +5 -0
  36. data/app/assets/javascripts/spree/backend/views/order/address.js +8 -6
  37. data/app/assets/javascripts/spree/backend/views/order/customer_select.js +2 -3
  38. data/app/assets/javascripts/spree/backend/views/order/details_adjustments.js +4 -1
  39. data/app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js +4 -0
  40. data/app/assets/javascripts/spree/backend/views/tables/return_items.js +9 -0
  41. data/app/assets/javascripts/spree/backend/views/tables/selectable_table.js +70 -0
  42. data/app/assets/javascripts/spree/backend/views/tables/selectable_table/sum_return_item_amount.js +32 -0
  43. data/app/assets/javascripts/spree/backend/views/tables/selectable_table/summary.js +45 -0
  44. data/app/assets/stylesheets/spree/backend/_bootstrap_custom.scss +2 -0
  45. data/app/assets/stylesheets/spree/backend/components/_breadcrumb.scss +3 -3
  46. data/app/assets/stylesheets/spree/backend/components/_messages.scss +4 -0
  47. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +181 -49
  48. data/app/assets/stylesheets/spree/backend/globals/{_mixins.css → _mixins.scss} +0 -0
  49. data/app/assets/stylesheets/spree/backend/globals/_variables.scss +2 -0
  50. data/app/assets/stylesheets/spree/backend/sections/_orders.scss +5 -1
  51. data/app/assets/stylesheets/spree/backend/sections/_style_guide.scss +4 -0
  52. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +1 -0
  53. data/app/assets/stylesheets/spree/backend/shared/_header.scss +5 -1
  54. data/app/assets/stylesheets/spree/backend/shared/_layout.scss +0 -9
  55. data/app/controllers/spree/admin/adjustments_controller.rb +1 -1
  56. data/app/controllers/spree/admin/base_controller.rb +7 -1
  57. data/app/controllers/spree/admin/cancellations_controller.rb +2 -0
  58. data/app/controllers/spree/admin/customer_returns_controller.rb +4 -4
  59. data/app/controllers/spree/admin/images_controller.rb +2 -1
  60. data/app/controllers/spree/admin/orders/customer_details_controller.rb +2 -0
  61. data/app/controllers/spree/admin/orders_controller.rb +9 -4
  62. data/app/controllers/spree/admin/payment_methods_controller.rb +4 -4
  63. data/app/controllers/spree/admin/payments_controller.rb +5 -3
  64. data/app/controllers/spree/admin/product_properties_controller.rb +2 -2
  65. data/app/controllers/spree/admin/products_controller.rb +19 -25
  66. data/app/controllers/spree/admin/promotion_codes_controller.rb +9 -4
  67. data/app/controllers/spree/admin/refunds_controller.rb +19 -0
  68. data/app/controllers/spree/admin/resource_controller.rb +39 -10
  69. data/app/controllers/spree/admin/return_authorizations_controller.rb +1 -1
  70. data/app/controllers/spree/admin/root_controller.rb +1 -1
  71. data/app/controllers/spree/admin/search_controller.rb +1 -2
  72. data/app/controllers/spree/admin/stock_items_controller.rb +6 -5
  73. data/app/controllers/spree/admin/stock_locations_controller.rb +4 -0
  74. data/app/controllers/spree/admin/stock_movements_controller.rb +7 -0
  75. data/app/controllers/spree/admin/style_guide_controller.rb +1 -1
  76. data/app/controllers/spree/admin/taxons/attachment_controller.rb +20 -0
  77. data/app/controllers/spree/admin/taxons_controller.rb +12 -1
  78. data/app/controllers/spree/admin/users/api_key_controller.rb +29 -0
  79. data/app/controllers/spree/admin/users_controller.rb +43 -22
  80. data/app/controllers/spree/admin/variants_controller.rb +4 -2
  81. data/app/controllers/spree/admin/zones_controller.rb +1 -1
  82. data/app/helpers/spree/admin/base_helper.rb +4 -0
  83. data/app/helpers/spree/admin/customer_returns_helper.rb +1 -1
  84. data/app/helpers/spree/admin/navigation_helper.rb +4 -3
  85. data/app/helpers/spree/admin/orders_helper.rb +8 -4
  86. data/app/helpers/spree/admin/stock_movements_helper.rb +8 -4
  87. data/app/helpers/spree/promotion_rules_helper.rb +1 -1
  88. data/app/views/spree/admin/customer_returns/_return_item_selection.html.erb +2 -3
  89. data/app/views/spree/admin/customer_returns/new.html.erb +1 -1
  90. data/app/views/spree/admin/images/index.html.erb +25 -21
  91. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +8 -1
  92. data/app/views/spree/admin/option_types/edit.html.erb +4 -2
  93. data/app/views/spree/admin/orders/_line_items_edit_form.html.erb +1 -0
  94. data/app/views/spree/admin/orders/customer_details/_form.html.erb +13 -13
  95. data/app/views/spree/admin/orders/edit.html.erb +3 -4
  96. data/app/views/spree/admin/orders/index.html.erb +23 -13
  97. data/app/views/spree/admin/payment_methods/_form.html.erb +7 -2
  98. data/app/views/spree/admin/payment_methods/new.html.erb +1 -1
  99. data/app/views/spree/admin/payments/index.html.erb +3 -1
  100. data/app/views/spree/admin/prices/_master_variant_table.html.erb +41 -41
  101. data/app/views/spree/admin/prices/_table.html.erb +3 -3
  102. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +7 -2
  103. data/app/views/spree/admin/product_properties/index.html.erb +14 -2
  104. data/app/views/spree/admin/products/_form.html.erb +13 -2
  105. data/app/views/spree/admin/products/index.html.erb +1 -1
  106. data/app/views/spree/admin/promotion_code_batches/new.html.erb +1 -1
  107. data/app/views/spree/admin/promotion_codes/index.html.erb +1 -1
  108. data/app/views/spree/admin/promotion_codes/new.html.erb +1 -1
  109. data/app/views/spree/admin/promotions/_actions.html.erb +2 -1
  110. data/app/views/spree/admin/promotions/_activations_new.html.erb +1 -1
  111. data/app/views/spree/admin/promotions/_rules.html.erb +1 -1
  112. data/app/views/spree/admin/promotions/edit.html.erb +2 -2
  113. data/app/views/spree/admin/promotions/index.html.erb +13 -6
  114. data/app/views/spree/admin/return_authorizations/_form.html.erb +3 -10
  115. data/app/views/spree/admin/return_authorizations/index.html.erb +1 -1
  116. data/app/views/spree/admin/return_authorizations/new.html.erb +1 -1
  117. data/app/views/spree/admin/search/users.json.jbuilder +15 -1
  118. data/app/views/spree/admin/shared/_address.html.erb +6 -6
  119. data/app/views/spree/admin/shared/_address_form.html.erb +15 -8
  120. data/app/views/spree/admin/shared/_calculator_fields.html.erb +5 -0
  121. data/app/views/spree/admin/shared/_navigation.html.erb +3 -0
  122. data/app/views/spree/admin/shared/_new_resource_links.html.erb +1 -1
  123. data/app/views/spree/admin/shared/_order_submenu.html.erb +6 -6
  124. data/app/views/spree/admin/shared/_payments_tabs.html.erb +1 -1
  125. data/app/views/spree/admin/shared/_settings_checkout_tabs.html.erb +5 -5
  126. data/app/views/spree/admin/shared/_settings_sub_menu.html.erb +7 -7
  127. data/app/views/spree/admin/shared/_shipping_tabs.html.erb +3 -3
  128. data/app/views/spree/admin/shared/_taxes_tabs.html.erb +2 -2
  129. data/app/views/spree/admin/shared/preference_fields/_encrypted_string.html.erb +12 -0
  130. data/app/views/spree/admin/shipping_methods/_form.html.erb +19 -1
  131. data/app/views/spree/admin/stock_items/_stock_management.html.erb +1 -1
  132. data/app/views/spree/admin/stock_locations/edit.html.erb +1 -1
  133. data/app/views/spree/admin/stock_locations/index.html.erb +4 -2
  134. data/app/views/spree/admin/stock_movements/index.html.erb +30 -1
  135. data/app/views/spree/admin/store_credit_reasons/index.html.erb +1 -1
  136. data/app/views/spree/admin/store_credits/index.html.erb +1 -1
  137. data/app/views/spree/admin/stores/_form.html.erb +6 -0
  138. data/app/views/spree/admin/style_guide/topics/tables/_building_tables.html.erb +27 -3
  139. data/app/views/spree/admin/tax_categories/_form.html.erb +1 -0
  140. data/app/views/spree/admin/tax_rates/_form.html.erb +1 -1
  141. data/app/views/spree/admin/taxonomies/new.html.erb +1 -1
  142. data/app/views/spree/admin/taxons/_form.html.erb +1 -5
  143. data/app/views/spree/admin/taxons/attachment_forms/_paperclip.html.erb +16 -0
  144. data/app/views/spree/admin/users/_form.html.erb +14 -12
  145. data/app/views/spree/admin/users/_tabs.html.erb +1 -1
  146. data/app/views/spree/admin/users/edit.html.erb +5 -6
  147. data/app/views/spree/admin/users/items.html.erb +5 -3
  148. data/app/views/spree/admin/users/orders.html.erb +5 -3
  149. data/app/views/spree/admin/variants/_table_filter.html.erb +1 -1
  150. data/app/views/spree/admin/variants/index.html.erb +2 -2
  151. data/app/views/spree/layouts/admin.html.erb +1 -2
  152. data/config/initializers/form_builder.rb +2 -2
  153. data/config/routes.rb +4 -6
  154. data/lib/spree/backend.rb +1 -0
  155. data/lib/spree/backend/config.rb +9 -0
  156. data/lib/spree/backend/engine.rb +5 -5
  157. data/{app/models → lib}/spree/backend_configuration.rb +19 -3
  158. data/solidus_backend.gemspec +5 -4
  159. data/vendor/assets/stylesheets/solidus_admin/bootstrap/_variables.scss +1 -1
  160. metadata +44 -124
  161. data/app/assets/javascripts/spree/backend/returns/return_item_selection.js +0 -35
  162. data/app/assets/javascripts/spree/backend/templates/variants/autocomplete_stock.hbs +0 -56
  163. data/app/views/spree/admin/orders/_add_product.html.erb +0 -12
  164. data/script/rails +0 -10
  165. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -26
  166. data/spec/controllers/spree/admin/cancellations_controller_spec.rb +0 -83
  167. data/spec/controllers/spree/admin/customer_returns_controller_spec.rb +0 -235
  168. data/spec/controllers/spree/admin/locale_controller_spec.rb +0 -45
  169. data/spec/controllers/spree/admin/missing_products_controller_spec.rb +0 -18
  170. data/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb +0 -128
  171. data/spec/controllers/spree/admin/orders_controller_spec.rb +0 -408
  172. data/spec/controllers/spree/admin/payment_methods_controller_spec.rb +0 -95
  173. data/spec/controllers/spree/admin/payments_controller_spec.rb +0 -194
  174. data/spec/controllers/spree/admin/prices_controller_spec.rb +0 -45
  175. data/spec/controllers/spree/admin/product_properties_controller_spec.rb +0 -71
  176. data/spec/controllers/spree/admin/products_controller_spec.rb +0 -270
  177. data/spec/controllers/spree/admin/promotion_actions_controller_spec.rb +0 -23
  178. data/spec/controllers/spree/admin/promotion_codes_controller_spec.rb +0 -32
  179. data/spec/controllers/spree/admin/promotion_rules_controller_spec.rb +0 -36
  180. data/spec/controllers/spree/admin/promotions_controller_spec.rb +0 -122
  181. data/spec/controllers/spree/admin/refunds_controller_spec.rb +0 -35
  182. data/spec/controllers/spree/admin/reimbursements_controller_spec.rb +0 -137
  183. data/spec/controllers/spree/admin/resource_controller_spec.rb +0 -190
  184. data/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +0 -291
  185. data/spec/controllers/spree/admin/return_items_controller_spec.rb +0 -29
  186. data/spec/controllers/spree/admin/root_controller_spec.rb +0 -43
  187. data/spec/controllers/spree/admin/search_controller_spec.rb +0 -106
  188. data/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +0 -16
  189. data/spec/controllers/spree/admin/stock_items_controller_spec.rb +0 -52
  190. data/spec/controllers/spree/admin/stock_locations_controller_spec.rb +0 -44
  191. data/spec/controllers/spree/admin/store_credits_controller_spec.rb +0 -311
  192. data/spec/controllers/spree/admin/users_controller_spec.rb +0 -264
  193. data/spec/controllers/spree/admin/variants_controller_spec.rb +0 -71
  194. data/spec/features/admin/configuration/payment_methods_spec.rb +0 -167
  195. data/spec/features/admin/configuration/shipping_methods_spec.rb +0 -114
  196. data/spec/features/admin/configuration/stock_locations_spec.rb +0 -54
  197. data/spec/features/admin/configuration/store_spec.rb +0 -62
  198. data/spec/features/admin/configuration/tax_categories_spec.rb +0 -58
  199. data/spec/features/admin/configuration/tax_rates_spec.rb +0 -31
  200. data/spec/features/admin/configuration/taxonomies_spec.rb +0 -54
  201. data/spec/features/admin/configuration/zones_spec.rb +0 -41
  202. data/spec/features/admin/homepage_spec.rb +0 -86
  203. data/spec/features/admin/javascript_format_money_spec.rb +0 -22
  204. data/spec/features/admin/locale_spec.rb +0 -34
  205. data/spec/features/admin/orders/adjustments_promotions_spec.rb +0 -55
  206. data/spec/features/admin/orders/adjustments_spec.rb +0 -130
  207. data/spec/features/admin/orders/cancelling_and_resuming_spec.rb +0 -45
  208. data/spec/features/admin/orders/cancelling_inventory_spec.rb +0 -50
  209. data/spec/features/admin/orders/customer_details_spec.rb +0 -204
  210. data/spec/features/admin/orders/customer_returns_spec.rb +0 -28
  211. data/spec/features/admin/orders/line_items_spec.rb +0 -52
  212. data/spec/features/admin/orders/listing_spec.rb +0 -186
  213. data/spec/features/admin/orders/log_entries_spec.rb +0 -56
  214. data/spec/features/admin/orders/new_order_spec.rb +0 -331
  215. data/spec/features/admin/orders/new_refund_spec.rb +0 -35
  216. data/spec/features/admin/orders/order_details_spec.rb +0 -581
  217. data/spec/features/admin/orders/payments_spec.rb +0 -330
  218. data/spec/features/admin/orders/return_authorizations_spec.rb +0 -27
  219. data/spec/features/admin/orders/return_payment_state_spec.rb +0 -65
  220. data/spec/features/admin/orders/risk_analysis_spec.rb +0 -49
  221. data/spec/features/admin/orders/shipments_spec.rb +0 -145
  222. data/spec/features/admin/payments/store_credits_spec.rb +0 -23
  223. data/spec/features/admin/products/edit/images_spec.rb +0 -76
  224. data/spec/features/admin/products/edit/products_spec.rb +0 -92
  225. data/spec/features/admin/products/edit/taxons_spec.rb +0 -51
  226. data/spec/features/admin/products/edit/variants_spec.rb +0 -63
  227. data/spec/features/admin/products/option_types_spec.rb +0 -116
  228. data/spec/features/admin/products/pricing_spec.rb +0 -127
  229. data/spec/features/admin/products/products_spec.rb +0 -336
  230. data/spec/features/admin/products/properties_spec.rb +0 -141
  231. data/spec/features/admin/products/stock_management_spec.rb +0 -101
  232. data/spec/features/admin/products/variant_spec.rb +0 -89
  233. data/spec/features/admin/promotion_adjustments_spec.rb +0 -277
  234. data/spec/features/admin/promotions/option_value_rule_spec.rb +0 -90
  235. data/spec/features/admin/promotions/product_rule_spec.rb +0 -35
  236. data/spec/features/admin/promotions/promotion_categories_spec.rb +0 -83
  237. data/spec/features/admin/promotions/promotion_spec.rb +0 -52
  238. data/spec/features/admin/promotions/tiered_calculator_spec.rb +0 -76
  239. data/spec/features/admin/promotions/user_rule_spec.rb +0 -42
  240. data/spec/features/admin/reimbursements_spec.rb +0 -18
  241. data/spec/features/admin/store_credits_spec.rb +0 -132
  242. data/spec/features/admin/stores_spec.rb +0 -37
  243. data/spec/features/admin/style_guide_spec.rb +0 -14
  244. data/spec/features/admin/taxons_spec.rb +0 -78
  245. data/spec/features/admin/users_spec.rb +0 -402
  246. data/spec/helpers/admin/base_helper_spec.rb +0 -49
  247. data/spec/helpers/admin/navigation_helper_spec.rb +0 -139
  248. data/spec/helpers/admin/stock_movements_helper_spec.rb +0 -29
  249. data/spec/helpers/admin/store_credit_events_helper_spec.rb +0 -97
  250. data/spec/helpers/promotion_rules_helper_spec.rb +0 -14
  251. data/spec/javascripts/fixtures/_boot.html.erb +0 -8
  252. data/spec/javascripts/fixtures/number_with_currency/with_currency_select.html.erb +0 -3
  253. data/spec/javascripts/fixtures/number_with_currency/without_select.html.erb +0 -3
  254. data/spec/javascripts/format_money_spec.js +0 -48
  255. data/spec/javascripts/spec_helper.js +0 -13
  256. data/spec/javascripts/support/show_errors.js +0 -8
  257. data/spec/javascripts/support/with_translations.js +0 -11
  258. data/spec/javascripts/translation_spec.js +0 -58
  259. data/spec/javascripts/views/number_with_currency_spec.js +0 -72
  260. data/spec/models/spree/backend_configuration/menu_item_spec.rb +0 -17
  261. data/spec/models/spree/backend_configuration_spec.rb +0 -22
  262. data/spec/spec_helper.rb +0 -122
  263. data/spec/support/appear_before_matcher.rb +0 -10
  264. data/spec/support/feature/base_feature_helper.rb +0 -12
  265. data/spec/support/feature/order_feature_helper.rb +0 -27
  266. data/spec/support/ror_ringer.jpeg +0 -0
  267. data/spec/teaspoon_env.rb +0 -51
  268. data/spec/test_views/spree/admin/widgets/edit.html.erb +0 -1
  269. data/spec/test_views/spree/admin/widgets/new.html.erb +0 -1
  270. data/spec/views/spree/admin/shared/navigation_footer_spec.rb +0 -67
@@ -40,7 +40,7 @@ module Spree
40
40
  [
41
41
  Spree::AdjustmentReason.active.to_a,
42
42
  @adjustment.adjustment_reason
43
- ].flatten.compact.uniq.sort_by { |r| r.name.downcase }
43
+ ].flatten.compact.uniq.sort_by { |reason| reason.name.downcase }
44
44
  end
45
45
  end
46
46
  end
@@ -4,7 +4,7 @@ module Spree
4
4
  module Admin
5
5
  class BaseController < Spree::BaseController
6
6
  helper 'spree/admin/navigation'
7
- layout '/spree/layouts/admin'
7
+ layout 'spree/layouts/admin'
8
8
 
9
9
  before_action :authorize_admin
10
10
 
@@ -62,6 +62,12 @@ module Spree
62
62
  def order_mutex_redirect_path
63
63
  edit_admin_order_path(@order)
64
64
  end
65
+
66
+ def resource_not_found(flash_class:, redirect_url:)
67
+ flash[:error] = flash_message_for(flash_class.new, :not_found)
68
+ redirect_to redirect_url
69
+ nil
70
+ end
65
71
  end
66
72
  end
67
73
  end
@@ -36,6 +36,8 @@ module Spree
36
36
  def load_order
37
37
  @order = Spree::Order.find_by!(number: params[:order_id])
38
38
  authorize! action, @order
39
+ rescue ActiveRecord::RecordNotFound
40
+ resource_not_found(flash_class: Spree::Order, redirect_url: admin_orders_path)
39
41
  end
40
42
 
41
43
  def model_class
@@ -37,13 +37,15 @@ module Spree
37
37
  end
38
38
 
39
39
  def find_resource
40
- Spree::CustomerReturn.accessible_by(current_ability, :read).find(params[:id])
40
+ Spree::CustomerReturn.accessible_by(current_ability, :show).find(params[:id])
41
41
  end
42
42
 
43
43
  def collection
44
44
  parent # trigger loading the order
45
+ return unless @order
46
+
45
47
  @collection ||= Spree::ReturnItem
46
- .accessible_by(current_ability, :read)
48
+ .accessible_by(current_ability)
47
49
  .where(inventory_unit_id: @order.inventory_units.pluck(:id))
48
50
  .map(&:customer_return).uniq.compact
49
51
  @customer_returns = @collection
@@ -70,8 +72,6 @@ module Spree
70
72
  return_item = item_params[:id] ? Spree::ReturnItem.find(item_params[:id]) : Spree::ReturnItem.new
71
73
  return_item.assign_attributes(item_params)
72
74
 
73
- return_item.skip_customer_return_processing = true
74
-
75
75
  if item_params[:reception_status_event].blank?
76
76
  return redirect_to(new_object_url, flash: { error: 'Reception status choice required' })
77
77
  end
@@ -4,7 +4,6 @@ module Spree
4
4
  module Admin
5
5
  class ImagesController < ResourceController
6
6
  before_action :load_data
7
-
8
7
  create.before :set_viewable
9
8
  update.before :set_viewable
10
9
 
@@ -24,6 +23,8 @@ module Spree
24
23
  [variant.sku_and_options_text, variant.id]
25
24
  end
26
25
  @variants.insert(0, [t('spree.all'), @product.master.id])
26
+ rescue ActiveRecord::RecordNotFound
27
+ resource_not_found(flash_class: Spree::Product, redirect_url: admin_products_path)
27
28
  end
28
29
 
29
30
  def set_viewable
@@ -61,6 +61,8 @@ module Spree
61
61
 
62
62
  def load_order
63
63
  @order = Spree::Order.includes(:adjustments).find_by!(number: params[:order_id])
64
+ rescue ActiveRecord::RecordNotFound
65
+ resource_not_found(flash_class: Spree::Order, redirect_url: admin_orders_path)
64
66
  end
65
67
 
66
68
  def model_class
@@ -10,7 +10,6 @@ module Spree
10
10
  around_action :lock_order, only: [:update, :advance, :complete, :confirm, :cancel, :resume, :approve, :resend]
11
11
 
12
12
  rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
13
-
14
13
  respond_to :html
15
14
 
16
15
  def index
@@ -61,7 +60,11 @@ module Spree
61
60
 
62
61
  def new
63
62
  user = Spree.user_class.find_by(id: params[:user_id]) if params[:user_id]
64
- @order = Spree::Core::Importer::Order.import(user, order_params)
63
+ order_importer_params = order_params
64
+ order_importer_params[:bill_address] = user&.bill_address
65
+ order_importer_params[:ship_address] = user&.ship_address
66
+
67
+ @order = Spree::Core::Importer::Order.import(user, order_importer_params)
65
68
  redirect_to cart_admin_order_url(@order)
66
69
  end
67
70
 
@@ -105,8 +108,8 @@ module Spree
105
108
  @order.complete!
106
109
  flash[:success] = t('spree.order_completed')
107
110
  redirect_to edit_admin_order_url(@order)
108
- rescue StateMachines::InvalidTransition => e
109
- flash[:error] = e.message
111
+ rescue StateMachines::InvalidTransition => error
112
+ flash[:error] = error.message
110
113
  redirect_to confirm_admin_order_url(@order)
111
114
  end
112
115
 
@@ -164,6 +167,8 @@ module Spree
164
167
  def load_order
165
168
  @order = Spree::Order.includes(:adjustments).find_by!(number: params[:id])
166
169
  authorize! action, @order
170
+ rescue ActiveRecord::RecordNotFound
171
+ resource_not_found(flash_class: Spree::Order, redirect_url: admin_orders_path)
167
172
  end
168
173
 
169
174
  # Used for extensions which need to provide their own custom event links on the order details view.
@@ -28,13 +28,13 @@ module Spree
28
28
  invoke_callbacks(:update, :before)
29
29
 
30
30
  attributes = payment_method_params
31
- attributes.each do |k, _v|
32
- if k.include?("password") && attributes[k].blank?
33
- attributes.delete(k)
31
+ attributes.each do |key, _value|
32
+ if key.include?("password") && attributes[key].blank?
33
+ attributes.delete(key)
34
34
  end
35
35
  end
36
36
 
37
- if @payment_method.update_attributes(attributes)
37
+ if @payment_method.update(attributes)
38
38
  invoke_callbacks(:update, :after)
39
39
  flash[:success] = t('spree.successfully_updated', resource: t('spree.payment_method'))
40
40
  redirect_to edit_admin_payment_method_path(@payment_method)
@@ -46,8 +46,8 @@ module Spree
46
46
  flash[:error] = t('spree.payment_could_not_be_created')
47
47
  render :new
48
48
  end
49
- rescue Spree::Core::GatewayError => e
50
- flash[:error] = e.message.to_s
49
+ rescue Spree::Core::GatewayError => error
50
+ flash[:error] = error.message.to_s
51
51
  redirect_to new_admin_order_payment_path(@order)
52
52
  end
53
53
  end
@@ -80,7 +80,7 @@ module Spree
80
80
 
81
81
  def load_data
82
82
  @amount = params[:amount] || load_order.total
83
- @payment_methods = Spree::PaymentMethod.active.available_to_admin
83
+ @payment_methods = Spree::PaymentMethod.active.available_to_admin.ordered_by_position
84
84
  if @payment && @payment.payment_method
85
85
  @payment_method = @payment.payment_method
86
86
  else
@@ -92,6 +92,8 @@ module Spree
92
92
  @order = Spree::Order.find_by!(number: params[:order_id])
93
93
  authorize! action, @order
94
94
  @order
95
+ rescue ActiveRecord::RecordNotFound
96
+ resource_not_found(flash_class: Spree::Order, redirect_url: admin_orders_path)
95
97
  end
96
98
 
97
99
  def load_payment
@@ -3,7 +3,7 @@
3
3
  module Spree
4
4
  module Admin
5
5
  class ProductPropertiesController < ResourceController
6
- belongs_to 'spree/product', find_by: :slug
6
+ belongs_to 'spree/product', find_by: :slug, includes: { product_properties: :property }
7
7
  before_action :find_properties
8
8
  before_action :setup_property, only: :index, if: -> { can?(:create, model_class) }
9
9
  before_action :setup_variant_property_rules, only: :index
@@ -15,7 +15,7 @@ module Spree
15
15
  end
16
16
 
17
17
  def setup_property
18
- @product.product_properties.build
18
+ @product.product_properties.build if @product.product_properties.empty?
19
19
  end
20
20
 
21
21
  def setup_variant_property_rules
@@ -9,6 +9,7 @@ module Spree
9
9
  update.before :update_before
10
10
  helper_method :clone_object_url
11
11
  before_action :split_params, only: [:create, :update]
12
+ before_action :normalize_variant_property_rules, only: [:update]
12
13
 
13
14
  def show
14
15
  redirect_to action: :edit
@@ -19,29 +20,6 @@ module Spree
19
20
  respond_with(@collection)
20
21
  end
21
22
 
22
- def update
23
- if updating_variant_property_rules?
24
- params[:product][:variant_property_rules_attributes].each do |_index, param_attrs|
25
- param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',')
26
- end
27
- end
28
- invoke_callbacks(:update, :before)
29
- if @object.update_attributes(permitted_resource_params)
30
- invoke_callbacks(:update, :after)
31
- flash[:success] = flash_message_for(@object, :successfully_updated)
32
- respond_with(@object) do |format|
33
- format.html { redirect_to location_after_save }
34
- format.js { render layout: false }
35
- end
36
- else
37
- # Stops people submitting blank slugs, causing errors when they try to
38
- # update the product again
39
- @product.slug = @product.slug_was if @product.slug.blank?
40
- invoke_callbacks(:update, :fails)
41
- respond_with(@object)
42
- end
43
- end
44
-
45
23
  def destroy
46
24
  @product = Spree::Product.friendly.find(params[:id])
47
25
  @product.discard
@@ -78,7 +56,7 @@ module Spree
78
56
  end
79
57
 
80
58
  def find_resource
81
- Spree::Product.with_deleted.friendly.find(params[:id])
59
+ Spree::Product.with_discarded.friendly.find(params[:id])
82
60
  end
83
61
 
84
62
  def location_after_save
@@ -96,6 +74,7 @@ module Spree
96
74
 
97
75
  def load_data
98
76
  @tax_categories = Spree::TaxCategory.order(:name)
77
+ @default_tax_category = @tax_categories.detect(&:is_default)
99
78
  @shipping_categories = Spree::ShippingCategory.order(:name)
100
79
  end
101
80
 
@@ -120,7 +99,7 @@ module Spree
120
99
  end
121
100
 
122
101
  def product_includes
123
- [{ variants: [:images], master: [:images, :default_price] }]
102
+ [:variant_images, { variants: [:images], master: [:images, :default_price] }]
124
103
  end
125
104
 
126
105
  def clone_object_url(resource)
@@ -138,6 +117,21 @@ module Spree
138
117
  def updating_variant_property_rules?
139
118
  params[:product][:variant_property_rules_attributes].present?
140
119
  end
120
+
121
+ def render_after_update_error
122
+ # Stops people submitting blank slugs, causing errors when they try to
123
+ # update the product again
124
+ @product.slug = @product.slug_was if @product.slug.blank?
125
+ render action: 'edit'
126
+ end
127
+
128
+ def normalize_variant_property_rules
129
+ return unless updating_variant_property_rules?
130
+
131
+ params[:product][:variant_property_rules_attributes].each do |_index, param_attrs|
132
+ param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',')
133
+ end
134
+ end
141
135
  end
142
136
  end
143
137
  end
@@ -6,7 +6,7 @@ module Spree
6
6
  module Admin
7
7
  class PromotionCodesController < Spree::Admin::ResourceController
8
8
  def index
9
- @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
9
+ @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
10
10
  @promotion_codes = @promotion.promotion_codes.order(:value)
11
11
 
12
12
  respond_to do |format|
@@ -22,12 +22,17 @@ module Spree
22
22
  end
23
23
 
24
24
  def new
25
- @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
26
- @promotion_code = @promotion.promotion_codes.build
25
+ @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
26
+ if @promotion.apply_automatically
27
+ flash[:error] = t('activerecord.errors.models.spree/promotion_code.attributes.base.disallowed_with_apply_automatically')
28
+ redirect_to admin_promotion_promotion_codes_url(@promotion)
29
+ else
30
+ @promotion_code = @promotion.promotion_codes.build
31
+ end
27
32
  end
28
33
 
29
34
  def create
30
- @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id])
35
+ @promotion = Spree::Promotion.accessible_by(current_ability, :show).find(params[:promotion_id])
31
36
  @promotion_code = @promotion.promotion_codes.build(value: params[:promotion_code][:value])
32
37
 
33
38
  if @promotion_code.save
@@ -10,6 +10,21 @@ module Spree
10
10
 
11
11
  rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error
12
12
 
13
+ def create
14
+ @refund.attributes = refund_params.merge(perform_after_create: false)
15
+ if @refund.save && @refund.perform!
16
+ flash[:success] = flash_message_for(@refund, :successfully_created)
17
+ respond_with(@refund) do |format|
18
+ format.html { redirect_to location_after_save }
19
+ end
20
+ else
21
+ flash.now[:error] = @refund.errors.full_messages.join(", ")
22
+ respond_with(@refund) do |format|
23
+ format.html { render action: 'new' }
24
+ end
25
+ end
26
+ end
27
+
13
28
  private
14
29
 
15
30
  def location_after_save
@@ -25,6 +40,10 @@ module Spree
25
40
  @refund_reasons ||= Spree::RefundReason.active.all
26
41
  end
27
42
 
43
+ def refund_params
44
+ params.require(:refund).permit!
45
+ end
46
+
28
47
  def build_resource
29
48
  super.tap do |refund|
30
49
  refund.amount = refund.payment.credit_allowed
@@ -5,7 +5,10 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
5
5
 
6
6
  helper_method :new_object_url, :edit_object_url, :object_url, :collection_url
7
7
  before_action :load_resource, except: :update_positions
8
- rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found
8
+ rescue_from ActiveRecord::RecordNotFound do |exception|
9
+ resource_not_found(flash_class: exception.model.constantize)
10
+ end
11
+ rescue_from ActiveRecord::RecordInvalid, with: :resource_invalid
9
12
 
10
13
  respond_to :html
11
14
 
@@ -30,7 +33,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
30
33
 
31
34
  def update
32
35
  invoke_callbacks(:update, :before)
33
- if @object.update_attributes(permitted_resource_params)
36
+ if @object.update(permitted_resource_params)
34
37
  invoke_callbacks(:update, :after)
35
38
  respond_with(@object) do |format|
36
39
  format.html do
@@ -76,7 +79,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
76
79
  def update_positions
77
80
  ActiveRecord::Base.transaction do
78
81
  params[:positions].each do |id, index|
79
- model_class.find(id).set_list_position(index)
82
+ model_class.find_by(id: id)&.set_list_position(index)
80
83
  end
81
84
  end
82
85
 
@@ -107,8 +110,14 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
107
110
  else
108
111
  invoke_callbacks(:destroy, :fails)
109
112
  respond_with(@object) do |format|
110
- format.html { redirect_to location_after_destroy }
111
- format.js { render status: :unprocessable_entity, plain: @object.errors.full_messages.join(', ') }
113
+ message = @object.errors.full_messages.to_sentence
114
+ format.html do
115
+ flash[:error] = message
116
+ redirect_to location_after_destroy
117
+ end
118
+ format.js do
119
+ render status: :unprocessable_entity, plain: message
120
+ end
112
121
  end
113
122
  end
114
123
  end
@@ -123,12 +132,12 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
123
132
  @parent_data[:model_name] = model_name
124
133
  @parent_data[:model_class] = (options[:model_class] || model_name.to_s.classify.constantize)
125
134
  @parent_data[:find_by] = options[:find_by] || :id
135
+ @parent_data[:includes] = options[:includes]
126
136
  end
127
137
  end
128
138
 
129
- def resource_not_found
130
- flash[:error] = flash_message_for(model_class.new, :not_found)
131
- redirect_to collection_url
139
+ def resource_not_found(flash_class: model_class, redirect_url: collection_url)
140
+ super
132
141
  end
133
142
 
134
143
  def model_class
@@ -183,12 +192,16 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
183
192
 
184
193
  def parent
185
194
  if parent?
186
- @parent ||= self.class.parent_data[:model_class].find_by(self.class.parent_data[:find_by] => params["#{parent_model_name}_id"])
195
+ @parent ||= self.class.parent_data[:model_class]
196
+ .includes(self.class.parent_data[:includes])
197
+ .find_by!(self.class.parent_data[:find_by] => params["#{parent_model_name}_id"])
187
198
  instance_variable_set("@#{parent_model_name}", @parent)
188
199
  else
189
200
  Spree::Deprecation.warn "Calling #parent is deprecated on a ResourceController which has not defined a belongs_to"
190
201
  nil
191
202
  end
203
+ rescue ActiveRecord::RecordNotFound => e
204
+ resource_not_found(flash_class: e.model.constantize, redirect_url: spree.polymorphic_url([:admin, parent_model_name.pluralize]))
192
205
  end
193
206
 
194
207
  def parent?
@@ -212,7 +225,8 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
212
225
  end
213
226
 
214
227
  def collection
215
- return parent.send(controller_name) if parent?
228
+ return parent.send(controller_name) if parent? && parent
229
+
216
230
  if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
217
231
  model_class.accessible_by(current_ability, action)
218
232
  else
@@ -290,4 +304,19 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
290
304
  def render_after_update_error
291
305
  render action: 'edit'
292
306
  end
307
+
308
+ def resource_invalid(exception)
309
+ invoke_callbacks(action, :fails)
310
+ respond_with(@object) do |format|
311
+ format.html do
312
+ flash.now[:error] = exception.message
313
+ if @object.new_record?
314
+ render_after_create_error
315
+ else
316
+ render_after_update_error
317
+ end
318
+ end
319
+ format.js { render layout: false }
320
+ end
321
+ end
293
322
  end