spree_backend 4.2.5 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/config/spree_backend_manifest.js +129 -0
  4. data/app/assets/images/backend-arrows-fullscreen.svg +3 -0
  5. data/app/assets/images/backend-box.svg +3 -0
  6. data/app/assets/images/backend-circle-fill.svg +3 -0
  7. data/app/assets/images/backend-circle.svg +3 -0
  8. data/app/assets/images/backend-default-layout.svg +6 -0
  9. data/app/assets/images/backend-eye-slash-fill.svg +4 -0
  10. data/app/assets/images/backend-file-richtext.svg +4 -0
  11. data/app/assets/images/backend-fullscreen-exit.svg +3 -0
  12. data/app/assets/images/backend-fullscreen.svg +3 -0
  13. data/app/assets/images/backend-mobile.svg +5 -0
  14. data/app/assets/images/backend-pages.svg +10 -0
  15. data/app/assets/images/backend-phone.svg +4 -0
  16. data/app/assets/images/backend-reversed-layout.svg +6 -0
  17. data/app/assets/images/backend-spree-icon.svg +1 -0
  18. data/app/assets/images/backend-spree-logo.svg +6 -0
  19. data/app/assets/images/backend-store.svg +2 -13
  20. data/app/assets/images/backend-translate.svg +4 -0
  21. data/app/assets/images/backend-users.svg +2 -5
  22. data/app/assets/images/backend-window-sidebar.svg +4 -0
  23. data/app/assets/images/noimage/backend-missing-image.svg +4 -0
  24. data/app/assets/images/noimage/large.png +0 -0
  25. data/app/assets/images/noimage/mini.png +0 -0
  26. data/app/assets/images/noimage/product.png +0 -0
  27. data/app/assets/images/noimage/small.png +0 -0
  28. data/app/assets/javascripts/spree/backend/address_states.es6 +44 -0
  29. data/app/assets/javascripts/spree/backend/admin.js +45 -307
  30. data/app/assets/javascripts/spree/backend/checkouts/edit.js +22 -13
  31. data/app/assets/javascripts/spree/backend/cms/_index.es6 +4 -0
  32. data/app/assets/javascripts/spree/backend/cms/links.es6 +25 -0
  33. data/app/assets/javascripts/spree/backend/cms/live_preview.es6 +34 -0
  34. data/app/assets/javascripts/spree/backend/cms/page.es6 +133 -0
  35. data/app/assets/javascripts/spree/backend/cms/section.es6 +43 -0
  36. data/app/assets/javascripts/spree/backend/global/_index.js +11 -0
  37. data/app/assets/javascripts/spree/backend/global/alerts.es6 +66 -0
  38. data/app/assets/javascripts/spree/backend/global/api_functions.es6 +5 -0
  39. data/app/assets/javascripts/spree/backend/global/bootstrap.es6 +15 -0
  40. data/app/assets/javascripts/spree/backend/global/flatpickr.es6 +22 -0
  41. data/app/assets/javascripts/spree/backend/global/info_alert.es6 +38 -0
  42. data/app/assets/javascripts/spree/backend/global/radio_panel_toggle.es6 +18 -0
  43. data/app/assets/javascripts/spree/backend/global/ransack.es6 +108 -0
  44. data/app/assets/javascripts/spree/backend/global/responsive_menus.es6 +56 -0
  45. data/app/assets/javascripts/spree/backend/global/select2_autocomplete.es6 +132 -0
  46. data/app/assets/javascripts/spree/backend/global/select2_populate.es6 +87 -0
  47. data/app/assets/javascripts/spree/backend/global/side_scroll_indication.es6 +137 -0
  48. data/app/assets/javascripts/spree/backend/global/sortable.es6 +35 -0
  49. data/app/assets/javascripts/spree/backend/global/tinymce.es6 +11 -0
  50. data/app/assets/javascripts/spree/backend/menus/_index.es6 +2 -0
  51. data/app/assets/javascripts/spree/backend/menus/menu.es6 +57 -0
  52. data/app/assets/javascripts/spree/backend/menus/menu_item.es6 +26 -0
  53. data/app/assets/javascripts/spree/backend/option_type_autocomplete.js +13 -17
  54. data/app/assets/javascripts/spree/backend/option_value_picker.js +10 -22
  55. data/app/assets/javascripts/spree/backend/payments/edit.js +1 -1
  56. data/app/assets/javascripts/spree/backend/payments/new.js +18 -5
  57. data/app/assets/javascripts/spree/backend/spree-select2.js +19 -1
  58. data/app/assets/javascripts/spree/backend/stock_location.js +1 -2
  59. data/app/assets/javascripts/spree/backend/taxon_autocomplete.js +7 -1
  60. data/app/assets/javascripts/spree/backend/taxons.js +74 -73
  61. data/app/assets/javascripts/spree/backend/user_picker.js +7 -10
  62. data/app/assets/javascripts/spree/backend.js +28 -1
  63. data/app/assets/javascripts/spree.js +78 -0
  64. data/app/assets/stylesheets/spree/backend/components/_filters.scss +1 -3
  65. data/app/assets/stylesheets/spree/backend/components/_main.scss +0 -1
  66. data/app/assets/stylesheets/spree/backend/components/_navbar.scss +35 -0
  67. data/app/assets/stylesheets/spree/backend/components/_navigation.scss +13 -0
  68. data/app/assets/stylesheets/spree/backend/components/_sidebar.scss +0 -1
  69. data/app/assets/stylesheets/spree/backend/components/_tables.scss +4 -5
  70. data/app/assets/stylesheets/spree/backend/global/_mixins.scss +59 -0
  71. data/app/assets/stylesheets/spree/backend/plugins/_nav_x.scss +95 -0
  72. data/app/assets/stylesheets/spree/backend/plugins/{select2_bootstrap4.scss → _select2_bootstrap4.scss} +0 -0
  73. data/app/assets/stylesheets/spree/backend/plugins/_sweetalert2_custom.scss +100 -0
  74. data/app/assets/stylesheets/spree/backend/plugins/_tinymce_custom.scss +4 -0
  75. data/app/assets/stylesheets/spree/backend/shared/_base.scss +79 -25
  76. data/app/assets/stylesheets/spree/backend/shared/_forms.scss +8 -0
  77. data/app/assets/stylesheets/spree/backend/spree_admin.css.scss +5 -0
  78. data/app/assets/stylesheets/spree/backend/views/_cms_pages.scss +148 -0
  79. data/app/assets/stylesheets/spree/backend/views/_menus.scss +61 -0
  80. data/app/controllers/concerns/spree/admin/order_concern.rb +24 -0
  81. data/app/controllers/concerns/spree/admin/product_concern.rb +11 -0
  82. data/app/controllers/spree/admin/base_controller.rb +63 -3
  83. data/app/controllers/spree/admin/cms_pages_controller.rb +29 -0
  84. data/app/controllers/spree/admin/cms_sections_controller.rb +15 -0
  85. data/app/controllers/spree/admin/customer_returns_controller.rb +4 -5
  86. data/app/controllers/spree/admin/errors_controller.rb +11 -0
  87. data/app/controllers/spree/admin/general_settings_controller.rb +1 -1
  88. data/app/controllers/spree/admin/images_controller.rb +19 -16
  89. data/app/controllers/spree/admin/log_entries_controller.rb +4 -3
  90. data/app/controllers/spree/admin/menu_items_controller.rb +33 -0
  91. data/app/controllers/spree/admin/menus_controller.rb +32 -0
  92. data/app/controllers/spree/admin/option_types_controller.rb +1 -1
  93. data/app/controllers/spree/admin/orders/customer_details_controller.rb +6 -11
  94. data/app/controllers/spree/admin/orders_controller.rb +23 -31
  95. data/app/controllers/spree/admin/payment_methods_controller.rb +17 -4
  96. data/app/controllers/spree/admin/payments_controller.rb +5 -10
  97. data/app/controllers/spree/admin/prices_controller.rb +2 -2
  98. data/app/controllers/spree/admin/products_controller.rb +21 -10
  99. data/app/controllers/spree/admin/promotion_actions_controller.rb +1 -1
  100. data/app/controllers/spree/admin/promotion_rules_controller.rb +1 -1
  101. data/app/controllers/spree/admin/promotions_controller.rb +3 -3
  102. data/app/controllers/spree/admin/prototypes_controller.rb +1 -1
  103. data/app/controllers/spree/admin/reimbursements_controller.rb +1 -1
  104. data/app/controllers/spree/admin/reports_controller.rb +5 -1
  105. data/app/controllers/spree/admin/resource_controller.rb +32 -5
  106. data/app/controllers/spree/admin/return_index_controller.rb +1 -1
  107. data/app/controllers/spree/admin/state_changes_controller.rb +2 -7
  108. data/app/controllers/spree/admin/stock_items_controller.rb +2 -2
  109. data/app/controllers/spree/admin/stock_locations_controller.rb +2 -2
  110. data/app/controllers/spree/admin/stock_movements_controller.rb +1 -1
  111. data/app/controllers/spree/admin/stock_transfers_controller.rb +1 -1
  112. data/app/controllers/spree/admin/store_credits_controller.rb +13 -8
  113. data/app/controllers/spree/admin/stores_controller.rb +14 -17
  114. data/app/controllers/spree/admin/taxons_controller.rb +9 -5
  115. data/app/controllers/spree/admin/users_controller.rb +9 -7
  116. data/app/controllers/spree/admin/variants_controller.rb +16 -15
  117. data/app/helpers/spree/admin/base_helper.rb +52 -14
  118. data/app/helpers/spree/admin/cms_helper.rb +15 -0
  119. data/app/helpers/spree/admin/menu_helper.rb +30 -0
  120. data/app/helpers/spree/admin/stores_helper.rb +21 -0
  121. data/app/models/spree/backend_configuration.rb +2 -0
  122. data/app/views/spree/admin/adjustments/_adjustment.html.erb +7 -5
  123. data/app/views/spree/admin/cms_pages/_form.html.erb +135 -0
  124. data/app/views/spree/admin/cms_pages/_live_preview_area.html.erb +61 -0
  125. data/app/views/spree/admin/cms_pages/_section_template.html.erb +16 -0
  126. data/app/views/spree/admin/cms_pages/edit.html.erb +21 -0
  127. data/app/views/spree/admin/cms_pages/index.html.erb +84 -0
  128. data/app/views/spree/admin/cms_pages/new.html.erb +8 -0
  129. data/app/views/spree/admin/cms_sections/_form.html.erb +69 -0
  130. data/app/views/spree/admin/cms_sections/edit.html.erb +19 -0
  131. data/app/views/spree/admin/cms_sections/new.html.erb +11 -0
  132. data/app/views/spree/admin/cms_sections/types/_featured_article.html.erb +50 -0
  133. data/app/views/spree/admin/cms_sections/types/_hero_image.html.erb +61 -0
  134. data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +174 -0
  135. data/app/views/spree/admin/cms_sections/types/_product_carousel.html.erb +5 -0
  136. data/app/views/spree/admin/cms_sections/types/_rich_text_content.html.erb +4 -0
  137. data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +121 -0
  138. data/app/views/spree/admin/countries/index.html.erb +5 -3
  139. data/app/views/spree/admin/customer_returns/_reimbursements_table.html.erb +6 -4
  140. data/app/views/spree/admin/customer_returns/_return_item_decision.html.erb +9 -7
  141. data/app/views/spree/admin/customer_returns/index.html.erb +4 -2
  142. data/app/views/spree/admin/errors/forbidden.html.erb +0 -0
  143. data/app/views/spree/admin/images/index.html.erb +8 -4
  144. data/app/views/spree/admin/menu_items/_form.html.erb +115 -0
  145. data/app/views/spree/admin/menu_items/edit.html.erb +11 -0
  146. data/app/views/spree/admin/menu_items/new.html.erb +11 -0
  147. data/app/views/spree/admin/menus/_form.html.erb +19 -0
  148. data/app/views/spree/admin/menus/edit.html.erb +57 -0
  149. data/app/views/spree/admin/menus/index.html.erb +90 -0
  150. data/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb +30 -0
  151. data/app/views/spree/admin/menus/new.html.erb +22 -0
  152. data/app/views/spree/admin/option_types/_form.html.erb +3 -0
  153. data/app/views/spree/admin/option_types/_option_value_fields.html.erb +5 -1
  154. data/app/views/spree/admin/option_types/index.html.erb +5 -3
  155. data/app/views/spree/admin/orders/_channel_form.html.erb +2 -2
  156. data/app/views/spree/admin/orders/_line_items.html.erb +10 -8
  157. data/app/views/spree/admin/orders/_shipment.html.erb +26 -18
  158. data/app/views/spree/admin/orders/_shipment_manifest.html.erb +11 -9
  159. data/app/views/spree/admin/orders/customer_details/_autocomplete.js.erb +2 -2
  160. data/app/views/spree/admin/orders/index.html.erb +100 -101
  161. data/app/views/spree/admin/payment_methods/_form.html.erb +6 -4
  162. data/app/views/spree/admin/payment_methods/edit.html.erb +1 -1
  163. data/app/views/spree/admin/payment_methods/index.html.erb +22 -3
  164. data/app/views/spree/admin/payment_methods/new.html.erb +1 -1
  165. data/app/views/spree/admin/payments/_list.html.erb +9 -7
  166. data/app/views/spree/admin/prices/_variant_prices.html.erb +7 -14
  167. data/app/views/spree/admin/product_properties/_product_property_fields.html.erb +9 -7
  168. data/app/views/spree/admin/products/_autocomplete.js.erb +10 -6
  169. data/app/views/spree/admin/products/_form.html.erb +35 -5
  170. data/app/views/spree/admin/products/index.html.erb +15 -14
  171. data/app/views/spree/admin/products/new.html.erb +6 -1
  172. data/app/views/spree/admin/products/stock.html.erb +71 -68
  173. data/app/views/spree/admin/promotion_categories/index.html.erb +5 -3
  174. data/app/views/spree/admin/promotions/_form.html.erb +7 -0
  175. data/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb +1 -0
  176. data/app/views/spree/admin/promotions/calculators/_default_fields.html.erb +2 -1
  177. data/app/views/spree/admin/promotions/index.html.erb +33 -34
  178. data/app/views/spree/admin/properties/_form.html.erb +6 -0
  179. data/app/views/spree/admin/properties/index.html.erb +19 -3
  180. data/app/views/spree/admin/prototypes/_form.html.erb +1 -1
  181. data/app/views/spree/admin/prototypes/_prototypes.html.erb +8 -6
  182. data/app/views/spree/admin/prototypes/index.html.erb +5 -3
  183. data/app/views/spree/admin/reimbursement_types/index.html.erb +5 -3
  184. data/app/views/spree/admin/reports/index.html.erb +1 -1
  185. data/app/views/spree/admin/reports/sales_total.html.erb +1 -1
  186. data/app/views/spree/admin/return_authorizations/_form.html.erb +2 -2
  187. data/app/views/spree/admin/return_authorizations/index.html.erb +7 -5
  188. data/app/views/spree/admin/return_index/customer_returns.html.erb +4 -2
  189. data/app/views/spree/admin/return_index/return_authorizations.html.erb +5 -3
  190. data/app/views/spree/admin/roles/index.html.erb +5 -3
  191. data/app/views/spree/admin/shared/_account_nav.html.erb +5 -5
  192. data/app/views/spree/admin/shared/_address_form.html.erb +5 -4
  193. data/app/views/spree/admin/shared/_content_header.html.erb +20 -6
  194. data/app/views/spree/admin/shared/_head.html.erb +2 -1
  195. data/app/views/spree/admin/shared/_header.html.erb +7 -10
  196. data/app/views/spree/admin/shared/_link_fields.html.erb +22 -0
  197. data/app/views/spree/admin/shared/_main_menu.html.erb +19 -4
  198. data/app/views/spree/admin/shared/_order_tabs.html.erb +1 -10
  199. data/app/views/spree/admin/shared/_paths.html.erb +8 -0
  200. data/app/views/spree/admin/shared/_refunds.html.erb +4 -2
  201. data/app/views/spree/admin/shared/_sidebar.html.erb +1 -1
  202. data/app/views/spree/admin/shared/_store_switcher.html.erb +23 -0
  203. data/app/views/spree/admin/shared/_table_filter.html.erb +6 -6
  204. data/app/views/spree/admin/shared/_translations.html.erb +2 -0
  205. data/app/views/spree/admin/shared/cms/_spree_product.html.erb +27 -0
  206. data/app/views/spree/admin/shared/cms/_spree_taxon.html.erb +27 -0
  207. data/app/views/spree/admin/shared/linkables/_home_page.html.erb +3 -0
  208. data/app/views/spree/admin/shared/linkables/_spree_cms_page.erb +23 -0
  209. data/app/views/spree/admin/shared/linkables/_spree_product.html.erb +20 -0
  210. data/app/views/spree/admin/shared/linkables/_spree_taxon.html.erb +22 -0
  211. data/app/views/spree/admin/shared/linkables/_url.html.erb +16 -0
  212. data/app/views/spree/admin/shared/named_types/_index.html.erb +7 -5
  213. data/app/views/spree/admin/shared/sub_menu/_configuration.html.erb +1 -3
  214. data/app/views/spree/admin/shared/sub_menu/_content.html.erb +4 -0
  215. data/app/views/spree/admin/shared/sub_menu/_stock.html.erb +4 -0
  216. data/app/views/spree/admin/shipping_categories/index.html.erb +5 -3
  217. data/app/views/spree/admin/shipping_methods/index.html.erb +5 -3
  218. data/app/views/spree/admin/states/_state_list.html.erb +5 -3
  219. data/app/views/spree/admin/stock_locations/index.html.erb +5 -3
  220. data/app/views/spree/admin/stock_transfers/index.html.erb +5 -4
  221. data/app/views/spree/admin/stock_transfers/new.html.erb +9 -7
  222. data/app/views/spree/admin/store_credit_categories/index.html.erb +5 -3
  223. data/app/views/spree/admin/store_credits/index.html.erb +7 -5
  224. data/app/views/spree/admin/stores/_form.html.erb +12 -2
  225. data/app/views/spree/admin/stores/index.html.erb +12 -10
  226. data/app/views/spree/admin/tax_categories/index.html.erb +5 -3
  227. data/app/views/spree/admin/tax_rates/index.html.erb +5 -3
  228. data/app/views/spree/admin/taxonomies/_list.html.erb +5 -3
  229. data/app/views/spree/admin/taxons/_form.html.erb +1 -1
  230. data/app/views/spree/admin/users/_addresses_form.html.erb +2 -4
  231. data/app/views/spree/admin/users/_lifetime_stats.html.erb +16 -4
  232. data/app/views/spree/admin/users/index.html.erb +5 -3
  233. data/app/views/spree/admin/users/items.html.erb +1 -1
  234. data/app/views/spree/admin/variants/_autocomplete.js.erb +6 -2
  235. data/app/views/spree/admin/variants/_autocomplete_line_items_stock.js.erb +18 -12
  236. data/app/views/spree/admin/variants/_autocomplete_stock.js.erb +12 -8
  237. data/app/views/spree/admin/variants/_split.js.erb +9 -7
  238. data/app/views/spree/admin/variants/index.html.erb +8 -5
  239. data/app/views/spree/admin/zones/index.html.erb +5 -3
  240. data/app/views/spree/layouts/admin.html.erb +16 -16
  241. data/config/initializers/assets.rb +5 -1
  242. data/config/routes.rb +14 -2
  243. data/lib/generators/spree/backend/install/install_generator.rb +22 -0
  244. data/lib/generators/spree/backend/install/templates/vendor/assets/javascripts/spree/backend/all.js +8 -0
  245. data/lib/generators/spree/backend/install/templates/vendor/assets/stylesheets/spree/backend/all.css +9 -0
  246. data/lib/spree/backend/engine.rb +4 -11
  247. data/lib/spree/backend.rb +7 -4
  248. data/lib/spree_backend.rb +0 -2
  249. data/spec/fixtures/files/favicon.ico +0 -0
  250. data/spec/fixtures/files/icon_512x512.png +0 -0
  251. data/spree_backend.gemspec +10 -5
  252. data/vendor/assets/javascripts/cleave.js +8 -0
  253. data/vendor/assets/javascripts/jsonapi-serializer.min.js +8 -0
  254. data/vendor/assets/javascripts/jsuri.js +458 -0
  255. data/vendor/assets/javascripts/sortable.js +2 -3709
  256. data/vendor/assets/javascripts/sweetalert2.js +2 -0
  257. metadata +193 -21
  258. data/app/assets/javascripts/spree/backend/address_states.js +0 -44
  259. data/app/assets/javascripts/spree/frontend/backend.js +0 -1
  260. data/app/assets/stylesheets/spree/frontend/backend.css +0 -1
  261. data/app/views/spree/admin/orders/_store_form.html.erb +0 -18
@@ -0,0 +1,24 @@
1
+ module Spree
2
+ module Admin
3
+ module OrderConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found
8
+ end
9
+
10
+ protected
11
+
12
+ def load_order
13
+ @order = current_store.orders.find_by!(number: params[:order_id])
14
+ authorize! action, @order
15
+ @order
16
+ end
17
+
18
+ def resource_not_found
19
+ flash[:error] = flash_message_for(model_class.new, :not_found)
20
+ redirect_to spree.admin_orders_path
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Admin
3
+ module ProductConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ def product_scope
7
+ current_store.products.accessible_by(current_ability, :index)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,16 @@
1
1
  module Spree
2
2
  module Admin
3
- class BaseController < Spree::BaseController
3
+ class BaseController < ApplicationController
4
+ include Spree::Core::ControllerHelpers::Auth
5
+ include Spree::Core::ControllerHelpers::Search
6
+ include Spree::Core::ControllerHelpers::Store
7
+ include Spree::Core::ControllerHelpers::StrongParameters
8
+ include Spree::Core::ControllerHelpers::Locale
9
+ include Spree::Core::ControllerHelpers::Currency
10
+
11
+ respond_to :html
12
+
13
+ helper 'spree/base'
4
14
  helper 'spree/admin/navigation'
5
15
  helper 'spree/locale'
6
16
  helper 'spree/currency'
@@ -8,6 +18,9 @@ module Spree
8
18
 
9
19
  before_action :authorize_admin
10
20
  before_action :generate_admin_api_key
21
+ before_action :load_stores
22
+
23
+ helper_method :admin_oauth_token
11
24
 
12
25
  protected
13
26
 
@@ -25,6 +38,24 @@ module Spree
25
38
  authorize! action, record
26
39
  end
27
40
 
41
+ def redirect_unauthorized_access
42
+ if try_spree_current_user
43
+ flash[:error] = Spree.t(:authorization_failure)
44
+ redirect_to spree.admin_forbidden_path
45
+ else
46
+ store_location
47
+ if defined?(spree.admin_login_path)
48
+ redirect_to spree.admin_login_path
49
+ elsif respond_to?(:spree_login_path)
50
+ redirect_to spree_login_path
51
+ elsif spree.respond_to?(:root_path)
52
+ redirect_to spree.root_path
53
+ else
54
+ redirect_to main_app.respond_to?(:root_path) ? main_app.root_path : '/'
55
+ end
56
+ end
57
+ end
58
+
28
59
  # Need to generate an API key for a user due to some backend actions
29
60
  # requiring authentication to the Spree API
30
61
  def generate_admin_api_key
@@ -35,7 +66,7 @@ module Spree
35
66
 
36
67
  def flash_message_for(object, event_sym)
37
68
  resource_desc = object.class.model_name.human
38
- resource_desc += " \"#{object.name}\"" if object.respond_to?(:name) && object.name.present?
69
+ resource_desc += " \"#{object.name}\"" if (object.persisted? || object.destroyed?) && object.respond_to?(:name) && object.name.present? && !object.is_a?(Spree::Order)
39
70
  Spree.t(event_sym, resource: resource_desc)
40
71
  end
41
72
 
@@ -47,12 +78,41 @@ module Spree
47
78
  Spree::Backend::Config[:locale]
48
79
  end
49
80
 
81
+ def stores_scope
82
+ Spree::Store.accessible_by(current_ability, :show)
83
+ end
84
+
85
+ def load_stores
86
+ @stores = stores_scope.order(default: :desc)
87
+ end
88
+
50
89
  def can_not_transition_without_customer_info
51
90
  unless @order.billing_address.present?
52
91
  flash[:notice] = Spree.t(:fill_in_customer_info)
53
- redirect_to edit_admin_order_customer_url(@order)
92
+ redirect_to spree.edit_admin_order_customer_url(@order)
93
+ end
94
+ end
95
+
96
+ def admin_oauth_application
97
+ @admin_oauth_application ||= begin
98
+ Doorkeeper::Application.find_or_create_by!(name: 'Admin Panel', scopes: 'admin', redirect_uri: '')
54
99
  end
55
100
  end
101
+
102
+ # FIXME: auto-expire this token
103
+ def admin_oauth_token
104
+ user = try_spree_current_user
105
+ return unless user
106
+
107
+ @admin_oauth_token ||= begin
108
+ Doorkeeper::AccessToken.active_for(user).where(application_id: admin_oauth_application.id).last ||
109
+ Doorkeeper::AccessToken.create!(
110
+ resource_owner_id: user.id,
111
+ application_id: admin_oauth_application.id,
112
+ scopes: admin_oauth_application.scopes
113
+ )
114
+ end.token
115
+ end
56
116
  end
57
117
  end
58
118
  end
@@ -0,0 +1,29 @@
1
+ module Spree
2
+ module Admin
3
+ class CmsPagesController < ResourceController
4
+ private
5
+
6
+ def scope
7
+ current_store.cms_pages
8
+ end
9
+
10
+ def find_resource
11
+ scope.find(params[:id])
12
+ end
13
+
14
+ def collection
15
+ return @collection if @collection.present?
16
+
17
+ params[:q] ||= {}
18
+ @collection = scope
19
+
20
+ @search = @collection.ransack(params[:q])
21
+ @collection = @search.result.page(params[:page]).per(params[:per_page])
22
+ end
23
+
24
+ def location_after_save
25
+ spree.edit_admin_cms_page_path(@cms_page)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module Admin
3
+ class CmsSectionsController < ResourceController
4
+ belongs_to 'spree/cms_page'
5
+
6
+ def collection_url
7
+ spree.edit_admin_cms_page_path(@cms_page)
8
+ end
9
+
10
+ def location_after_save
11
+ spree.edit_admin_cms_page_cms_section_path(@cms_page, @cms_section)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -31,15 +31,14 @@ module Spree
31
31
  end
32
32
 
33
33
  def find_resource
34
- Spree::CustomerReturn.accessible_by(current_ability, :show).find(params[:id])
34
+ current_store.customer_returns.accessible_by(current_ability, :show).find(params[:id])
35
35
  end
36
36
 
37
37
  def collection
38
38
  parent # trigger loading the order
39
- @collection ||= Spree::ReturnItem.
40
- accessible_by(current_ability).
41
- where(inventory_unit_id: @order.inventory_units.pluck(:id)).
42
- map(&:customer_return).uniq.compact
39
+
40
+ order_customer_return_ids = @order.return_items.accessible_by(current_ability).pluck(:customer_return_id).uniq.compact
41
+ @collection ||= current_store.customer_returns.where(id: order_customer_return_ids)
43
42
  @customer_returns = @collection
44
43
  end
45
44
 
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ module Admin
3
+ class ErrorsController < BaseController
4
+ skip_before_action :authorize_admin
5
+
6
+ def forbidden
7
+ render status: 403
8
+ end
9
+ end
10
+ end
11
+ end
@@ -17,7 +17,7 @@ module Spree
17
17
  end
18
18
 
19
19
  flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings))
20
- redirect_to edit_admin_general_settings_path
20
+ redirect_to spree.edit_admin_general_settings_path
21
21
  end
22
22
 
23
23
  def clear_cache
@@ -1,8 +1,8 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class ImagesController < ResourceController
4
+ before_action :load_product
4
5
  before_action :load_edit_data, except: :index
5
- before_action :load_index_data, only: :index
6
6
 
7
7
  create.before :set_viewable
8
8
  update.before :set_viewable
@@ -10,19 +10,14 @@ module Spree
10
10
  private
11
11
 
12
12
  def location_after_destroy
13
- admin_product_images_url(@product)
13
+ spree.admin_product_images_url(@product)
14
14
  end
15
15
 
16
16
  def location_after_save
17
- admin_product_images_url(@product)
18
- end
19
-
20
- def load_index_data
21
- @product = Product.friendly.preload(*variant_index_includes).find(params[:product_id])
17
+ spree.admin_product_images_url(@product)
22
18
  end
23
19
 
24
20
  def load_edit_data
25
- @product = Product.friendly.preload(*variant_edit_includes).find(params[:product_id])
26
21
  @variants = @product.variants.map do |variant|
27
22
  [variant.sku_and_options_text, variant.id]
28
23
  end
@@ -34,16 +29,24 @@ module Spree
34
29
  @image.viewable_id = params[:image][:viewable_id]
35
30
  end
36
31
 
37
- def variant_index_includes
38
- [
39
- variant_images: [viewable: { option_values: :option_type }]
40
- ]
32
+ def load_product
33
+ @product = scope.friendly.find(params[:product_id])
34
+ end
35
+
36
+ def scope
37
+ current_store.products
38
+ end
39
+
40
+ def collection_url
41
+ spree.admin_product_images_url
42
+ end
43
+
44
+ def modle_class
45
+ Spree::Image
41
46
  end
42
47
 
43
- def variant_edit_includes
44
- [
45
- variants_including_master: { option_values: :option_type, images: :viewable }
46
- ]
48
+ def collection
49
+ @collection ||= load_product.variant_images
47
50
  end
48
51
  end
49
52
  end
@@ -1,7 +1,9 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class LogEntriesController < Spree::Admin::BaseController
4
- before_action :find_order_and_payment
4
+ include Spree::Admin::OrderConcern
5
+ before_action :load_order
6
+ before_action :load_payment
5
7
 
6
8
  def index
7
9
  @log_entries = @payment.log_entries
@@ -9,8 +11,7 @@ module Spree
9
11
 
10
12
  private
11
13
 
12
- def find_order_and_payment
13
- @order = Spree::Order.find_by!(number: params[:order_id])
14
+ def load_payment
14
15
  @payment = @order.payments.find_by!(number: params[:payment_id])
15
16
  end
16
17
  end
@@ -0,0 +1,33 @@
1
+ module Spree
2
+ module Admin
3
+ class MenuItemsController < ResourceController
4
+ belongs_to 'spree/menu'
5
+
6
+ before_action :load_data
7
+
8
+ def collection_url
9
+ spree.edit_admin_menu_path(@menu)
10
+ end
11
+
12
+ def location_after_save
13
+ spree.edit_admin_menu_menu_item_path(@menu, @menu_item)
14
+ end
15
+
16
+ def remove_icon
17
+ if @menu_item.icon&.destroy
18
+ flash[:success] = Spree.t('notice_messages.icon_removed')
19
+ redirect_to spree.edit_admin_menu_menu_item_path(@menu, @menu_item)
20
+ else
21
+ flash[:error] = Spree.t('errors.messages.cannot_remove_icon')
22
+ render :edit
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def load_data
29
+ @menu_item_types = Spree::MenuItem::ITEM_TYPE
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ module Spree
2
+ module Admin
3
+ class MenusController < ResourceController
4
+ def index; end
5
+
6
+ private
7
+
8
+ def scope
9
+ current_store.menus
10
+ end
11
+
12
+ def find_resource
13
+ scope.find(params[:id])
14
+ end
15
+
16
+ def collection
17
+ return @collection if @collection.present?
18
+
19
+ params[:q] ||= {}
20
+ @collection = scope
21
+
22
+ @search = @collection.ransack(params[:q])
23
+ @collection = @search.result.page(params[:page]).
24
+ per(params[:per_page] || Spree::Backend::Config[:menus_per_page])
25
+ end
26
+
27
+ def location_after_save
28
+ spree.edit_admin_menu_path(@menu)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -11,7 +11,7 @@ module Spree
11
11
  end
12
12
 
13
13
  respond_to do |format|
14
- format.html { redirect_to admin_product_variants_url(params[:product_id]) }
14
+ format.html { redirect_to spree.admin_product_variants_url(params[:product_id]) }
15
15
  format.js { render plain: 'Ok' }
16
16
  end
17
17
  end
@@ -2,6 +2,8 @@ module Spree
2
2
  module Admin
3
3
  module Orders
4
4
  class CustomerDetailsController < Spree::Admin::BaseController
5
+ include Spree::Admin::OrderConcern
6
+
5
7
  before_action :load_order
6
8
  before_action :load_user, only: :update, unless: :guest_checkout?
7
9
 
@@ -11,15 +13,12 @@ module Spree
11
13
  end
12
14
 
13
15
  def edit
14
- country_id = Address.default.country_id
15
- @order.build_bill_address(country_id: country_id) if @order.bill_address.nil?
16
- @order.build_ship_address(country_id: country_id) if @order.ship_address.nil?
17
-
18
- @order.bill_address.country_id = country_id if @order.bill_address.country.nil?
19
- @order.ship_address.country_id = country_id if @order.ship_address.country.nil?
16
+ @order.build_bill_address(country: current_store.default_country) if @order.bill_address.nil?
17
+ @order.build_ship_address(country: current_store.default_country) if @order.ship_address.nil?
20
18
  end
21
19
 
22
20
  def update
21
+ params[:order][:user_id] = nil if guest_checkout?
23
22
  if @order.update(order_params)
24
23
  @order.associate_user!(@user, @order.email.blank?) unless guest_checkout?
25
24
  @order.next if @order.address?
@@ -27,7 +26,7 @@ module Spree
27
26
 
28
27
  if @order.errors.empty?
29
28
  flash[:success] = Spree.t('customer_details_updated')
30
- redirect_to edit_admin_order_url(@order)
29
+ redirect_to spree.edit_admin_order_url(@order)
31
30
  else
32
31
  render action: :edit
33
32
  end
@@ -46,10 +45,6 @@ module Spree
46
45
  )
47
46
  end
48
47
 
49
- def load_order
50
- @order = Order.includes(:adjustments).find_by!(number: params[:order_id])
51
- end
52
-
53
48
  def model_class
54
49
  Spree::Order
55
50
  end