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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3306eaeb2757f8d71427567e38353c13c2ff2b7ebc9bfd4fa59dbfe24af3ed9
|
4
|
+
data.tar.gz: 561544b09df06f7210d0dd07a48547ac3b2d8661654fb0129e92f7ad413a4a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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-
|
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
|