effective_resources 2.11.1 → 2.11.3

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: 70b3835f1e45128ade83d38d69adbcd8096fd5aecce4882028d0512dab970dae
4
- data.tar.gz: 7c38e5cb62a55b4fa4924970aad1b0f45cf06b0dccedb41770f8df394e98a9c0
3
+ metadata.gz: 812cfa2dff0975f437ae27401f0514ffda1e9e0f63656ed9a108d36994e6f54e
4
+ data.tar.gz: 3abb1076d4711aacaeeec65dd3cc0c37d5e9c10d07ee254f6a8b870a626e115a
5
5
  SHA512:
6
- metadata.gz: 50be7d9a989a25f8aa6777e85603c18b8ccc3be72e78aa35e4aa83814ca0fa74371de434c1138dc9a2331b57d79c1e032dbf987628c2b3b800b8b3819b26eb3d
7
- data.tar.gz: 46e3229e7ecc0a7e989ac022afed029183b96e9a225f7a3d93edc3d9ff0a14a37682bf4d1685e1c3ebf3f8c8a5760e0cd09eafc7346eb940bf13d5aecd1752ad
6
+ metadata.gz: bd3bf2b4b9073a4097c86a4cc8ba7e9199080f4ce835431be533e20227728fc389b72d5fdf4aeccb2f71818bb312db477df0db42d2f3b4f5017ce527cb964b86
7
+ data.tar.gz: ab42b89c90b2bd741e325148dab189fc600e49da80dec0596dfeb238ada7daa5f9edef3a8bf497d7bdce0004edbcf98d9a06b8a03afcf1b62272da398e4f97f5
@@ -242,7 +242,7 @@ module Effective
242
242
  successes = resources.select do |resource|
243
243
  begin
244
244
  resource.public_send("#{action}!") if EffectiveResources.authorized?(self, action, resource)
245
- rescue => e
245
+ rescue Exception => e
246
246
  false
247
247
  end
248
248
  end.length
@@ -197,31 +197,39 @@ module EffectiveDeviseUser
197
197
  # https://github.com/heartcombo/devise/blob/f6e73e5b5c8f519f4be29ac9069c6ed8a2343ce4/lib/devise/models/database_authenticatable.rb#L216
198
198
  def find_for_database_authentication(warden_conditions)
199
199
  conditions = warden_conditions.dup.presence || {}
200
- primary_or_alternate_email = conditions[:email]
201
- conditions.delete(:email)
202
200
 
203
- raise "Expected an email #{has_alternate_email? ? 'or alternate email' : ''} but got [#{primary_or_alternate_email}] instead" if primary_or_alternate_email.blank?
201
+ email = conditions.delete(:email).to_s.strip.downcase
202
+ raise "Expected an email condition but got #{conditions} instead" unless email.present?
204
203
 
205
- query = if has_alternate_email?
206
- "lower(email) = :value OR lower(alternate_email) = :value"
207
- else
208
- "lower(email) = :value"
209
- end
210
-
211
- all
212
- .where(conditions)
213
- .where(query, value: primary_or_alternate_email.strip.downcase)
214
- .first
204
+ if has_alternate_email?
205
+ where(conditions).where('email = :email OR alternate_email = :email', email: email).first
206
+ else
207
+ where(conditions).where(email: email).first
208
+ end
215
209
  end
216
210
 
217
211
  def has_alternate_email?
218
- 'alternate_email'.in? column_names
212
+ column_names.include?('alternate_email')
219
213
  end
220
214
 
215
+ def find_by_any_email(value)
216
+ email = value.to_s.strip.downcase
217
+
218
+ if has_alternate_email?
219
+ where(email: email).or(where(alternate_email: email)).first
220
+ else
221
+ where(email: email).first
222
+ end
223
+ end
221
224
  end
222
225
 
223
226
  # EffectiveDeviseUser Instance Methods
224
227
 
228
+ # The user's to_s when in an email
229
+ def email_to_s
230
+ to_s
231
+ end
232
+
225
233
  def alternate_email=(value)
226
234
  super(value.to_s.strip.downcase.presence)
227
235
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.11.1'.freeze
2
+ VERSION = '2.11.3'.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.1
4
+ version: 2.11.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-09-19 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails