solidus_core 4.4.2 → 4.5.1

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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/core/controller_helpers/auth.rb +66 -0
  3. data/app/helpers/spree/core/controller_helpers/common.rb +82 -0
  4. data/app/helpers/spree/core/controller_helpers/order.rb +86 -0
  5. data/app/helpers/spree/core/controller_helpers/payment_parameters.rb +165 -0
  6. data/app/helpers/spree/core/controller_helpers/pricing.rb +19 -0
  7. data/app/helpers/spree/core/controller_helpers/search.rb +16 -0
  8. data/app/helpers/spree/core/controller_helpers/store.rb +19 -0
  9. data/app/helpers/spree/core/controller_helpers/strong_parameters.rb +74 -0
  10. data/app/models/concerns/spree/metadata.rb +64 -0
  11. data/app/models/concerns/spree/user_address_book.rb +4 -5
  12. data/app/models/spree/core/state_machines/inventory_unit.rb +42 -0
  13. data/app/models/spree/core/state_machines/order/class_methods.rb +217 -0
  14. data/app/models/spree/core/state_machines/order.rb +42 -0
  15. data/app/models/spree/core/state_machines/payment.rb +61 -0
  16. data/app/models/spree/core/state_machines/reimbursement.rb +33 -0
  17. data/app/models/spree/core/state_machines/return_authorization.rb +32 -0
  18. data/app/models/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  19. data/app/models/spree/core/state_machines/return_item/reception_status.rb +42 -0
  20. data/app/models/spree/core/state_machines/shipment.rb +58 -0
  21. data/app/models/spree/customer_return.rb +2 -0
  22. data/app/models/spree/item_total.rb +28 -0
  23. data/app/models/spree/legacy_user.rb +1 -0
  24. data/app/models/spree/line_item.rb +21 -0
  25. data/app/models/spree/money.rb +120 -0
  26. data/app/models/spree/order.rb +20 -9
  27. data/app/models/spree/order_merger.rb +1 -1
  28. data/app/models/spree/order_taxation.rb +1 -0
  29. data/app/models/spree/order_updater.rb +13 -30
  30. data/app/models/spree/payment.rb +1 -0
  31. data/app/models/spree/permission_sets/base.rb +45 -0
  32. data/app/models/spree/permission_sets/configuration_display.rb +53 -0
  33. data/app/models/spree/permission_sets/configuration_management.rb +52 -0
  34. data/app/models/spree/permission_sets/dashboard_display.rb +28 -0
  35. data/app/models/spree/permission_sets/default_customer.rb +83 -0
  36. data/app/models/spree/permission_sets/order_display.rb +50 -0
  37. data/app/models/spree/permission_sets/order_management.rb +50 -0
  38. data/app/models/spree/permission_sets/product_display.rb +43 -0
  39. data/app/models/spree/permission_sets/product_management.rb +47 -0
  40. data/app/models/spree/permission_sets/restricted_stock_display.rb +33 -0
  41. data/app/models/spree/permission_sets/restricted_stock_management.rb +33 -0
  42. data/app/models/spree/permission_sets/stock_display.rb +26 -0
  43. data/app/models/spree/permission_sets/stock_management.rb +26 -0
  44. data/app/models/spree/permission_sets/super_user.rb +26 -0
  45. data/app/models/spree/permission_sets/user_display.rb +27 -0
  46. data/app/models/spree/permission_sets/user_management.rb +44 -0
  47. data/app/models/spree/product.rb +7 -0
  48. data/app/models/spree/refund.rb +2 -0
  49. data/app/models/spree/return_authorization.rb +2 -0
  50. data/app/models/spree/shipment.rb +2 -0
  51. data/app/models/spree/simple_order_contents.rb +4 -1
  52. data/app/models/spree/store_credit_event.rb +1 -0
  53. data/app/models/spree/tax/tax_helpers.rb +12 -1
  54. data/app/models/spree/tax_calculator/default.rb +1 -1
  55. data/app/models/spree/taxon.rb +22 -2
  56. data/app/models/spree/taxon_brand_selector.rb +22 -0
  57. data/app/models/spree/unauthorized_redirect_handler.rb +24 -0
  58. data/app/models/spree/user_address.rb +9 -3
  59. data/app/models/spree/variant.rb +14 -1
  60. data/config/locales/en.yml +14 -0
  61. data/db/migrate/20220419170826_remove_archived_user_addresses.rb +12 -0
  62. data/db/migrate/20250129061658_add_metadata_to_spree_resources.rb +28 -0
  63. data/db/migrate/20250201172950_add_gtin_and_condition_to_spree_variant.rb +6 -0
  64. data/db/migrate/20250207104016_add_primary_taxon_to_products.rb +7 -0
  65. data/db/migrate/20250221152004_add_metadata_to_users.rb +13 -0
  66. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +0 -5
  67. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -1
  68. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  69. data/lib/generators/spree/dummy/templates/rails/application.rb.tt +1 -1
  70. data/lib/generators/spree/dummy/templates/rails/manifest.js +3 -0
  71. data/lib/spree/app_configuration.rb +49 -0
  72. data/lib/spree/core/controller_helpers/auth.rb +5 -61
  73. data/lib/spree/core/controller_helpers/common.rb +5 -80
  74. data/lib/spree/core/controller_helpers/order.rb +5 -86
  75. data/lib/spree/core/controller_helpers/payment_parameters.rb +5 -163
  76. data/lib/spree/core/controller_helpers/pricing.rb +5 -17
  77. data/lib/spree/core/controller_helpers/search.rb +5 -14
  78. data/lib/spree/core/controller_helpers/store.rb +5 -17
  79. data/lib/spree/core/controller_helpers/strong_parameters.rb +5 -71
  80. data/lib/spree/core/engine.rb +5 -0
  81. data/lib/spree/core/state_machines/inventory_unit.rb +5 -40
  82. data/lib/spree/core/state_machines/order.rb +5 -250
  83. data/lib/spree/core/state_machines/payment.rb +5 -59
  84. data/lib/spree/core/state_machines/reimbursement.rb +5 -31
  85. data/lib/spree/core/state_machines/return_authorization.rb +5 -30
  86. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +5 -49
  87. data/lib/spree/core/state_machines/return_item/reception_status.rb +5 -40
  88. data/lib/spree/core/state_machines/shipment.rb +5 -56
  89. data/lib/spree/core/state_machines.rb +48 -81
  90. data/lib/spree/core/version.rb +2 -2
  91. data/lib/spree/core.rb +0 -10
  92. data/lib/spree/money.rb +5 -118
  93. data/lib/spree/permission_sets/base.rb +5 -42
  94. data/lib/spree/permission_sets/configuration_display.rb +5 -51
  95. data/lib/spree/permission_sets/configuration_management.rb +5 -50
  96. data/lib/spree/permission_sets/dashboard_display.rb +5 -26
  97. data/lib/spree/permission_sets/default_customer.rb +5 -81
  98. data/lib/spree/permission_sets/order_display.rb +5 -48
  99. data/lib/spree/permission_sets/order_management.rb +5 -48
  100. data/lib/spree/permission_sets/product_display.rb +5 -41
  101. data/lib/spree/permission_sets/product_management.rb +5 -45
  102. data/lib/spree/permission_sets/restricted_stock_display.rb +5 -31
  103. data/lib/spree/permission_sets/restricted_stock_management.rb +5 -31
  104. data/lib/spree/permission_sets/stock_display.rb +5 -24
  105. data/lib/spree/permission_sets/stock_management.rb +5 -24
  106. data/lib/spree/permission_sets/super_user.rb +5 -24
  107. data/lib/spree/permission_sets/user_display.rb +5 -25
  108. data/lib/spree/permission_sets/user_management.rb +5 -42
  109. data/lib/spree/permission_sets.rb +5 -16
  110. data/lib/spree/permitted_attributes.rb +18 -7
  111. data/lib/spree/preferences/configuration.rb +4 -0
  112. data/lib/spree/preferences/persistable.rb +1 -1
  113. data/lib/spree/testing_support/capybara_ext.rb +10 -0
  114. data/lib/spree/testing_support/dummy_app.rb +1 -1
  115. data/lib/spree/testing_support/factories/order_factory.rb +9 -1
  116. data/solidus_core.gemspec +1 -1
  117. metadata +65 -24
  118. data/lib/generators/spree/dummy/templates/rails/script/rails +0 -6
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ # Spree::Money is a relatively thin wrapper around Monetize which handles
5
+ # formatting via Spree::Config.
6
+ class Money
7
+ include Comparable
8
+ DifferentCurrencyError = Class.new(StandardError)
9
+
10
+ class << self
11
+ attr_accessor :default_formatting_rules
12
+
13
+ def parse(amount, currency = Spree::Config[:currency])
14
+ new(parse_to_money(amount, currency))
15
+ end
16
+
17
+ # @api private
18
+ def parse_to_money(amount, currency)
19
+ ::Monetize.parse(amount, currency)
20
+ end
21
+ end
22
+ self.default_formatting_rules = {
23
+ # Ruby money currently has this as false, which is wrong for the vast
24
+ # majority of locales.
25
+ sign_before_symbol: true
26
+ }
27
+
28
+ attr_reader :money
29
+
30
+ delegate :cents, :currency, :to_d, :zero?, to: :money
31
+
32
+ # @param amount [Money, #to_s] the value of the money object
33
+ # @param options [Hash] the default options for formatting the money object See #format
34
+ def initialize(amount, options = {})
35
+ if amount.is_a?(::Money)
36
+ @money = amount
37
+ else
38
+ currency = options[:currency] || Spree::Config[:currency]
39
+
40
+ @money = Monetize.from_string(amount, currency)
41
+ end
42
+ @options = Spree::Money.default_formatting_rules.merge(options)
43
+ end
44
+
45
+ # @return [String] the value of this money object formatted according to
46
+ # its options
47
+ def to_s
48
+ format
49
+ end
50
+
51
+ # @param options [Hash, String] the options for formatting the money object
52
+ # @option options [Boolean] with_currency when true, show the currency
53
+ # @option options [Boolean] no_cents when true, round to the closest dollar
54
+ # @option options [String] decimal_mark the mark for delimiting the
55
+ # decimals
56
+ # @option options [String, false, nil] thousands_separator the character to
57
+ # delimit powers of 1000, if one is desired, otherwise false or nil
58
+ # @option options [Boolean] sign_before_symbol when true the sign of the
59
+ # value comes before the currency symbol
60
+ # @option options [:before, :after] symbol_position the position of the
61
+ # currency symbol
62
+ # @return [String] the value of this money object formatted according to
63
+ # its options
64
+ def format(options = {})
65
+ @money.format(@options.merge(options))
66
+ end
67
+
68
+ # @note If you pass in options, ensure you pass in the { html_wrap: true } as well.
69
+ # @param options [Hash] additional formatting options
70
+ # @return [String] the value of this money object formatted according to
71
+ # its options and any additional options, by default with html_wrap.
72
+ def to_html(options = { html_wrap: true })
73
+ output = format(options)
74
+ # Maintain compatibility by checking html option renamed to html_wrap.
75
+ if options[:html_wrap]
76
+ output = output.html_safe
77
+ end
78
+ output
79
+ end
80
+
81
+ # (see #to_s)
82
+ def as_json(*)
83
+ to_s
84
+ end
85
+
86
+ def <=>(other)
87
+ if !other.respond_to?(:money)
88
+ raise TypeError, "Can't compare #{other.class} to Spree::Money"
89
+ end
90
+ if currency != other.currency
91
+ # By default, ::Money will try to run a conversion on `other.money` and
92
+ # try a comparison on that. We do not want any currency conversion to
93
+ # take place so we'll catch this here and raise an error.
94
+ raise(
95
+ DifferentCurrencyError,
96
+ "Can't compare #{currency} with #{other.currency}"
97
+ )
98
+ end
99
+ @money <=> other.money
100
+ end
101
+
102
+ # Delegates comparison to the internal ruby money instance.
103
+ #
104
+ # @see http://www.rubydoc.info/gems/money/Money/Arithmetic#%3D%3D-instance_method
105
+ def ==(other)
106
+ raise TypeError, "Can't compare #{other.class} to Spree::Money" if !other.respond_to?(:money)
107
+ @money == other.money
108
+ end
109
+
110
+ def -(other)
111
+ raise TypeError, "Can't subtract #{other.class} to Spree::Money" if !other.respond_to?(:money)
112
+ self.class.new(@money - other.money)
113
+ end
114
+
115
+ def +(other)
116
+ raise TypeError, "Can't add #{other.class} to Spree::Money" if !other.respond_to?(:money)
117
+ self.class.new(@money + other.money)
118
+ end
119
+ end
120
+ end
@@ -26,6 +26,7 @@ module Spree
26
26
  include ::Spree::Config.state_machines.order
27
27
 
28
28
  include Spree::Order::Payments
29
+ include Metadata
29
30
 
30
31
  class InsufficientStock < StandardError
31
32
  attr_reader :items
@@ -163,8 +164,24 @@ module Spree
163
164
  delegate :name, to: :bill_address, prefix: true, allow_nil: true
164
165
  alias_method :billing_name, :bill_address_name
165
166
 
166
- class_attribute :line_item_comparison_hooks
167
- self.line_item_comparison_hooks = Set.new
167
+ delegate :line_item_comparison_hooks, to: :class
168
+ class << self
169
+ def line_item_comparison_hooks=(value)
170
+ Spree::Config.line_item_comparison_hooks = value.to_a
171
+ end
172
+ line_item_hooks_deprecation_msg = "Use Spree::Config.line_item_comparison_hooks instead."
173
+ deprecate :line_item_comparison_hooks= => line_item_hooks_deprecation_msg, :deprecator => Spree.deprecator
174
+
175
+ def line_item_comparison_hooks
176
+ Spree::Config.line_item_comparison_hooks
177
+ end
178
+ deprecate line_item_comparison_hooks: line_item_hooks_deprecation_msg, deprecator: Spree.deprecator
179
+
180
+ def register_line_item_comparison_hook(hook)
181
+ Spree::Config.line_item_comparison_hooks << hook
182
+ end
183
+ deprecate register_line_item_comparison_hook: line_item_hooks_deprecation_msg, deprecator: Spree.deprecator
184
+ end
168
185
 
169
186
  scope :created_between, ->(start_date, end_date) { where(created_at: start_date..end_date) }
170
187
  scope :completed_between, ->(start_date, end_date) { where(completed_at: start_date..end_date) }
@@ -198,12 +215,6 @@ module Spree
198
215
  where.not(state: 'canceled')
199
216
  end
200
217
 
201
- # Use this method in other gems that wish to register their own custom logic
202
- # that should be called when determining if two line items are equal.
203
- def self.register_line_item_comparison_hook(hook)
204
- line_item_comparison_hooks.add(hook)
205
- end
206
-
207
218
  # For compatiblity with Calculator::PriceSack
208
219
  def amount
209
220
  line_items.sum(&:amount)
@@ -356,7 +367,7 @@ module Spree
356
367
  def line_item_options_match(line_item, options)
357
368
  return true unless options
358
369
 
359
- line_item_comparison_hooks.all? { |hook|
370
+ Spree::Config.line_item_comparison_hooks.all? { |hook|
360
371
  send(hook, line_item, options)
361
372
  }
362
373
  end
@@ -78,7 +78,7 @@ module Spree
78
78
  def find_matching_line_item(other_order_line_item)
79
79
  order.line_items.detect do |my_li|
80
80
  my_li.variant == other_order_line_item.variant &&
81
- order.line_item_comparison_hooks.all? do |hook|
81
+ Spree::Config.line_item_comparison_hooks.all? do |hook|
82
82
  order.send(hook, my_li, other_order_line_item.serializable_hash)
83
83
  end
84
84
  end
@@ -28,6 +28,7 @@ module Spree
28
28
 
29
29
  @order.line_items.each do |item|
30
30
  taxed_items = taxes.line_item_taxes.select { |element| element.item_id == item.id }
31
+ item.tax_category_id = item.variant_tax_category_id
31
32
  update_adjustments(item, taxed_items)
32
33
  end
33
34
 
@@ -113,7 +113,7 @@ module Spree
113
113
  # It also fits the criteria for sales tax as outlined here:
114
114
  # http://www.boe.ca.gov/formspubs/pub113/
115
115
  update_promotions
116
- update_taxes
116
+ update_tax_adjustments
117
117
  update_item_totals
118
118
  end
119
119
 
@@ -198,21 +198,8 @@ module Spree
198
198
  Spree::Config.promotions.order_adjuster_class.new(order).call
199
199
  end
200
200
 
201
- def update_taxes
201
+ def update_tax_adjustments
202
202
  Spree::Config.tax_adjuster_class.new(order).adjust!
203
-
204
- [*line_items, *shipments].each do |item|
205
- tax_adjustments = item.adjustments.select(&:tax?)
206
- # Tax adjustments come in not one but *two* exciting flavours:
207
- # Included & additional
208
-
209
- # Included tax adjustments are those which are included in the price.
210
- # These ones should not affect the eventual total price.
211
- #
212
- # Additional tax adjustments are the opposite, affecting the final total.
213
- item.included_tax_total = tax_adjustments.select(&:included?).sum(&:amount)
214
- item.additional_tax_total = tax_adjustments.reject(&:included?).sum(&:amount)
215
- end
216
203
  end
217
204
 
218
205
  def update_cancellations
@@ -221,21 +208,17 @@ module Spree
221
208
 
222
209
  def update_item_totals
223
210
  [*line_items, *shipments].each do |item|
224
- # The cancellation_total isn't persisted anywhere but is included in
225
- # the adjustment_total
226
- item.adjustment_total = item.adjustments.
227
- reject(&:included?).
228
- sum(&:amount)
229
-
230
- if item.changed?
231
- item.update_columns(
232
- promo_total: item.promo_total,
233
- included_tax_total: item.included_tax_total,
234
- additional_tax_total: item.additional_tax_total,
235
- adjustment_total: item.adjustment_total,
236
- updated_at: Time.current,
237
- )
238
- end
211
+ Spree::Config.item_total_class.new(item).recalculate!
212
+
213
+ next unless item.changed?
214
+
215
+ item.update_columns(
216
+ promo_total: item.promo_total,
217
+ included_tax_total: item.included_tax_total,
218
+ additional_tax_total: item.additional_tax_total,
219
+ adjustment_total: item.adjustment_total,
220
+ updated_at: Time.current,
221
+ )
239
222
  end
240
223
  end
241
224
  end
@@ -7,6 +7,7 @@ module Spree
7
7
  #
8
8
  class Payment < Spree::Base
9
9
  include Spree::Payment::Processing
10
+ include Metadata
10
11
 
11
12
  IDENTIFIER_CHARS = (('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze
12
13
  NON_RISKY_AVS_CODES = ['B', 'D', 'H', 'J', 'M', 'Q', 'T', 'V', 'X', 'Y'].freeze
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # This is the base class used for crafting permission sets.
6
+ #
7
+ # This is used by {Spree::RoleConfiguration} when adding custom behavior to {Spree::Ability}.
8
+ # See one of the subclasses for example structure such as {Spree::PermissionSets::UserDisplay}
9
+ #
10
+ # @see Spree::RoleConfiguration
11
+ # @see Spree::PermissionSets
12
+ class Base
13
+ # @param ability [CanCan::Ability]
14
+ # The ability that will be extended with the current permission set.
15
+ # The ability passed in must respond to #user
16
+ def initialize(ability)
17
+ @ability = ability
18
+ end
19
+
20
+ # Activate permissions on the ability. Put your can and cannot statements here.
21
+ # Must be overridden by subclasses
22
+ def activate!
23
+ raise NotImplementedError.new
24
+ end
25
+
26
+ # Provide the permission set privilege in the form of a :symbol.
27
+ # Must be overridden by subclasses.
28
+ def self.privilege
29
+ raise NotImplementedError, "Subclass #{name} must define a privilege using `self.privilege :symbol`"
30
+ end
31
+
32
+ # Provide the permission set category in the form of a :symbol.
33
+ # Must be overridden by subclasses.
34
+ def self.category
35
+ raise NotImplementedError, "Subclass #{name} must define a category using `self.category :symbol`"
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :ability
41
+
42
+ delegate :can, :cannot, :user, to: :ability
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Read-only permissions for e-commerce settings.
6
+ #
7
+ # Roles with this permission will be able to view information, also from the admin
8
+ # panel, about:
9
+ #
10
+ # - Tax categories
11
+ # - Tax rates
12
+ # - Zones
13
+ # - Countries
14
+ # - States
15
+ # - Payment methods
16
+ # - Taxonomies
17
+ # - Shipping methods
18
+ # - Shipping categories
19
+ # - Stock locations
20
+ # - Stock movements
21
+ # - Refund reasons
22
+ # - Reimbursement types
23
+ # - Return reasons
24
+ class ConfigurationDisplay < PermissionSets::Base
25
+ class << self
26
+ def privilege
27
+ :display
28
+ end
29
+
30
+ def category
31
+ :configuration
32
+ end
33
+ end
34
+
35
+ def activate!
36
+ can [:read, :admin], Spree::TaxCategory
37
+ can [:read, :admin], Spree::TaxRate
38
+ can [:read, :admin], Spree::Zone
39
+ can [:read, :admin], Spree::Country
40
+ can [:read, :admin], Spree::State
41
+ can [:read, :admin], Spree::PaymentMethod
42
+ can [:read, :admin], Spree::Taxonomy
43
+ can [:read, :admin], Spree::ShippingMethod
44
+ can [:read, :admin], Spree::ShippingCategory
45
+ can [:read, :admin], Spree::StockLocation
46
+ can [:read, :admin], Spree::StockMovement
47
+ can [:read, :admin], Spree::RefundReason
48
+ can [:read, :admin], Spree::ReimbursementType
49
+ can [:read, :admin], Spree::ReturnReason
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Read and write permissions for e-commerce settings.
6
+ #
7
+ # Roles with this permission set will have full control over:
8
+ #
9
+ # - Tax categories
10
+ # - Tax rates
11
+ # - Zones
12
+ # - Countries
13
+ # - States
14
+ # - Payment methods
15
+ # - Taxonomies
16
+ # - Shipping methods
17
+ # - Shipping categories
18
+ # - Stock locations
19
+ # - Stock movements
20
+ # - Refund reasons
21
+ # - Reimbursement types
22
+ # - Return reasons
23
+ class ConfigurationManagement < PermissionSets::Base
24
+ class << self
25
+ def privilege
26
+ :management
27
+ end
28
+
29
+ def category
30
+ :configuration
31
+ end
32
+ end
33
+
34
+ def activate!
35
+ can :manage, Spree::TaxCategory
36
+ can :manage, Spree::TaxRate
37
+ can :manage, Spree::Zone
38
+ can :manage, Spree::Country
39
+ can :manage, Spree::State
40
+ can :manage, Spree::PaymentMethod
41
+ can :manage, Spree::Taxonomy
42
+ can :manage, Spree::ShippingMethod
43
+ can :manage, Spree::ShippingCategory
44
+ can :manage, Spree::StockLocation
45
+ can :manage, Spree::StockMovement
46
+ can :manage, Spree::RefundReason
47
+ can :manage, Spree::ReimbursementType
48
+ can :manage, Spree::ReturnReason
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Permissions for viewing the admin dashboard.
6
+ #
7
+ # Roles with this permission set will be able to view the admin dashboard,
8
+ # which may or not contain sensitive information depending on
9
+ # customizations.
10
+ class DashboardDisplay < PermissionSets::Base
11
+ class << self
12
+ def privilege
13
+ :other
14
+ end
15
+
16
+ def category
17
+ :dashboard_display
18
+ end
19
+ end
20
+
21
+ def activate!
22
+ Spree.deprecator.warn "The #{self.class.name} module is deprecated. " \
23
+ "If you still use dashboards, please copy all controllers and views from #{self.class.name} to your application."
24
+ can [:admin, :home], :dashboards
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Permissions for e-commerce customers.
6
+ #
7
+ # This permission set is always added to the `:default` role, which in turn
8
+ # is the default role for all users without any explicit roles.
9
+ #
10
+ # Permissions include reading and updating orders when the ability's user
11
+ # has been assigned as the order's user, unless the order is already
12
+ # completed. Same is true for guest checkout orders.
13
+ #
14
+ # It grants read-only permissions for the following resources typically used
15
+ # during a checkout process:
16
+ #
17
+ # - Zones
18
+ # - Countries
19
+ # - States
20
+ # - Taxons
21
+ # - Taxonomies
22
+ # - Products
23
+ # - Properties
24
+ # - Product properties
25
+ # - Variants
26
+ # - Option types
27
+ # - Option values
28
+ # - Stock items
29
+ # - Stock locations
30
+ #
31
+ # Abilities with this role can also create refund authorizations for orders
32
+ # with the same user, as well as reading and updating the user record and
33
+ # their associated cards.
34
+ class DefaultCustomer < PermissionSets::Base
35
+ class << self
36
+ def privilege
37
+ :other
38
+ end
39
+
40
+ def category
41
+ :default_customer
42
+ end
43
+ end
44
+
45
+ def activate!
46
+ can :read, Country
47
+ can :read, OptionType
48
+ can :read, OptionValue
49
+ can :create, Order do |order, token|
50
+ # same user, or both nil
51
+ order.user == user ||
52
+ # guest checkout order
53
+ order.email.present? ||
54
+ # via API, just like with show and update
55
+ (order.guest_token.present? && token == order.guest_token)
56
+ end
57
+ can [:show, :update], Order, Order.where(user:) do |order, token|
58
+ order.user == user || (order.guest_token.present? && token == order.guest_token)
59
+ end
60
+ cannot :update, Order do |order|
61
+ order.completed?
62
+ end
63
+ can :create, ReturnAuthorization do |return_authorization|
64
+ return_authorization.order.user == user
65
+ end
66
+ can [:read, :update], CreditCard, user_id: user.id
67
+ can :read, Product
68
+ can :read, ProductProperty
69
+ can :read, Property
70
+ can :create, Spree.user_class
71
+ can [:show, :update, :update_email], Spree.user_class, id: user.id
72
+ can :read, State
73
+ can :read, StockItem, stock_location: { active: true }
74
+ can :read, StockLocation, active: true
75
+ can :read, Taxon
76
+ can :read, Taxonomy
77
+ can [:save_in_address_book, :remove_from_address_book], Spree.user_class, id: user.id
78
+ can [:read, :view_out_of_stock], Variant
79
+ can :read, Zone
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Read permissions for orders.
6
+ #
7
+ # This permission set allows users to view all related information about
8
+ # orders, also from the admin panel, including:
9
+ #
10
+ # - Orders
11
+ # - Payments
12
+ # - Shipments
13
+ # - Adjustments
14
+ # - Line items
15
+ # - Return authorizations
16
+ # - Customer returns
17
+ # - Order cancellations
18
+ # - Reimbursements
19
+ # - Return items
20
+ # - Refunds
21
+ #
22
+ # However, it does not allow any modifications to be made to any of these
23
+ # resources.
24
+ class OrderDisplay < PermissionSets::Base
25
+ class << self
26
+ def privilege
27
+ :display
28
+ end
29
+
30
+ def category
31
+ :order
32
+ end
33
+ end
34
+
35
+ def activate!
36
+ can [:read, :admin, :edit, :cart], Spree::Order
37
+ can [:read, :admin], Spree::Payment
38
+ can [:read, :admin], Spree::Shipment
39
+ can [:read, :admin], Spree::Adjustment
40
+ can [:read, :admin], Spree::LineItem
41
+ can [:read, :admin], Spree::ReturnAuthorization
42
+ can [:read, :admin], Spree::CustomerReturn
43
+ can [:read, :admin], Spree::OrderCancellations
44
+ can [:read, :admin], Spree::Reimbursement
45
+ can [:read, :admin], Spree::ReturnItem
46
+ can [:read, :admin], Spree::Refund
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Full permissions for order management.
6
+ #
7
+ # This permission set grants full control over all order and related resources,
8
+ # including:
9
+ #
10
+ # - Orders
11
+ # - Payments
12
+ # - Shipments
13
+ # - Adjustments
14
+ # - Line items
15
+ # - Return authorizations
16
+ # - Customer returns
17
+ # - Order cancellations
18
+ # - Reimbursements
19
+ # - Return items
20
+ # - Refunds
21
+ #
22
+ # It also allows reading reimbursement types, but not modifying them.
23
+ class OrderManagement < PermissionSets::Base
24
+ class << self
25
+ def privilege
26
+ :management
27
+ end
28
+
29
+ def category
30
+ :order
31
+ end
32
+ end
33
+
34
+ def activate!
35
+ can :read, Spree::ReimbursementType
36
+ can :manage, Spree::Order
37
+ can :manage, Spree::Payment
38
+ can :manage, Spree::Shipment
39
+ can :manage, Spree::Adjustment
40
+ can :manage, Spree::LineItem
41
+ can :manage, Spree::ReturnAuthorization
42
+ can :manage, Spree::CustomerReturn
43
+ can :manage, Spree::OrderCancellations
44
+ can :manage, Spree::Reimbursement
45
+ can :manage, Spree::ReturnItem
46
+ can :manage, Spree::Refund
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PermissionSets
5
+ # Read-only permissions for products.
6
+ #
7
+ # This permission set allows users to view all related information about
8
+ # products, also from the admin panel, including:
9
+ #
10
+ # - Products
11
+ # - Images
12
+ # - Variants
13
+ # - Option values
14
+ # - Product properties
15
+ # - Option types
16
+ # - Properties
17
+ # - Taxonomies
18
+ # - Taxons
19
+ class ProductDisplay < PermissionSets::Base
20
+ class << self
21
+ def privilege
22
+ :display
23
+ end
24
+
25
+ def category
26
+ :product
27
+ end
28
+ end
29
+
30
+ def activate!
31
+ can [:read, :admin, :edit], Spree::Product
32
+ can [:read, :admin], Spree::Image
33
+ can [:read, :admin], Spree::Variant
34
+ can [:read, :admin], Spree::OptionValue
35
+ can [:read, :admin], Spree::ProductProperty
36
+ can [:read, :admin], Spree::OptionType
37
+ can [:read, :admin], Spree::Property
38
+ can [:read, :admin], Spree::Taxonomy
39
+ can [:read, :admin], Spree::Taxon
40
+ end
41
+ end
42
+ end
43
+ end