solidus_admin 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9976fca44d3e64ccb4f4dc321ca3ed988f654bec55498f0b1a624abcf7c15cb
4
- data.tar.gz: 15267cab9e5166d3d8311c741c07d8f0e36d64e4efcaa8170a0860f3b04eac92
3
+ metadata.gz: 1cc353f410a59b215ed2ec204142a898415cc32f0ccc5d808019fe9c196bdfae
4
+ data.tar.gz: 50796a9a1bd1be8a888f61ac20fd753ed88661de07f9427bb5d6b1c72fcf1d2b
5
5
  SHA512:
6
- metadata.gz: 339413880b765aed28876f823195d02527986164c174513665cdb2297ded7091d3d6a773654756e6733784ea8b18a48d9b423e843eb7d3335ae34f3e5796ab24
7
- data.tar.gz: 1eeef37a4149c99f55a1c142f8aa210f82475da1af680212a04960ca64ad129ebab13179c79780803fe37c11c3c20957d9f1bab9bec0d45bc9ed21bc076c3497
6
+ metadata.gz: a25f0ba55ab0ea44fecbb6e6f48a65b480f63ea7cbcca9d66c1c6a29cf1f62642c4c66b5e9da4b1326cf1c4c54e98ca4f8c6eb43ec434ccb459fc7dd1b8ac5a1
7
+ data.tar.gz: 591bd3ef9b1f3b80be29af4f3f05bdbf17b1d7be444a9e52894945708754a896fe72f44b8ea76adf9245040ff4f2d169da22b5d875f1f533eddc81a2086a6f09
@@ -80,11 +80,15 @@ class SolidusAdmin::UI::Pages::Index::Component < SolidusAdmin::BaseComponent
80
80
  end
81
81
 
82
82
  def prev_page_path
83
- solidus_admin.url_for(**request.params, page: @page.current_page - 1, only_path: true) if @page && !@page.first_page?
83
+ page_path(@page.current_page - 1) if @page && !@page.first_page?
84
84
  end
85
85
 
86
86
  def next_page_path
87
- solidus_admin.url_for(**request.params, page: @page.next_page, only_path: true) if @page&.next_page
87
+ page_path(@page.next_page) if @page&.next_page
88
+ end
89
+
90
+ def page_path(page)
91
+ "#{request.path}?#{request.query_parameters.merge("page" => page).to_query}"
88
92
  end
89
93
 
90
94
  def search_options
@@ -18,6 +18,7 @@ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
18
18
 
19
19
  def lock
20
20
  @adjustments = @order.all_adjustments.not_finalized.where(id: params[:id])
21
+ authorize_each! @adjustments
21
22
  @adjustments.each(&:finalize!)
22
23
  flash[:notice] = t(".success")
23
24
 
@@ -26,6 +27,7 @@ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
26
27
 
27
28
  def unlock
28
29
  @adjustments = @order.all_adjustments.finalized.where(id: params[:id])
30
+ authorize_each! @adjustments
29
31
  @adjustments.each(&:unfinalize!)
30
32
  flash[:notice] = t(".success")
31
33
 
@@ -34,6 +36,7 @@ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
34
36
 
35
37
  def destroy
36
38
  @adjustments = @order.all_adjustments.where(id: params[:id])
39
+ authorize_each! @adjustments
37
40
  @adjustments.destroy_all
38
41
  flash[:notice] = t(".success")
39
42
 
@@ -43,8 +46,7 @@ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
43
46
  private
44
47
 
45
48
  def load_adjustments
46
- @adjustments = @order
47
- .all_adjustments
49
+ @adjustments = accessible(@order.all_adjustments)
48
50
  .order("adjustable_type ASC, created_at ASC")
49
51
  .ransack(params[:q])
50
52
  .result
@@ -52,5 +54,6 @@ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
52
54
 
53
55
  def load_order
54
56
  @order = Spree::Order.find_by!(number: params[:order_id])
57
+ authorize! :show, @order
55
58
  end
56
59
  end
@@ -24,6 +24,18 @@ module SolidusAdmin::ControllerHelpers::Authorization
24
24
  authorize! action_name.to_sym, subject
25
25
  end
26
26
 
27
+ # Rules defined with a block can't be turned into a query, so the scope is
28
+ # left as it is for them, like in the legacy backend.
29
+ def accessible(scope)
30
+ return scope if current_ability.has_block?(:index, scope.all.klass)
31
+
32
+ scope.accessible_by(current_ability, :index)
33
+ end
34
+
35
+ def authorize_each!(records)
36
+ records.each { authorize! action_name.to_sym, _1 }
37
+ end
38
+
27
39
  def authorization_subject
28
40
  "Spree::#{controller_name.classify}".constantize
29
41
  rescue NameError
@@ -18,7 +18,8 @@ module SolidusAdmin::ControllerHelpers::Locale
18
18
  session[set_user_language_locale_key] = requested_locale
19
19
 
20
20
  flash[:notice] = t("spree.locale_changed")
21
- redirect_to params.except(:switch_to_locale).permit!.to_h.merge(account_menu_open: true)
21
+ query = request.query_parameters.except("switch_to_locale").merge("account_menu_open" => true)
22
+ redirect_to "#{request.path}?#{query.to_query}"
22
23
  end
23
24
  end
24
25
 
@@ -20,7 +20,8 @@ module SolidusAdmin::ControllerHelpers::Theme
20
20
  session[session_key] = requested_theme
21
21
 
22
22
  flash[:notice] = t("spree.theme_changed")
23
- redirect_to params.except(:switch_to_theme, :system_theme).permit!.to_h.merge(account_menu_open: true)
23
+ query = request.query_parameters.except("switch_to_theme", "system_theme").merge("account_menu_open" => true)
24
+ redirect_to "#{request.path}?#{query.to_query}"
24
25
  end
25
26
  end
26
27
 
@@ -25,6 +25,7 @@ class SolidusAdmin::CustomersController < SolidusAdmin::BaseController
25
25
 
26
26
  def load_order
27
27
  @order = Spree::Order.find_by!(number: params[:order_id])
28
+ authorize! action_name.to_sym, @order
28
29
  end
29
30
 
30
31
  def authorization_subject
@@ -13,7 +13,7 @@ module SolidusAdmin
13
13
 
14
14
  def index
15
15
  orders = apply_search_to(
16
- Spree::Order.includes(:line_items),
16
+ accessible(Spree::Order).includes(:line_items),
17
17
  param: :q,
18
18
  distinct: false
19
19
  )
@@ -31,6 +31,7 @@ module SolidusAdmin
31
31
 
32
32
  def load_product
33
33
  @product = Spree::Product.friendly.find(params[:product_id])
34
+ authorize! action_name.to_sym, Spree::Classification.new(product_id: @product.id)
34
35
  end
35
36
 
36
37
  def init_taxon
@@ -13,7 +13,7 @@ module SolidusAdmin
13
13
 
14
14
  def index
15
15
  products = apply_search_to(
16
- Spree::Product.includes(
16
+ accessible(Spree::Product).includes(
17
17
  :variant_images,
18
18
  master: :prices,
19
19
  variants: :prices,
@@ -36,6 +36,7 @@ module SolidusAdmin
36
36
 
37
37
  def show
38
38
  @product = Spree::Product.with_discarded.friendly.find(params[:id])
39
+ authorize! :show, @product
39
40
 
40
41
  respond_to do |format|
41
42
  format.html { render component("products/show").new(product: @product) }
@@ -44,6 +45,7 @@ module SolidusAdmin
44
45
 
45
46
  def update
46
47
  @product = Spree::Product.friendly.find(params[:id])
48
+ authorize! :update, @product
47
49
 
48
50
  if @product.update(product_params)
49
51
  flash[:success] = t(".success")
@@ -59,6 +61,7 @@ module SolidusAdmin
59
61
 
60
62
  def destroy
61
63
  @products = Spree::Product.where(id: params[:id])
64
+ authorize_each! @products
62
65
 
63
66
  Spree::Product.transaction do
64
67
  @products.discard_all
@@ -70,6 +73,7 @@ module SolidusAdmin
70
73
 
71
74
  def discontinue
72
75
  @products = Spree::Product.where(id: params[:id])
76
+ authorize_each! @products
73
77
 
74
78
  Spree::Product.transaction do
75
79
  @products
@@ -82,6 +86,7 @@ module SolidusAdmin
82
86
 
83
87
  def activate
84
88
  @products = Spree::Product.where(id: params[:id])
89
+ authorize_each! @products
85
90
 
86
91
  Spree::Product.transaction do
87
92
  @products
@@ -6,7 +6,7 @@ module SolidusAdmin
6
6
 
7
7
  def index
8
8
  reimbursement_types = apply_search_to(
9
- Spree::ReimbursementType.unscoped.order(id: :desc),
9
+ accessible(Spree::ReimbursementType.unscoped).order(id: :desc),
10
10
  param: :q
11
11
  )
12
12
 
@@ -32,11 +32,13 @@ module SolidusAdmin
32
32
 
33
33
  def new
34
34
  @resource ||= resource_class.new
35
+ authorize! :new, @resource
35
36
  render new_component.new(@resource)
36
37
  end
37
38
 
38
39
  def create
39
40
  @resource ||= resource_class.new(permitted_resource_params)
41
+ authorize! :create, @resource
40
42
 
41
43
  if @resource.save
42
44
  flash[:notice] = t(".success")
@@ -73,6 +75,7 @@ module SolidusAdmin
73
75
 
74
76
  def destroy
75
77
  @resource = resource_class.where(id: params[:id])
78
+ authorize_each! @resource
76
79
 
77
80
  resource_class.transaction { @resource.destroy_all }
78
81
 
@@ -92,7 +95,7 @@ module SolidusAdmin
92
95
 
93
96
  def set_paginated_resources
94
97
  @resources ||= apply_search_to(
95
- resources_collection,
98
+ accessible(resources_collection),
96
99
  param: :q
97
100
  ).tap do |resources|
98
101
  instance_variable_set("@#{plural_resource_name}", resources)
@@ -114,6 +117,7 @@ module SolidusAdmin
114
117
 
115
118
  def set_resource
116
119
  @resource ||= resource_class.find(params[:id]).tap do |resource|
120
+ authorize! action_name.to_sym, resource
117
121
  instance_variable_set("@#{resource_name}", resource)
118
122
  end
119
123
  end
@@ -6,7 +6,7 @@ module SolidusAdmin
6
6
 
7
7
  def index
8
8
  shipping_methods = apply_search_to(
9
- Spree::ShippingMethod.order(id: :desc),
9
+ accessible(Spree::ShippingMethod).order(id: :desc),
10
10
  param: :q
11
11
  )
12
12
 
@@ -19,6 +19,7 @@ module SolidusAdmin
19
19
 
20
20
  def destroy
21
21
  @shipping_methods = Spree::ShippingMethod.where(id: params[:id])
22
+ authorize_each! @shipping_methods
22
23
 
23
24
  Spree::ShippingMethod.transaction { @shipping_methods.destroy_all }
24
25
 
@@ -9,7 +9,7 @@ module SolidusAdmin
9
9
  before_action :set_store_credit_categories, only: [:new]
10
10
 
11
11
  def index
12
- @store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc)
12
+ @store_credits = accessible(@user.store_credits).order(id: :desc)
13
13
 
14
14
  respond_to do |format|
15
15
  format.html { render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) }
@@ -23,7 +23,8 @@ module SolidusAdmin
23
23
  end
24
24
 
25
25
  def new
26
- @store_credit ||= Spree::StoreCredit.new
26
+ @store_credit ||= Spree::StoreCredit.new(user: @user)
27
+ authorize! :new, @store_credit
27
28
 
28
29
  respond_to do |format|
29
30
  format.html {
@@ -43,6 +44,7 @@ module SolidusAdmin
43
44
  action_originator: spree_current_user
44
45
  })
45
46
  )
47
+ authorize! :create, @store_credit
46
48
 
47
49
  return unless ensure_amount { render_new_with_errors }
48
50
  return unless ensure_store_credit_category { render_new_with_errors }
@@ -132,7 +134,8 @@ module SolidusAdmin
132
134
  def resource_class = Spree::StoreCredit
133
135
 
134
136
  def set_store_credit
135
- @store_credit ||= Spree::StoreCredit.find(params[:id])
137
+ @store_credit ||= @user.store_credits.find(params[:id])
138
+ authorize! action_name.to_sym, @store_credit
136
139
  end
137
140
 
138
141
  def set_user
@@ -6,7 +6,7 @@ module SolidusAdmin
6
6
 
7
7
  def index
8
8
  stores = apply_search_to(
9
- Spree::Store.order(id: :desc),
9
+ accessible(Spree::Store).order(id: :desc),
10
10
  param: :q
11
11
  )
12
12
 
@@ -19,6 +19,7 @@ module SolidusAdmin
19
19
 
20
20
  def destroy
21
21
  @resource = resource_class.where(id: params[:id])
22
+ authorize_each! @resource
22
23
 
23
24
  failed = @resource.destroy_all.reject(&:destroyed?)
24
25
  if failed.none?
@@ -7,7 +7,7 @@ module SolidusAdmin
7
7
 
8
8
  def index
9
9
  taxonomies = apply_search_to(
10
- Spree::Taxonomy.all,
10
+ accessible(Spree::Taxonomy),
11
11
  param: :q
12
12
  )
13
13
 
@@ -20,6 +20,7 @@ module SolidusAdmin
20
20
 
21
21
  def destroy
22
22
  @taxonomies = Spree::Taxonomy.where(id: params[:id])
23
+ authorize_each! @taxonomies
23
24
 
24
25
  Spree::Taxonomy.transaction { @taxonomies.destroy_all }
25
26
 
@@ -15,7 +15,7 @@ module SolidusAdmin
15
15
 
16
16
  def index
17
17
  users = apply_search_to(
18
- Spree.user_class.order(created_at: :desc, id: :desc),
18
+ accessible(Spree.user_class).order(created_at: :desc, id: :desc),
19
19
  param: :q
20
20
  )
21
21
 
@@ -36,7 +36,7 @@ module SolidusAdmin
36
36
  def update_addresses
37
37
  set_address_from_params
38
38
 
39
- if @address.valid? && @user.update(user_params)
39
+ if @address.valid? && @user.update(address_params)
40
40
  flash[:notice] = t(".#{@type}.success")
41
41
 
42
42
  respond_to do |format|
@@ -74,6 +74,7 @@ module SolidusAdmin
74
74
 
75
75
  def destroy
76
76
  @users = Spree.user_class.where(id: params[:id])
77
+ authorize_each! @users
77
78
 
78
79
  Spree.user_class.transaction { @users.destroy_all }
79
80
 
@@ -85,12 +86,11 @@ module SolidusAdmin
85
86
 
86
87
  def set_user
87
88
  @user = Spree.user_class.find(params[:id])
89
+ authorize! action_name.to_sym, @user
88
90
  end
89
91
 
90
- def user_params
92
+ def address_params
91
93
  params.require(:user).permit(
92
- :user_id,
93
- permitted_user_attributes,
94
94
  bill_address_attributes: permitted_address_attributes,
95
95
  ship_address_attributes: permitted_address_attributes
96
96
  )
@@ -100,24 +100,24 @@ module SolidusAdmin
100
100
  # Since the update is being performed via the @user, and not directly on
101
101
  # the @address, we sadly don't seem to get these errors automatically.
102
102
  def set_address_from_params
103
- if user_params.key?(:bill_address_attributes)
104
- @address = Spree::Address.new(user_params[:bill_address_attributes])
103
+ if address_params.key?(:bill_address_attributes)
104
+ @address = Spree::Address.new(address_params[:bill_address_attributes])
105
105
  @type = "bill"
106
- elsif user_params.key?(:ship_address_attributes)
107
- @address = Spree::Address.new(user_params[:ship_address_attributes])
106
+ elsif address_params.key?(:ship_address_attributes)
107
+ @address = Spree::Address.new(address_params[:ship_address_attributes])
108
108
  @type = "ship"
109
109
  end
110
110
  end
111
111
 
112
112
  def set_orders
113
113
  params[:q] ||= {}
114
- @search = Spree::Order.reverse_chronological.ransack(params[:q].merge(user_id_eq: @user.id))
114
+ @search = Spree::Order.where(user_id: @user.id).reverse_chronological.ransack(params[:q])
115
115
  @orders = @search.result.page(params[:page]).per(Spree::Config.admin_products_per_page)
116
116
  end
117
117
 
118
118
  def set_items
119
119
  params[:q] ||= {}
120
- @search = Spree::Order.reverse_chronological.includes(line_items: {variant: [:product, {option_values: :option_type}]}).ransack(params[:q].merge(user_id_eq: @user.id))
120
+ @search = Spree::Order.where(user_id: @user.id).reverse_chronological.includes(line_items: {variant: [:product, {option_values: :option_type}]}).ransack(params[:q])
121
121
  @orders = @search.result.page(params[:page]).per(Spree::Config.admin_products_per_page)
122
122
  @items = @orders&.map(&:line_items)&.flatten
123
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusAdmin
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -682,7 +682,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
682
682
  - !ruby/object:Gem::Version
683
683
  version: 1.8.23
684
684
  requirements: []
685
- rubygems_version: 4.0.10
685
+ rubygems_version: 4.0.20
686
686
  specification_version: 4
687
687
  summary: Admin interface for the Solidus e-commerce framework.
688
688
  test_files: []