effective_messaging 0.7.5 → 0.8.1

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: 7407b82bbf657f12efd728834391a82d5a3f6d2d45e2833e4e092c442a9f87c8
4
- data.tar.gz: 9d5d26c07a3b88e0c8a9786e6c5b35cf75505b647116bd55732b543c163f4756
3
+ metadata.gz: 8d1af8fb6d222cf7dc1f2ad5c9baaf139607cef5f724879fd3bc037107d56b4d
4
+ data.tar.gz: f6315751785d8760aee7adb5593826f6b4ed80639ec1d0f54d1ee95f85462828
5
5
  SHA512:
6
- metadata.gz: 79a35234d7e9857bd44190646ed0cb10eeafe10a92998fe90ca56137ca85943516c6759b3ba0fede7b6902296c5d10a3231569cb49fcd39e5f053be50b83e7f7
7
- data.tar.gz: 28e9c078ca521aecdb71da681074cb5e6fc5b9fa6f14f34e4b5a8625a33c6fc7cda767f21b4dcc3fe19f8db804f92b6d95c7b17f31082090adf1593ebecc680e
6
+ metadata.gz: 657cc27116ca125f8102c2bc4ee1331d9359e673e7b9dc4647509541c217f4ad79c2a11e4dd4014ec0aff7f0b8fab9be45de9a104a8738f2a87d3d16d73dcf64
7
+ data.tar.gz: 5c0de10cdbbf454298c7033f39ed5ca08cfffb51c1f54cd6ee65f5d23872b08fd93267e1f5281eecbc6205493d99e48d04b9c3f47109c4cf178c6d1d6e75723d
@@ -9,7 +9,7 @@ module Admin
9
9
  col :notification
10
10
  col :report, visible: !attributes[:inline]
11
11
  col :resource, search: :string
12
- col :user, search: :string
12
+ col :user, label: 'Source', search: :string
13
13
  col :email
14
14
  col :skipped
15
15
 
@@ -35,7 +35,13 @@ module Effective
35
35
  validates :body, presence: true
36
36
 
37
37
  def to_s
38
- body.presence || 'New Chat Message'
38
+ truncate(body.presence || 'New Chat Message')
39
+ end
40
+
41
+ private
42
+
43
+ def truncate(value)
44
+ value.length > 100 ? (value.first(100) + '...') : value
39
45
  end
40
46
 
41
47
  end
@@ -134,7 +134,7 @@ module Effective
134
134
  validates :report, presence: true
135
135
 
136
136
  validate(if: -> { report.present? }) do
137
- errors.add(:report, 'must include an email or user column') unless report.email_report_column || report.user_report_column
137
+ errors.add(:report, 'must include an email, user, organization or owner column') unless report.email_report_column || report.emailable_report_column
138
138
  end
139
139
 
140
140
  validate(if: -> { report.present? && subject.present? }) do
@@ -347,7 +347,7 @@ module Effective
347
347
  end
348
348
 
349
349
  def already_notified_today?(resource)
350
- email = resource_email(resource) || resource_user(resource).try(:email)
350
+ email = resource_emails_to_s(resource)
351
351
  raise("expected an email for #{report} #{report&.id} and #{resource} #{resource&.id}") unless email.present?
352
352
 
353
353
  logs = notification_logs.select { |log| log.email == email }
@@ -362,7 +362,7 @@ module Effective
362
362
  def notifiable_immediate?(resource:, date: nil)
363
363
  raise('expected an immediate? notification') unless immediate?
364
364
 
365
- email = resource_email(resource) || resource_user(resource).try(:email)
365
+ email = resource_emails_to_s(resource)
366
366
  raise("expected an email for #{report} #{report&.id} and #{resource} #{resource&.id}") unless email.present?
367
367
 
368
368
  logs = notification_logs.select { |log| log.email == email }
@@ -394,12 +394,7 @@ module Effective
394
394
  def render_email(resource = nil)
395
395
  raise('expected an acts_as_reportable resource') if resource.present? && !resource.class.try(:acts_as_reportable?)
396
396
 
397
- to = if audience == 'emails'
398
- audience_emails.presence
399
- elsif audience == 'report'
400
- resource_email(resource) || resource_user(resource).try(:email)
401
- end
402
-
397
+ to = (audience == 'emails' ? audience_emails.presence : resource_emails_to_s(resource))
403
398
  raise('expected a to email address') unless to.present?
404
399
 
405
400
  assigns = assigns_for(resource)
@@ -437,12 +432,12 @@ module Effective
437
432
  end
438
433
 
439
434
  def build_notification_log(resource: nil, skipped: false)
440
- user = resource_user(resource)
435
+ emailable = resource_emailable(resource)
441
436
 
442
- email = resource_email(resource) || user.try(:email)
437
+ email = resource_emails_to_s(resource)
443
438
  email ||= audience_emails_to_s if scheduled_email?
444
439
 
445
- notification_logs.build(email: email, report: report, resource: resource, user: user, skipped: skipped)
440
+ notification_logs.build(email: email, report: report, resource: resource, user: emailable, skipped: skipped)
446
441
  end
447
442
 
448
443
  private
@@ -456,18 +451,31 @@ module Effective
456
451
  end
457
452
 
458
453
  def audience_emails_to_s
459
- audience_emails.presence&.join(',')
454
+ audience_emails.presence&.join(', ')
455
+ end
456
+
457
+ # All emails for this emailable resource
458
+ def resource_emails_to_s(resource)
459
+ emails = Array(resource_email(resource)).map(&:presence).compact
460
+
461
+ if emails.blank? && (emailable = resource_emailable(resource)).present?
462
+ emails = Array(emailable.try(:reportable_emails) || emailable.try(:email)).map(&:presence).compact
463
+ end
464
+
465
+ emails.presence&.join(', ')
460
466
  end
461
467
 
462
- def resource_user(resource)
468
+ # A user, owner, or organization column
469
+ def resource_emailable(resource)
463
470
  return unless resource.present?
464
471
 
465
- column = report&.user_report_column
472
+ column = report&.emailable_report_column
466
473
  return unless column.present?
467
474
 
468
475
  resource.public_send(column.name) || (resource if resource.respond_to?(:email))
469
476
  end
470
477
 
478
+ # An email column
471
479
  def resource_email(resource)
472
480
  return unless resource.present?
473
481
 
@@ -20,7 +20,7 @@ module Effective
20
20
  scope :sorted, -> { order(:id) }
21
21
  scope :deep, -> { includes(:notification, :report, :resource, :user) }
22
22
 
23
- validates :email, presence: true, email: true
23
+ validates :email, presence: true
24
24
 
25
25
  def to_s
26
26
  model_name.human
@@ -0,0 +1,9 @@
1
+ = effective_form_with(model: [:admin, chat_message], engine: true) do |f|
2
+ - unless inline_datatable?
3
+ = f.static_field :chat, label: et(f.object.chat)
4
+
5
+ = f.static_field :name, label: 'From'
6
+ = f.text_area :body
7
+
8
+ = f.submit 'Save'
9
+
@@ -3,6 +3,9 @@
3
3
  = render 'admin/chats/form_chat', chat: chat
4
4
 
5
5
  - if chat.persisted?
6
+ = tab(chat.chat_messages) do
7
+ = render_inline_datatable(Admin::EffectiveChatMessagesDatatable.new(chat: chat))
8
+
6
9
  - if chat.respond_to?(:logs_datatable)
7
10
  = tab "Logs" do
8
11
  = render_inline_datatable(chat.logs_datatable)
data/config/routes.rb CHANGED
@@ -12,7 +12,7 @@ EffectiveMessaging::Engine.routes.draw do
12
12
 
13
13
  namespace :admin do
14
14
  resources :chats
15
- resources :chat_messages, only: [:index, :show, :destroy]
15
+ resources :chat_messages, except: [:new, :create]
16
16
 
17
17
  resources :notifications do
18
18
  post :enable, on: :member
@@ -1,3 +1,3 @@
1
1
  module EffectiveMessaging
2
- VERSION = '0.7.5'.freeze
2
+ VERSION = '0.8.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.8.1
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-03-20 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -229,6 +229,7 @@ files:
229
229
  - app/models/effective/notification.rb
230
230
  - app/models/effective/notification_log.rb
231
231
  - app/views/admin/chat_messages/_chat_message.html.haml
232
+ - app/views/admin/chat_messages/_form.html.haml
232
233
  - app/views/admin/chats/_chat.html.haml
233
234
  - app/views/admin/chats/_form.html.haml
234
235
  - app/views/admin/chats/_form_chat.html.haml