effective_resources 2.11.4 → 2.11.5

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: 85bdb3dc24c4beb4f3558641fc4f209ba7094d052033f766c67e54aa62c34735
4
- data.tar.gz: 8d38b7bbfd0046d29c6489ffbd7373711436c9aecee76b1de111394dabd08ef6
3
+ metadata.gz: 0db1af1cd9888460bd6ba110a0d972925ad88c0221bc77d6fc98a15b44175b31
4
+ data.tar.gz: acb21c1d6a77daec5e2401ee22aa17b60005a46dfc708b06e8b1a5c0b5437196
5
5
  SHA512:
6
- metadata.gz: ecaa55c198d2616bfcfcea71b51adf36cd1f28deef42d698fd6e62c1981da827577f01ee4b1f9d51b4f625dadfd84b71f6c01eed9059f774ca7beb26294aa636
7
- data.tar.gz: 3f76720e84164f7c15cbc08ffe92efdf665cce447d64c13b5ecfe50767769eff0d494b3647f3074156a31b5ce6ef9a48959bd2b6a42eaf1bbefa36d09a5d3ef4
6
+ metadata.gz: a62c534e47770dda823fb51cc30834f1de229c61dae266d1de6f20031c6137ce57782c11f512d83a82bb0a90ca7983b439c94dd55298cdbba5466367d7e057a4
7
+ data.tar.gz: ade2cf04ecca9009abe9b2883252f5064843e83f76232d5ab8e51418370a0297bbe436ea83700d33c8840778cad272f0ffc447930fa10c631b92788c961aa3bc
@@ -48,12 +48,17 @@ module EffectiveDeviseUser
48
48
  # Devise invitable ignores model validations, so we manually check for duplicate email addresses.
49
49
  before_save(if: -> { new_record? && try(:invitation_sent_at).present? }) do
50
50
  if email.blank?
51
- self.errors.add(:email, "can't be blank")
51
+ errors.add(:email, "can't be blank")
52
52
  raise("email can't be blank")
53
53
  end
54
54
 
55
- if self.class.where(email: email.downcase.strip).exists?
56
- self.errors.add(:email, 'has already been taken')
55
+ if self.class.where(email: value).present?
56
+ errors.add(:email, 'has already been taken')
57
+ raise("email has already been taken")
58
+ end
59
+
60
+ if respond_to?(:alternate_email) && self.class.where(alternate_email: value).present?
61
+ errors.add(:email, 'has already been taken')
57
62
  raise("email has already been taken")
58
63
  end
59
64
  end
@@ -63,25 +68,29 @@ module EffectiveDeviseUser
63
68
  assign_attributes(provider: nil, access_token: nil, refresh_token: nil, token_expires_at: nil)
64
69
  end
65
70
 
71
+ validate(if: -> { email.present? && try(:alternate_email).present? }) do
72
+ errors.add(:alternate_email, 'cannot be the same as email') if email.strip.downcase == alternate_email.strip.downcase
73
+ end
74
+
66
75
  # Uniqueness validation of emails and alternate emails across all users
67
76
  validate(if: -> { respond_to?(:alternate_email) }) do
68
- records = self.class.where.not(id: self.id) # exclude self
69
- email_duplicates = records.where("lower(email) = :email OR lower(alternate_email) = :email", email: email.to_s.strip.downcase)
70
- alternate_email_duplicates = records.where("lower(email) = :alternate_email OR lower(alternate_email) = :alternate_email", alternate_email: alternate_email.to_s.strip.downcase)
77
+ records = self.class.where.not(id: id)
71
78
 
72
- # Check if a uniqueness validation was already performed before triggering the exists query
73
- if !self.errors.added?(:email, 'has already been taken') && email_duplicates.exists?
74
- self.errors.add(:email, 'has already been taken')
79
+ # Validate email uniqueness
80
+ if (value = email.to_s.strip.downcase).present? && !errors.added?(:email, 'has already been taken')
81
+ existing = records.where("email = :value OR alternate_email = :value", value: value)
82
+ errors.add(:email, 'has already been taken') if existing.present?
75
83
  end
76
84
 
77
- # Check if the alternate email is set before triggering the exists query
78
- if try(:alternate_email).present? && alternate_email_duplicates.exists?
79
- self.errors.add(:alternate_email, 'has already been taken')
85
+ # Validate alternate_email uniqueness
86
+ if (value = alternate_email.to_s.strip.downcase).present?
87
+ existing = records.where("email = :value OR alternate_email = :value", value: value)
88
+ errors.add(:alternate_email, 'has already been taken') if existing.present?
80
89
  end
81
90
  end
82
91
 
83
92
  with_options(if: -> { respond_to?(:alternate_email) }) do
84
- validates :alternate_email, email: true, allow_blank: true
93
+ validates :alternate_email, email: true
85
94
  end
86
95
 
87
96
  end
@@ -6,13 +6,11 @@ module EffectiveResources
6
6
 
7
7
  config.autoload_paths += Dir[
8
8
  "#{config.root}/jobs/",
9
- "#{config.root}/lib/validators/",
10
9
  "#{config.root}/app/controllers/concerns/"
11
10
  ]
12
11
 
13
12
  config.eager_load_paths += Dir[
14
13
  "#{config.root}/jobs/",
15
- "#{config.root}/lib/validators/",
16
14
  "#{config.root}/app/controllers/concerns/"
17
15
  ]
18
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.11.4'.freeze
2
+ VERSION = '2.11.5'.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.11.4
4
+ version: 2.11.5
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-10-13 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -223,8 +223,12 @@ 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/boolean_validator.rb
226
227
  - app/validators/content_type_validator.rb
228
+ - app/validators/email_cc_validator.rb
229
+ - app/validators/email_validator.rb
227
230
  - app/validators/size_validator.rb
231
+ - app/validators/url_validator.rb
228
232
  - app/views/application/_flash.html.haml
229
233
  - app/views/application/create.js.erb
230
234
  - app/views/application/destroy.js.erb
@@ -251,10 +255,6 @@ files:
251
255
  - lib/effective_resources/engine.rb
252
256
  - lib/effective_resources/version.rb
253
257
  - lib/generators/effective_resources/install_generator.rb
254
- - lib/validators/boolean_validator.rb
255
- - lib/validators/email_cc_validator.rb
256
- - lib/validators/email_validator.rb
257
- - lib/validators/url_validator.rb
258
258
  homepage: https://github.com/code-and-effect/effective_resources
259
259
  licenses:
260
260
  - MIT
File without changes
File without changes
File without changes
File without changes