effective_resources 2.11.4 → 2.11.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85bdb3dc24c4beb4f3558641fc4f209ba7094d052033f766c67e54aa62c34735
4
- data.tar.gz: 8d38b7bbfd0046d29c6489ffbd7373711436c9aecee76b1de111394dabd08ef6
3
+ metadata.gz: df20052518286a1ff3271eddb3e9007211d31ac6702cc4bb87ddf0c6706a0a31
4
+ data.tar.gz: 15b0d4740305154619c1cf4922ed567811149c60966d63d2c737c6306a2b8e1c
5
5
  SHA512:
6
- metadata.gz: ecaa55c198d2616bfcfcea71b51adf36cd1f28deef42d698fd6e62c1981da827577f01ee4b1f9d51b4f625dadfd84b71f6c01eed9059f774ca7beb26294aa636
7
- data.tar.gz: 3f76720e84164f7c15cbc08ffe92efdf665cce447d64c13b5ecfe50767769eff0d494b3647f3074156a31b5ce6ef9a48959bd2b6a42eaf1bbefa36d09a5d3ef4
6
+ metadata.gz: eccffe9230dd0ee3119e04c48cc8b05374d73d29ca18c7d5344c7d6be3cf39362622cadf17265b0f146773bd0be3dd77276b5988832d82c641c8c0f1f348a4c7
7
+ data.tar.gz: ab946a0050800cab2698955c69cdd27911ec110f7a68dacd19ef975b7800e2eadd1145c456f660d775b3f985d4e1e6a9f62776363191d78fae68f08ea0e81bb9
@@ -48,12 +48,19 @@ 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
+ value = email.strip.downcase
56
+
57
+ if self.class.where(email: value).present?
58
+ errors.add(:email, 'has already been taken')
59
+ raise("email has already been taken")
60
+ end
61
+
62
+ if respond_to?(:alternate_email) && self.class.where(alternate_email: value).present?
63
+ errors.add(:email, 'has already been taken')
57
64
  raise("email has already been taken")
58
65
  end
59
66
  end
@@ -63,25 +70,29 @@ module EffectiveDeviseUser
63
70
  assign_attributes(provider: nil, access_token: nil, refresh_token: nil, token_expires_at: nil)
64
71
  end
65
72
 
73
+ validate(if: -> { email.present? && try(:alternate_email).present? }) do
74
+ errors.add(:alternate_email, 'cannot be the same as email') if email.strip.downcase == alternate_email.strip.downcase
75
+ end
76
+
66
77
  # Uniqueness validation of emails and alternate emails across all users
67
78
  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)
79
+ records = self.class.where.not(id: id)
71
80
 
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')
81
+ # Validate email uniqueness
82
+ if (value = email.to_s.strip.downcase).present? && !errors.added?(:email, 'has already been taken')
83
+ existing = records.where("email = :value OR alternate_email = :value", value: value)
84
+ errors.add(:email, 'has already been taken') if existing.present?
75
85
  end
76
86
 
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')
87
+ # Validate alternate_email uniqueness
88
+ if (value = alternate_email.to_s.strip.downcase).present?
89
+ existing = records.where("email = :value OR alternate_email = :value", value: value)
90
+ errors.add(:alternate_email, 'has already been taken') if existing.present?
80
91
  end
81
92
  end
82
93
 
83
94
  with_options(if: -> { respond_to?(:alternate_email) }) do
84
- validates :alternate_email, email: true, allow_blank: true
95
+ validates :alternate_email, email: true
85
96
  end
86
97
 
87
98
  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.6'.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.6
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