effective_messaging 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/app/controllers/admin/notifications_controller.rb +17 -0
- data/app/datatables/admin/effective_notifications_datatable.rb +37 -0
- data/app/jobs/effective/notification_job.rb +10 -0
- data/app/mailers/effective/messaging_mailer.rb +1 -2
- data/app/mailers/effective/notifications_mailer.rb +37 -0
- data/app/models/effective/notification.rb +173 -0
- data/app/views/admin/chats/_form.html.haml +2 -2
- data/app/views/admin/notifications/_form.html.haml +7 -0
- data/app/views/admin/notifications/_form_notification.html.haml +60 -0
- data/app/views/admin/notifications/_notification.html.haml +67 -0
- data/config/effective_messaging.rb +5 -2
- data/config/routes.rb +1 -0
- data/db/migrate/01_create_effective_messaging.rb.erb +25 -0
- data/lib/effective_messaging/version.rb +1 -1
- data/lib/effective_messaging.rb +3 -2
- data/lib/generators/effective_messaging/install_generator.rb +1 -0
- data/lib/tasks/effective_messaging_tasks.rake +21 -4
- metadata +12 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562e0f1c733ddda4bc2100b12ba84500090e89136a0318d00915d3518b775b52
|
4
|
+
data.tar.gz: 5f3d887a18529c663ff520a0b992bd96c0bbd545e47db08e6031c5fa56837c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b438f053eff518e167b3ccd39b90472a35879c07f2b650257cc3fbe21b160dd96cfba455c2bcaf80ce857da92e05e78920a159b6cc8a7f66f2b193d609f1033
|
7
|
+
data.tar.gz: a76f710b600e910220e3406d9e055e6a2f77f69478ccf58fcd8c7953eb053374d1569804995152d73b3ead14a74e254157a41039de4bb8aa12147c78e2b1efef
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Centralize all communications between one or more users.
|
4
4
|
|
5
|
+
Works with effective_reports to schedule notifications to report results containing emails.
|
6
|
+
|
5
7
|
## Getting Started
|
6
8
|
|
7
9
|
This requires Rails 6+ and Twitter Bootstrap 4 and just works with Devise.
|
@@ -69,6 +71,9 @@ Add a link to the admin menu:
|
|
69
71
|
|
70
72
|
- if can?(:admin, :effective_messaging) && can?(:index, Effective::ChatMessage)
|
71
73
|
= nav_link_to 'Chat Messages', effective_messaging.admin_chat_messages_path
|
74
|
+
|
75
|
+
- if can?(:admin, :effective_messaging) && can?(:index, Effective::Notification)
|
76
|
+
= nav_link_to 'Chat Messages', effective_messaging.admin_notifications_path
|
72
77
|
```
|
73
78
|
|
74
79
|
## Authorization
|
@@ -89,6 +94,8 @@ if user.admin?
|
|
89
94
|
can(crud, Effective::Chat)
|
90
95
|
can(crud, Effective::ChatUser)
|
91
96
|
can(crud - [:new, :create], Effective::ChatMessage)
|
97
|
+
|
98
|
+
can(crud + [:create_notification_job], Effective::Notification)
|
92
99
|
end
|
93
100
|
```
|
94
101
|
|
@@ -109,6 +116,12 @@ and you can just render it *outside of a form*:
|
|
109
116
|
= render('effective/chats/chat', chat: chat)
|
110
117
|
```
|
111
118
|
|
119
|
+
## Creating a notification
|
120
|
+
|
121
|
+
First create an effective report with an email column in the results.
|
122
|
+
|
123
|
+
Then visit /admin/notifications to schedule a notification with a From, Subject and Body
|
124
|
+
|
112
125
|
## License
|
113
126
|
|
114
127
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Admin
|
2
|
+
class NotificationsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
before_action { EffectiveResources.authorize!(self, :admin, :effective_messaging) }
|
5
|
+
|
6
|
+
include Effective::CrudController
|
7
|
+
|
8
|
+
submit :create_notification_job, 'Send Now'
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def permitted_params
|
13
|
+
params.require(:effective_notification).permit!
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Admin
|
2
|
+
class EffectiveNotificationsDatatable < Effective::Datatable
|
3
|
+
filters do
|
4
|
+
scope :all
|
5
|
+
scope :notifiable, label: 'Upcoming'
|
6
|
+
scope :completed, label: 'Past'
|
7
|
+
end
|
8
|
+
|
9
|
+
datatable do
|
10
|
+
order :updated_at
|
11
|
+
|
12
|
+
col :updated_at, visible: false
|
13
|
+
col :created_at, visible: false
|
14
|
+
col :id, visible: false
|
15
|
+
|
16
|
+
col :send_at
|
17
|
+
col :report, search: Effective::Report.emails.sorted
|
18
|
+
|
19
|
+
col :subject
|
20
|
+
col :body, visible: false
|
21
|
+
|
22
|
+
col :from, visible: false, search: Array(EffectiveMessaging.froms).presence
|
23
|
+
col :cc, visible: false
|
24
|
+
col :bcc, visible: false
|
25
|
+
|
26
|
+
col :started_at, visible: false
|
27
|
+
col :completed_at
|
28
|
+
col :notifications_sent, visible: false
|
29
|
+
|
30
|
+
actions_col
|
31
|
+
end
|
32
|
+
|
33
|
+
collection do
|
34
|
+
Effective::Notification.deep.all
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Effective
|
2
2
|
class MessagingMailer < EffectiveMessaging.parent_mailer_class
|
3
|
-
|
4
3
|
include EffectiveMailer
|
5
|
-
include EffectiveEmailTemplatesMailer
|
4
|
+
include EffectiveEmailTemplatesMailer
|
6
5
|
|
7
6
|
def chat_new_message(chat, chat_user, opts = {})
|
8
7
|
raise('expected a chat') unless chat.kind_of?(Chat)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Effective
|
2
|
+
class NotificationsMailer < EffectiveReports.parent_mailer_class
|
3
|
+
include EffectiveMailer
|
4
|
+
|
5
|
+
# Does not use effective_email_templates mailer
|
6
|
+
|
7
|
+
def notification(notification, resource, opts = {})
|
8
|
+
raise('expected an Effective::Notification') unless notification.kind_of?(Effective::Notification)
|
9
|
+
raise('expected a resource') unless resource.present?
|
10
|
+
|
11
|
+
# Returns a Hash of params to pass to mail()
|
12
|
+
# Includes a :to, :from, etc
|
13
|
+
rendered = notification.render_email(resource)
|
14
|
+
|
15
|
+
# Works with effective_logging to associate this email with the notification
|
16
|
+
headers = headers_for(notification, opts)
|
17
|
+
|
18
|
+
# Use postmark broadcast-stream
|
19
|
+
if defined?(Postmark)
|
20
|
+
headers.merge!(message_stream: 'broadcast-stream')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Calls effective_resources subject proc, so we can prepend [LETTERS]
|
24
|
+
subject = subject_for(__method__, rendered.fetch(:subject), resource, opts)
|
25
|
+
|
26
|
+
# Pass everything to mail
|
27
|
+
mail(rendered.merge(headers).merge(subject: subject))
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def mailer_settings
|
33
|
+
EffectiveMessaging
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Effective
|
4
|
+
class Notification < ActiveRecord::Base
|
5
|
+
self.table_name = EffectiveMessaging.notifications_table_name.to_s
|
6
|
+
|
7
|
+
attr_accessor :current_user
|
8
|
+
attr_accessor :current_resource
|
9
|
+
|
10
|
+
log_changes if respond_to?(:log_changes)
|
11
|
+
|
12
|
+
# Unused. If we want to use notifications in a has_many way
|
13
|
+
belongs_to :parent, polymorphic: true, optional: true
|
14
|
+
|
15
|
+
# Unused. When the notification belongs to one user
|
16
|
+
belongs_to :user, polymorphic: true, optional: true
|
17
|
+
|
18
|
+
# Effective namespace
|
19
|
+
belongs_to :report, class_name: 'Effective::Report'
|
20
|
+
|
21
|
+
CONTENT_TYPES = ['text/plain', 'text/html']
|
22
|
+
|
23
|
+
effective_resource do
|
24
|
+
send_at :datetime
|
25
|
+
|
26
|
+
subject :string
|
27
|
+
body :text
|
28
|
+
|
29
|
+
from :string
|
30
|
+
cc :string
|
31
|
+
bcc :string
|
32
|
+
|
33
|
+
# Tracking background jobs email send out
|
34
|
+
started_at :datetime
|
35
|
+
completed_at :datetime
|
36
|
+
notifications_sent :integer
|
37
|
+
|
38
|
+
timestamps
|
39
|
+
end
|
40
|
+
|
41
|
+
scope :sorted, -> { order(:id) }
|
42
|
+
scope :deep, -> { includes(report: :report_columns) }
|
43
|
+
|
44
|
+
scope :upcoming, -> { where('send_at > ?', Time.zone.now) }
|
45
|
+
scope :started, -> { where.not(started_at: nil) }
|
46
|
+
scope :completed, -> { where.not(completed_at: nil) }
|
47
|
+
|
48
|
+
# Called by the notifier rake task
|
49
|
+
scope :notifiable, -> { where(started_at: nil) }
|
50
|
+
|
51
|
+
before_validation(if: -> { send_at_changed? }) do
|
52
|
+
assign_attributes(started_at: nil, completed_at: nil, notifications_sent: nil)
|
53
|
+
end
|
54
|
+
|
55
|
+
validates :send_at, presence: true
|
56
|
+
validates :from, presence: true, email: true
|
57
|
+
validates :subject, presence: true, liquid: true
|
58
|
+
validates :body, presence: true, liquid: true
|
59
|
+
|
60
|
+
validate(if: -> { report.present? }) do
|
61
|
+
self.errors.add(:report, 'must include an email column') unless report.email_report_column.present?
|
62
|
+
end
|
63
|
+
|
64
|
+
validate(if: -> { report.present? && subject.present? }) do
|
65
|
+
if(invalid = template_variables(body: false) - report_variables).present?
|
66
|
+
self.errors.add(:subject, "Invalid variable: #{invalid.to_sentence}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
validate(if: -> { report.present? && body.present? }) do
|
71
|
+
if(invalid = template_variables(subject: false) - report_variables).present?
|
72
|
+
self.errors.add(:body, "Invalid variable: #{invalid.to_sentence}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_s
|
77
|
+
subject.presence || 'notification'
|
78
|
+
end
|
79
|
+
|
80
|
+
def template_subject
|
81
|
+
Liquid::Template.parse(subject)
|
82
|
+
end
|
83
|
+
|
84
|
+
def template_body
|
85
|
+
Liquid::Template.parse(body)
|
86
|
+
end
|
87
|
+
|
88
|
+
def report_variables
|
89
|
+
Array(report&.report_columns).map(&:name)
|
90
|
+
end
|
91
|
+
|
92
|
+
def rows_count
|
93
|
+
@rows_count ||= report.collection().count if report
|
94
|
+
end
|
95
|
+
|
96
|
+
def in_progress?
|
97
|
+
started_at.present? && completed_at.blank?
|
98
|
+
end
|
99
|
+
|
100
|
+
def notifiable?
|
101
|
+
started_at.blank? && completed_at.blank?
|
102
|
+
end
|
103
|
+
|
104
|
+
def notify_now?
|
105
|
+
notifiable? && Time.zone.now >= send_at
|
106
|
+
end
|
107
|
+
|
108
|
+
def notify!(force: false, limit: nil)
|
109
|
+
return false unless (notify_now? || force)
|
110
|
+
|
111
|
+
update!(started_at: Time.zone.now, completed_at: nil, notifications_sent: nil)
|
112
|
+
|
113
|
+
index = 0
|
114
|
+
|
115
|
+
report.collection().find_each do |resource|
|
116
|
+
print('.')
|
117
|
+
|
118
|
+
assign_attributes(current_resource: resource)
|
119
|
+
Effective::NotificationsMailer.notification(self, resource).deliver_now
|
120
|
+
|
121
|
+
index += 1
|
122
|
+
break if limit && index >= limit
|
123
|
+
|
124
|
+
GC.start if (index % 250) == 0
|
125
|
+
end
|
126
|
+
|
127
|
+
update!(current_resource: nil, completed_at: Time.zone.now, notifications_sent: index)
|
128
|
+
end
|
129
|
+
|
130
|
+
# The 'Send Now' action on admin. Enqueues a job that calls notify!(force: true)
|
131
|
+
def create_notification_job!
|
132
|
+
update!(started_at: Time.zone.now, completed_at: nil, notifications_sent: nil)
|
133
|
+
|
134
|
+
NotificationJob.perform_later(id, true) # force = true
|
135
|
+
true
|
136
|
+
end
|
137
|
+
|
138
|
+
def render_email(resource)
|
139
|
+
raise('expected a resource') unless resource.present?
|
140
|
+
|
141
|
+
assigns = assigns_for(resource)
|
142
|
+
to = assigns.fetch(report.email_report_column.name) || raise('expected an email assigns')
|
143
|
+
|
144
|
+
{
|
145
|
+
to: to,
|
146
|
+
from: from,
|
147
|
+
cc: cc.presence,
|
148
|
+
bcc: bcc.presence,
|
149
|
+
content_type: CONTENT_TYPES.first,
|
150
|
+
subject: template_subject.render(assigns),
|
151
|
+
body: template_body.render(assigns)
|
152
|
+
}.compact
|
153
|
+
end
|
154
|
+
|
155
|
+
def assigns_for(resource)
|
156
|
+
Array(report&.report_columns).inject({}) do |h, column|
|
157
|
+
value = resource.send(column.name)
|
158
|
+
h[column.name] = column.format(value); h
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def template_variables(body: true, subject: true)
|
165
|
+
[(template_body.presence if body), (template_subject.presence if subject)].compact.map do |template|
|
166
|
+
Liquid::ParseTreeVisitor.for(template.root).add_callback_for(Liquid::VariableLookup) do |node|
|
167
|
+
[node.name, *node.lookups].join('.')
|
168
|
+
end.visit
|
169
|
+
end.flatten.uniq.compact
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
@@ -3,6 +3,6 @@
|
|
3
3
|
= render 'admin/chats/form_chat', chat: chat
|
4
4
|
|
5
5
|
- if chat.persisted?
|
6
|
-
- if chat.respond_to?(:
|
6
|
+
- if chat.respond_to?(:logs_datatable)
|
7
7
|
= tab "Logs" do
|
8
|
-
= render_inline_datatable(chat.
|
8
|
+
= render_inline_datatable(chat.logs_datatable)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
= effective_form_with(model: [:admin, notification], engine: true) do |f|
|
2
|
+
%h2 Data Source
|
3
|
+
%p
|
4
|
+
Please select a
|
5
|
+
= link_to 'report', effective_reports.admin_reports_path, target: '_blank'
|
6
|
+
with an email report column to use as the data source.
|
7
|
+
|
8
|
+
%p Each result from the report will be sent a notification.
|
9
|
+
|
10
|
+
.row
|
11
|
+
.col-md-6
|
12
|
+
= f.select :report_id, Effective::Report.sorted.emails.all, label: 'Report with email column',
|
13
|
+
'data-load-ajax-url': effective_messaging.new_admin_notification_path,
|
14
|
+
'data-load-ajax-div': '#effective-messaging-ajax'
|
15
|
+
|
16
|
+
%h2 Schedule
|
17
|
+
%p Please select a date when the notifications should be sent
|
18
|
+
|
19
|
+
.row
|
20
|
+
.col-md-6
|
21
|
+
- minDate = [f.object.created_at, Time.zone.now].compact.min
|
22
|
+
|
23
|
+
= f.datetime_field :send_at, label: 'Send the notification at', input_js: { minDate: minDate.strftime('%F %H:%M:%S') },
|
24
|
+
hint: 'A future date. Changing this value will reset the started_at and completed_at dates so this notification can be sent again.'
|
25
|
+
.col-md-6
|
26
|
+
- if f.object.completed_at.present?
|
27
|
+
= f.static_field :completed_at
|
28
|
+
- elsif f.object.started_at.present?
|
29
|
+
= f.static_field :started_at
|
30
|
+
|
31
|
+
%h2 Notification
|
32
|
+
%p The following notification will be sent to each row in the data source
|
33
|
+
|
34
|
+
- froms = Array(EffectiveMessaging.froms)
|
35
|
+
|
36
|
+
- if froms.present?
|
37
|
+
- f.object.from ||= froms.first
|
38
|
+
= f.select :from, Array(froms)
|
39
|
+
- else
|
40
|
+
= f.email_field :from
|
41
|
+
|
42
|
+
= f.text_field :subject
|
43
|
+
= f.text_area :body
|
44
|
+
|
45
|
+
#effective-messaging-ajax
|
46
|
+
- if f.object.report.present?
|
47
|
+
%p You can use the following variables in the subject and body:
|
48
|
+
|
49
|
+
%ul
|
50
|
+
- f.object.report_variables.each do |name|
|
51
|
+
%li {{ #{name} }}
|
52
|
+
|
53
|
+
= f.submit do
|
54
|
+
= f.save 'Save'
|
55
|
+
|
56
|
+
- if f.object.persisted? && !f.object.in_progress?
|
57
|
+
= f.save 'Send Now', class: 'btn btn-warning', 'data-confirm': "Really send #{pluralize(notification.rows_count, 'notification')} now?"
|
58
|
+
|
59
|
+
= f.save 'Add New', class: 'btn btn-secondary'
|
60
|
+
= f.save 'Continue', class: 'btn btn-secondary'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
%p
|
2
|
+
This notification will be sent to all rows from the
|
3
|
+
= link_to(notification.report, effective_reports.admin_report_path(notification.report), target: '_blank')
|
4
|
+
report at the time of sending.
|
5
|
+
|
6
|
+
%p Currently there are #{pluralize(notification.rows_count, 'rows')} that would be notified.
|
7
|
+
|
8
|
+
= card(notification) do
|
9
|
+
%table.table
|
10
|
+
%tbody
|
11
|
+
%tr
|
12
|
+
%th Send At
|
13
|
+
%td= notification.send_at.strftime('%F %H:%M')
|
14
|
+
|
15
|
+
%tr
|
16
|
+
%th Report
|
17
|
+
%td= link_to(notification.report, effective_reports.admin_report_path(notification.report), target: '_blank')
|
18
|
+
|
19
|
+
%tr
|
20
|
+
%th Current rows count
|
21
|
+
%td= notification.rows_count
|
22
|
+
|
23
|
+
%tr
|
24
|
+
%th Started At
|
25
|
+
%td= notification.started_at&.strftime('%F %H:%M') || 'Never'
|
26
|
+
|
27
|
+
%tr
|
28
|
+
%th Completed At
|
29
|
+
%td= notification.completed_at&.strftime('%F %H:%M') || 'Never'
|
30
|
+
|
31
|
+
%tr
|
32
|
+
%th Notifications Sent
|
33
|
+
%td= notification.notifications_sent.presence || 'None'
|
34
|
+
|
35
|
+
- if notification.rows_count > 0
|
36
|
+
%p Using a random row from the data source, a preview of the notification follows:
|
37
|
+
|
38
|
+
= card('Preview of Notification') do
|
39
|
+
- resource = notification.report.collection.order('RANDOM()').first
|
40
|
+
- rendered = notification.render_email(resource)
|
41
|
+
|
42
|
+
%table.table
|
43
|
+
%tbody
|
44
|
+
%tr
|
45
|
+
%th To
|
46
|
+
%td= rendered.fetch(:to)
|
47
|
+
%tr
|
48
|
+
%th From
|
49
|
+
%td= rendered.fetch(:from)
|
50
|
+
|
51
|
+
- if (cc = rendered[:cc]).present?
|
52
|
+
%tr
|
53
|
+
%th CC
|
54
|
+
%td= cc
|
55
|
+
|
56
|
+
- if (bcc = rendered[:bcc]).present?
|
57
|
+
%tr
|
58
|
+
%th BCC
|
59
|
+
%td= bcc
|
60
|
+
|
61
|
+
%tr
|
62
|
+
%th Subject
|
63
|
+
%td= rendered.fetch(:subject)
|
64
|
+
|
65
|
+
%tr
|
66
|
+
%td{colspan: 2}
|
67
|
+
= simple_format(rendered.fetch(:body).to_s)
|
@@ -2,11 +2,16 @@ EffectiveMessaging.setup do |config|
|
|
2
2
|
config.chats_table_name = :chats
|
3
3
|
config.chat_users_table_name = :chat_users
|
4
4
|
config.chat_messages_table_name = :chat_messages
|
5
|
+
config.notifications_table_name = :notifications
|
5
6
|
|
6
7
|
# Layout Settings
|
7
8
|
# Configure the Layout per controller, or all at once
|
8
9
|
# config.layout = { application: 'application', admin: 'admin' }
|
9
10
|
|
11
|
+
# From Settings
|
12
|
+
# For the Admin new notification form. Set to an array to use a select, or nil to use a freeform text entry
|
13
|
+
config.froms = ['noreply@example.com']
|
14
|
+
|
10
15
|
# Mailer Settings
|
11
16
|
# Please see config/initializers/effective_messaging.rb for default effective_* gem mailer settings
|
12
17
|
#
|
@@ -22,6 +27,4 @@ EffectiveMessaging.setup do |config|
|
|
22
27
|
# config.mailer_admin = nil # Default To value for Admin correspondence
|
23
28
|
# config.mailer_subject = nil # Proc.new method used to customize Subject
|
24
29
|
|
25
|
-
# Will work with effective_email_templates gem
|
26
|
-
config.use_effective_email_templates = true
|
27
30
|
end
|
data/config/routes.rb
CHANGED
@@ -40,5 +40,30 @@ class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
|
|
40
40
|
t.timestamps
|
41
41
|
end
|
42
42
|
|
43
|
+
create_table <%= @notifications_table_name %> do |t|
|
44
|
+
t.integer :parent_id
|
45
|
+
t.string :parent_type
|
46
|
+
|
47
|
+
t.integer :user_id
|
48
|
+
t.string :user_type
|
49
|
+
|
50
|
+
t.integer :report_id
|
51
|
+
|
52
|
+
t.datetime :send_at
|
53
|
+
|
54
|
+
t.string :subject
|
55
|
+
t.text :body
|
56
|
+
|
57
|
+
t.string :from
|
58
|
+
t.string :cc
|
59
|
+
t.string :bcc
|
60
|
+
|
61
|
+
t.datetime :started_at
|
62
|
+
t.datetime :completed_at
|
63
|
+
t.integer :notifications_sent
|
64
|
+
|
65
|
+
t.timestamps
|
66
|
+
end
|
67
|
+
|
43
68
|
end
|
44
69
|
end
|
data/lib/effective_messaging.rb
CHANGED
@@ -7,9 +7,10 @@ module EffectiveMessaging
|
|
7
7
|
|
8
8
|
def self.config_keys
|
9
9
|
[
|
10
|
-
:chats_table_name, :chat_users_table_name, :chat_messages_table_name,
|
10
|
+
:chats_table_name, :chat_users_table_name, :chat_messages_table_name, :notifications_table_name,
|
11
11
|
:layout,
|
12
|
-
:
|
12
|
+
:froms,
|
13
|
+
:mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject
|
13
14
|
]
|
14
15
|
end
|
15
16
|
|
@@ -23,6 +23,7 @@ module EffectiveMessaging
|
|
23
23
|
@chats_table_name = ':' + EffectiveMessaging.chats_table_name.to_s
|
24
24
|
@chat_users_table_name = ':' + EffectiveMessaging.chat_users_table_name.to_s
|
25
25
|
@chat_messages_table_name = ':' + EffectiveMessaging.chat_messages_table_name.to_s
|
26
|
+
@notifications_table_name = ':' + EffectiveMessaging.notifications_table_name.to_s
|
26
27
|
|
27
28
|
migration_template ('../' * 3) + 'db/migrate/01_create_effective_messaging.rb.erb', 'db/migrate/create_effective_messaging.rb'
|
28
29
|
end
|
@@ -1,8 +1,25 @@
|
|
1
|
+
# rake effective_messaging:notify
|
1
2
|
namespace :effective_messaging do
|
3
|
+
desc 'Sends scheduled notifications for effective messaging'
|
4
|
+
task notify: :environment do
|
5
|
+
puts 'Sending notifications'
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
+
notifications = Effective::Notification.all.deep.notifiable
|
8
|
+
|
9
|
+
notifications.find_each do |notification|
|
10
|
+
begin
|
11
|
+
notified = notification.notify!
|
12
|
+
Rails.logger.info "Sent notifications for #{notification.report}" if notified
|
13
|
+
rescue => e
|
14
|
+
if defined?(ExceptionNotifier)
|
15
|
+
data = { notification_id: notification.id, report_id: notification.report_id, resource_id: notification.current_resource&.id }
|
16
|
+
ExceptionNotifier.notify_exception(e, data: data)
|
17
|
+
end
|
7
18
|
|
19
|
+
puts "Error with effective_messaging #{notification.id} resource #{notification.current_resource&.id}: #{e.errors.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
puts 'All done'
|
24
|
+
end
|
8
25
|
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.1.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 4.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: effective_email_templates
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -81,21 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: wicked
|
84
|
+
name: effective_reports
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -192,20 +178,6 @@ dependencies:
|
|
192
178
|
- - ">="
|
193
179
|
- !ruby/object:Gem::Version
|
194
180
|
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: effective_email_templates
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
181
|
description: Centralize the communication between one or more users.
|
210
182
|
email:
|
211
183
|
- info@codeandeffect.com
|
@@ -223,22 +195,30 @@ files:
|
|
223
195
|
- app/assets/stylesheets/effective_messaging/base.scss
|
224
196
|
- app/controllers/admin/chat_messages_controller.rb
|
225
197
|
- app/controllers/admin/chats_controller.rb
|
198
|
+
- app/controllers/admin/notifications_controller.rb
|
226
199
|
- app/controllers/effective/chats_controller.rb
|
227
200
|
- app/datatables/admin/effective_chat_messages_datatable.rb
|
228
201
|
- app/datatables/admin/effective_chats_datatable.rb
|
202
|
+
- app/datatables/admin/effective_notifications_datatable.rb
|
229
203
|
- app/datatables/effective_chats_datatable.rb
|
230
204
|
- app/helpers/effective_messaging_helper.rb
|
205
|
+
- app/jobs/effective/notification_job.rb
|
231
206
|
- app/mailers/effective/messaging_mailer.rb
|
207
|
+
- app/mailers/effective/notifications_mailer.rb
|
232
208
|
- app/models/concerns/effective_messaging_parent.rb
|
233
209
|
- app/models/concerns/effective_messaging_user.rb
|
234
210
|
- app/models/effective/chat.rb
|
235
211
|
- app/models/effective/chat_message.rb
|
236
212
|
- app/models/effective/chat_user.rb
|
213
|
+
- app/models/effective/notification.rb
|
237
214
|
- app/views/admin/chat_messages/_chat_message.html.haml
|
238
215
|
- app/views/admin/chats/_chat.html.haml
|
239
216
|
- app/views/admin/chats/_form.html.haml
|
240
217
|
- app/views/admin/chats/_form_chat.html.haml
|
241
218
|
- app/views/admin/chats/_layout.html.haml
|
219
|
+
- app/views/admin/notifications/_form.html.haml
|
220
|
+
- app/views/admin/notifications/_form_notification.html.haml
|
221
|
+
- app/views/admin/notifications/_notification.html.haml
|
242
222
|
- app/views/effective/chats/_chat.html.haml
|
243
223
|
- app/views/effective/chats/_chat_message.html.haml
|
244
224
|
- app/views/effective/chats/_form.html.haml
|