effective_resources 2.8.2 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0140383360a1897a1b21a4a5897f5e61d9099210ab1fca6fe8e93159c7bdc999'
4
- data.tar.gz: 33819637928fe7fdb8e75df61f79526228652142fc76ab09222bed6ed9f91e6a
3
+ metadata.gz: a3306eaeb2757f8d71427567e38353c13c2ff2b7ebc9bfd4fa59dbfe24af3ed9
4
+ data.tar.gz: 561544b09df06f7210d0dd07a48547ac3b2d8661654fb0129e92f7ad413a4a56
5
5
  SHA512:
6
- metadata.gz: 490636b3efc23c0406833448528f2e8029d9d707a49db92309eda2d65fff6be90d7c31c9d835827866d953b9c18a13781aeb11b43f606c411b051037f0c6f1ed
7
- data.tar.gz: 1dc0516ce102fac154bfc374deee17678f4d4f33906a2e90bf96e175d5af0573faff5800749c5fff3f198110a3ef142b3fdb1b341e21aef3656a1388e6c4352b
6
+ metadata.gz: e7ca40c7ee7b3aa67659a45f62ecc86bd34e1ca3454f1baf0c601cd4437b960064ad9b58645dca6cfac931e327e86cbb39875dcda44eff32459caa7c94d6649c
7
+ data.tar.gz: 1489d7f93a9a8429f4cabe58c113864e7193f681feb6fc012ed2788d79b9be7f0ced3e12ae3622b30fd7beb122716249e987705f0b981f3f5df8b09e9c909a59
@@ -72,8 +72,10 @@ module ActsAsPurchasableWizard
72
72
  # From Billing Step
73
73
  order.billing_address = owner.billing_address if owner.try(:billing_address).present?
74
74
 
75
+ # This will update all order items to match the prices from their
76
+ order.try(:update_purchasable_attributes)
77
+
75
78
  # Important to add/remove anything
76
- # This will update the prices, but the purchasables must be persisted
77
79
  order.save!
78
80
 
79
81
  order
@@ -0,0 +1,50 @@
1
+ #
2
+ # Custom validator for attachments' content types
3
+ #
4
+ # @example
5
+ #
6
+ # -> validates :image, content_type: :image
7
+ # -> validates :image, content_type: [:jpg, :webp]
8
+ # -> validates :image, content_type: [:image, :pdf]
9
+ # -> validates :image, content_type: { in: :image, message: 'must be a valid image' }
10
+ #
11
+ class ContentTypeValidator < ActiveModel::EachValidator
12
+ EXPANSIONS = {
13
+ image: %i[png jpeg jpg jpe pjpeg gif bmp svg webp],
14
+ document: %i[text txt docx doc xml pdf csv],
15
+ calendar: %i[ics],
16
+ spreadsheet: %i[xlsx xls],
17
+ video: %i[mpeg mpg mp3 m4a mpg4 aac webm mp4 m4v],
18
+ }.freeze
19
+
20
+ def validate_each(record, attribute, value)
21
+ # Support for optional attachments
22
+ return unless value.present? && value.attached?
23
+
24
+ keys = EXPANSIONS.keys
25
+ values = EXPANSIONS.values.flatten
26
+ options = instance_values["options"]
27
+ message = options.try(:[], :message) || "must have a valid content type"
28
+ types = options[:with] || options[:in]
29
+
30
+ # Ensure array and ensure symbols
31
+ types = [types].flatten.compact.map(&:to_sym)
32
+
33
+ allowed_types = []
34
+ types.each do |types|
35
+ if types.in?(keys)
36
+ allowed_types << EXPANSIONS[types]
37
+ elsif types.in?(values)
38
+ allowed_types << types
39
+ else
40
+ raise("unknown content_type types: #{types}")
41
+ end
42
+ end
43
+ allowed_types = allowed_types.flatten.map(&:to_sym).uniq
44
+
45
+ unless value.filename.extension.to_sym.in?(allowed_types)
46
+ record.errors.add(attribute, message)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Custom validator for file sizes
3
+ #
4
+ # @example
5
+ #
6
+ # -> validates :image, size: { less_than: 2.megabytes }
7
+ # -> validates :image, size: { less_than: 2.megabytes, message: 'is too large, please upload a file smaller than 2MB' }
8
+ #
9
+ class SizeValidator < ActiveModel::EachValidator
10
+ def validate_each(record, attribute, value)
11
+ return unless value.present? && value.attached?
12
+
13
+ options = instance_values["options"]
14
+
15
+ max_size = options.try(:[], :less_than) || 2.megabytes
16
+ message = options.try(:[], :message) || "is too large, please upload a file smaller than #{max_size / 1.megabyte}MB"
17
+
18
+ if value.blob.byte_size > max_size
19
+ record.errors.add(attribute, message)
20
+ end
21
+
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.8.2'.freeze
2
+ VERSION = '2.8.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2
4
+ version: 2.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-16 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -223,6 +223,8 @@ files:
223
223
  - app/models/effective/resources/relation.rb
224
224
  - app/models/effective/resources/sql.rb
225
225
  - app/models/effective/resources/tenants.rb
226
+ - app/validators/content_type_validator.rb
227
+ - app/validators/size_validator.rb
226
228
  - app/views/application/_flash.html.haml
227
229
  - app/views/application/create.js.erb
228
230
  - app/views/application/destroy.js.erb