effective_resources 2.8.2 → 2.8.4

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: 13d2181e7cf9ab5d68d9b25302761489380f890e0c9046e545a5c2fcb854be0b
4
+ data.tar.gz: e4639dbcdb1cd89cebe4c0a196c5cf973b089b35cf24261a3c1ea70854fb5c59
5
5
  SHA512:
6
- metadata.gz: 490636b3efc23c0406833448528f2e8029d9d707a49db92309eda2d65fff6be90d7c31c9d835827866d953b9c18a13781aeb11b43f606c411b051037f0c6f1ed
7
- data.tar.gz: 1dc0516ce102fac154bfc374deee17678f4d4f33906a2e90bf96e175d5af0573faff5800749c5fff3f198110a3ef142b3fdb1b341e21aef3656a1388e6c4352b
6
+ metadata.gz: e2ee62822958ebf3be1872c0926c10cae4ffa140aab91e9201b4dc781222f6ee8f92f8bf0269209296c6dc334f49fc13582e6f71e7d42f3ae081059fa3c5bd2d
7
+ data.tar.gz: 55894ca40b3e35d3ac800715bf9c906af9253cc3bad75b5a8a4bb01b2cb9b36b5e2d1f9a74818ac9ccfd72a70305f64c7f94a519afd66a21a6184e0d6a5d1679
@@ -31,7 +31,7 @@ module Effective
31
31
 
32
32
  # Duplicate if possible
33
33
  if params[:duplicate_id]
34
- duplicate = resource_scope.find_by_id(params[:duplicate_id])
34
+ duplicate = resource_scope.find_by_id(params[:duplicate_id]) || resource_scope.find(params[:duplicate_id])
35
35
  EffectiveResources.authorize!(self, :show, duplicate)
36
36
 
37
37
  self.resource = duplicate_resource(duplicate)
@@ -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.4'.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.4
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