effective_resources 2.11.3 → 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: 812cfa2dff0975f437ae27401f0514ffda1e9e0f63656ed9a108d36994e6f54e
4
- data.tar.gz: 3abb1076d4711aacaeeec65dd3cc0c37d5e9c10d07ee254f6a8b870a626e115a
3
+ metadata.gz: 0db1af1cd9888460bd6ba110a0d972925ad88c0221bc77d6fc98a15b44175b31
4
+ data.tar.gz: acb21c1d6a77daec5e2401ee22aa17b60005a46dfc708b06e8b1a5c0b5437196
5
5
  SHA512:
6
- metadata.gz: bd3bf2b4b9073a4097c86a4cc8ba7e9199080f4ce835431be533e20227728fc389b72d5fdf4aeccb2f71818bb312db477df0db42d2f3b4f5017ce527cb964b86
7
- data.tar.gz: ab42b89c90b2bd741e325148dab189fc600e49da80dec0596dfeb238ada7daa5f9edef3a8bf497d7bdce0004edbcf98d9a06b8a03afcf1b62272da398e4f97f5
6
+ metadata.gz: a62c534e47770dda823fb51cc30834f1de229c61dae266d1de6f20031c6137ce57782c11f512d83a82bb0a90ca7983b439c94dd55298cdbba5466367d7e057a4
7
+ data.tar.gz: ade2cf04ecca9009abe9b2883252f5064843e83f76232d5ab8e51418370a0297bbe436ea83700d33c8840778cad272f0ffc447930fa10c631b92788c961aa3bc
@@ -96,7 +96,7 @@ module ActsAsStatused
96
96
  id = status_steps[sym_by_id]
97
97
  klass = status_steps[sym_by_type]
98
98
 
99
- klass.constantize.find(id) if id.present? && klass.present?
99
+ klass.constantize.find_by_id(id) if id.present? && klass.present?
100
100
  end
101
101
  end
102
102
 
@@ -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.3'.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.3
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-09-25 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