effective_resources 2.25.4 → 2.25.6

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: 2967108f64775ddd3de0531e80509fe3f4c4b369fdb3b2b59a96103b2082e516
4
- data.tar.gz: 1a53e6935d666e80676aed79910447929aad82d45dad2430a82093d85af70056
3
+ metadata.gz: 281dfe01432d3d514f46f43b7c0d76478b4675827581c2b9867ab14af1f51aae
4
+ data.tar.gz: 7edf326e2bd629a49b812e5ee96749e0ad95fb5b81d87d18b14a7452134af78a
5
5
  SHA512:
6
- metadata.gz: f3e0d13115d6e1acdea84ee206a3bfc31fe3885b2f6384332a36f1bedeaf33f85f5066c8e364396998a627249df7d99ba3495c0d14117139ad9d6db0e09d76eb
7
- data.tar.gz: e35ddd7ed8a8dcfce32a96a205a4aa9b8ca050b64d6accc3b7e4f134c9e7c04dd728a84426671f72afa3f2512d38f9f752b9e043a7c01efc7b19aa3c09a20e23
6
+ metadata.gz: 5e0af3a5c4f970d6c637a1429cf252875274a605c92c328fa87e05b9df4366b1924e466ab76e12c8be12f0980ae8dc091de5bc665de34307e6774d9c96bd7fe1
7
+ data.tar.gz: 85ea2f2757651bd051e549da3356d79729ec235776ae8eb35f00037f9616cd16ce5b08772a39fef6656f3926b137e4d6a1fdb9650cb45a60082b88cd29fbc07f
@@ -42,7 +42,8 @@ module Effective
42
42
 
43
43
  # Duplicate if possible
44
44
  if params[:duplicate_id].present?
45
- duplicate = resource_scope.find(params[:duplicate_id])
45
+ duplicate = (resource_scope.find(params[:duplicate_id]) rescue false)
46
+ duplicate ||= resource_scope.find_by_id(params[:duplicate_id])
46
47
 
47
48
  EffectiveResources.authorize!(self, :show, duplicate)
48
49
 
@@ -56,6 +56,15 @@ module Effective
56
56
 
57
57
  private
58
58
 
59
+ def to_masked_select2(resource)
60
+ if resource.respond_to?(:public_email)
61
+ "<span>#{resource}</span> <small>#{view_context.masked_email(resource)}</small>"
62
+ elsif resource.try(:email).present?
63
+ "<span>#{resource}</span> <small>#{resource.email}</small>"
64
+ else
65
+ "<span>#{resource}</span>"
66
+ end
67
+
59
68
  def to_select2(resource)
60
69
  if resource.try(:email).present?
61
70
  "<span>#{resource}</span> <small>#{resource.email}</small>"
@@ -11,7 +11,7 @@ module EffectiveResourcesEmailHelper
11
11
  end
12
12
 
13
13
  # acts_as_email_form
14
- def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
14
+ def email_form_fields(form, action = nil, skip: true, skip_link: nil, to: nil, variables: nil, partial: nil)
15
15
  raise('expected a form') unless form.respond_to?(:object)
16
16
 
17
17
  resource = form.object
@@ -26,7 +26,11 @@ module EffectiveResourcesEmailHelper
26
26
  action.kind_of?(Effective::EmailTemplate) ? action : Effective::EmailTemplate.where(template_name: action).first!
27
27
  end
28
28
 
29
+ # Display link to the admin email template
30
+ skip_link = !request.path.start_with?('/admin/') if skip_link.nil?
31
+
29
32
  # These defaults are only used when there is no email_template
33
+ # This can't happen right now.
30
34
  email_defaults = form.object.email_form_defaults(action) unless email_template.present?
31
35
 
32
36
  from = email_template&.from || email_defaults[:from] || EffectiveResources.mailer_froms.first
@@ -44,7 +48,8 @@ module EffectiveResourcesEmailHelper
44
48
  email_skip: skip,
45
49
  email_action: (action || true),
46
50
  email_template: email_template,
47
- email_variables: variables
51
+ email_variables: variables,
52
+ email_skip_link: skip_link
48
53
  }
49
54
 
50
55
  render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
@@ -323,6 +323,18 @@ module EffectiveResourcesHelper
323
323
  EffectiveResources.etsd(resource, attribute)
324
324
  end
325
325
 
326
+ def masked_email(resource)
327
+ public_email = resource.try(:public_email)
328
+ return public_email if public_email.present?
326
329
 
330
+ email = resource.email
331
+ return email if email.blank?
332
+
333
+ local, domain = email.split('@')
334
+ masked_local = local[0..1] + '*' * (local.length - 2)
335
+ masked_domain = domain.split('.').first[0..1] + '*' * (domain.split('.').first.length - 2) + '.' + domain.split('.').last
336
+
337
+ "#{masked_local}@#{masked_domain}"
338
+ end
327
339
 
328
340
  end
@@ -22,8 +22,12 @@ module ActsAsPublished
22
22
  included do
23
23
  attr_writer :save_as_draft
24
24
 
25
- before_validation do
26
- assign_attributes(published_start_at: nil, published_end_at: nil) if EffectiveResources.truthy?(@save_as_draft)
25
+ before_validation(if: -> { EffectiveResources.falsey?(@save_as_draft) && @save_as_draft.present? }) do
26
+ self.published_start_at ||= Time.zone.now
27
+ end
28
+
29
+ before_validation(if: -> { EffectiveResources.truthy?(@save_as_draft) }) do
30
+ assign_attributes(published_start_at: nil, published_end_at: nil)
27
31
  end
28
32
 
29
33
  validate(if: -> { published_start_at.present? && published_end_at.present? }) do
@@ -291,4 +291,8 @@ module EffectiveDeviseUser
291
291
  devise_mailer.send(notification, self, *args).deliver_now
292
292
  end
293
293
 
294
+ def to_select2_search_columns
295
+ [:email, :public_email, :first_name, :last_name, :name]
296
+ end
297
+
294
298
  end
@@ -1,5 +1,8 @@
1
1
  = form.hidden_field :email_form_action, value: email_action
2
2
 
3
+ - if email_template.present? && !email_skip_link
4
+ %p The following #{link_to(email_template, effective_email_templates.edit_admin_email_template_path(email_template), target: '_blank')} email will be sent:
5
+
3
6
  - if email_skip
4
7
  = form.check_box :email_form_skip, label: 'Do not send email'
5
8
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.25.4'.freeze
2
+ VERSION = '2.25.6'.freeze
3
3
  end
@@ -127,6 +127,10 @@ module EffectiveResources
127
127
  end
128
128
  end
129
129
 
130
+ def self.falsey?(value)
131
+ !truthy?(value)
132
+ end
133
+
130
134
  def self.advance_date(date, business_days: 1, holidays: [:us, :observed])
131
135
  raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
132
136
 
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.25.4
4
+ version: 2.25.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: 2024-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails