mail-notify 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +21 -0
- data/.github/workflows/publish.yml +1 -1
- data/.github/workflows/rails-integration-tests.yml +231 -0
- data/.gitignore +5 -1
- data/CHANGELOG.md +15 -1
- data/Dockerfile +68 -0
- data/README.md +2 -2
- data/Rakefile +1 -6
- data/{lib/mail/notify → app/views}/layouts/govuk_notify_layout.html.erb +23 -25
- data/bin/console +4 -9
- data/bin/rspec +27 -0
- data/bin/standardrb +27 -0
- data/lib/mail/notify/delivery_method.rb +16 -26
- data/lib/mail/notify/engine.rb +13 -0
- data/lib/mail/notify/mail_notify_preview_interceptor.rb +51 -0
- data/lib/mail/notify/mail_notify_previews_controller.rb +6 -0
- data/lib/mail/notify/mailer.rb +85 -7
- data/lib/mail/notify/message.rb +1 -3
- data/lib/mail/notify/version.rb +1 -1
- data/lib/mail/notify.rb +3 -3
- data/mail-notify.gemspec +14 -13
- data/renovate.json +3 -1
- metadata +64 -46
- data/.coveralls.yml +0 -0
- data/.github/workflows/build.yml +0 -27
- data/lib/mail/notify/mailers_controller.rb +0 -40
- data/lib/mail/notify/personalisation.rb +0 -30
- data/lib/mail/notify/railtie.rb +0 -19
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Notify
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
initializer "mail-notify.add_delivery_method", before: "action_mailer.set_configs" do
|
7
|
+
ActionMailer::Base.add_delivery_method(:notify, Mail::Notify::DeliveryMethod)
|
8
|
+
|
9
|
+
config.action_mailer.preview_interceptors = [:mail_notify_preview_interceptor]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# This is a ActionMailer interceptor class for previews from the Notifications API
|
5
|
+
#
|
6
|
+
# See ActionMailer::Base:
|
7
|
+
#
|
8
|
+
# https://github.com/rails/rails/blob/v5.2.8.1/actionmailer/lib/action_mailer/base.rb#L367
|
9
|
+
|
10
|
+
class MailNotifyPreviewInterceptor
|
11
|
+
##
|
12
|
+
# ActionMailer call back when a preview is being generated.
|
13
|
+
#
|
14
|
+
# Transforms the content of the passed in message.
|
15
|
+
|
16
|
+
def self.previewing_email(message)
|
17
|
+
new(message).transform!
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Creates a new MailNotifyPreviewInterceptor ready for use.
|
22
|
+
|
23
|
+
def initialize(message)
|
24
|
+
@message = message
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Transforms the content of the message to that from the Notifications API preview.
|
29
|
+
#
|
30
|
+
# The html is wrapped in a layout and rendered by the MailNotifyPreviewsControllers renderer.
|
31
|
+
|
32
|
+
def transform!
|
33
|
+
# the messages delivery method will be our Mail::Notify::DeliveryMethod and have the `preview` method.
|
34
|
+
preview = @message.delivery_method.preview(@message)
|
35
|
+
|
36
|
+
@message.subject = preview.subject
|
37
|
+
@message.html_part.body = renderer.render html: preview.html.html_safe, layout: "govuk_notify_layout"
|
38
|
+
@message.text_part.body = preview.body
|
39
|
+
|
40
|
+
@message
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def renderer
|
46
|
+
# rendering in Rails without a controller gets far too complicated, instead
|
47
|
+
# we rely on this empty controller to do it for us.
|
48
|
+
|
49
|
+
MailNotifyPreviewsController.renderer
|
50
|
+
end
|
51
|
+
end
|
data/lib/mail/notify/mailer.rb
CHANGED
@@ -2,21 +2,99 @@
|
|
2
2
|
|
3
3
|
module Mail
|
4
4
|
module Notify
|
5
|
+
##
|
6
|
+
# The Mail Notify base Mailer class, overridden in Rails applications to provide the additional
|
7
|
+
# Notify behaviour along with the application behaviour.
|
8
|
+
|
5
9
|
class Mailer < ActionMailer::Base
|
6
|
-
|
7
|
-
|
10
|
+
##
|
11
|
+
# Set a default from address, will only be used in previews if a from address is not supplied
|
12
|
+
# by subclasses
|
13
|
+
|
14
|
+
default from: "preview@notifications.service.gov.uk"
|
15
|
+
|
16
|
+
##
|
17
|
+
# Send an email where the content is managed in the Notify template.
|
18
|
+
#
|
19
|
+
# The required arguments are:
|
20
|
+
#
|
21
|
+
# - template_id
|
22
|
+
# - to address
|
23
|
+
#
|
24
|
+
# Can include personalisation.
|
25
|
+
#
|
26
|
+
# Add any additional headers in the options hash.
|
27
|
+
#
|
28
|
+
# A default subject is supplied as ActionMailer requires one, however it will never be used as
|
29
|
+
# the subject is assumed to be managed in the Notify template.
|
30
|
+
|
31
|
+
def template_mail(template_id, options)
|
32
|
+
raise ArgumentError, "You must specify a Notify template ID" if template_id.blank?
|
33
|
+
raise ArgumentError, "You must specify a to address" if options[:to].nil? || options[:to].blank?
|
34
|
+
|
35
|
+
message.template_id = template_id
|
36
|
+
message.reply_to_id = options[:reply_to_id]
|
37
|
+
message.reference = options[:reference]
|
38
|
+
|
39
|
+
message.personalisation = options[:personalisation] || {}
|
40
|
+
|
41
|
+
headers = options.except([:personalisation, :reply_to_id, :reference])
|
8
42
|
|
9
|
-
|
43
|
+
headers[:subject] = "Subject managed in Notify" unless options[:subject]
|
44
|
+
|
45
|
+
# We have to set the html and the plain text content to nil to prevent Rails from looking
|
46
|
+
# for the content in the views. We replace nil with the content returned from Notify before
|
47
|
+
# sending or previewing
|
48
|
+
mail(headers) do |format|
|
49
|
+
format.text { nil }
|
50
|
+
format.html { nil }
|
51
|
+
end
|
10
52
|
end
|
11
53
|
|
12
|
-
|
13
|
-
|
54
|
+
##
|
55
|
+
# Send an email where the content is managed in the Rails application.
|
56
|
+
#
|
57
|
+
# The required arguments are:
|
58
|
+
#
|
59
|
+
# - template_id
|
60
|
+
# - to address
|
61
|
+
# - subject
|
62
|
+
#
|
63
|
+
# Personalisation will dropped as all content comes from the view provided by Rails.
|
64
|
+
#
|
65
|
+
# Add any additional headers in the options hash.
|
66
|
+
|
67
|
+
def view_mail(template_id, options)
|
68
|
+
raise ArgumentError, "You must specify a Notify template ID" if template_id.blank?
|
69
|
+
raise ArgumentError, "You must supply a to address" if options[:to].blank?
|
70
|
+
raise ArgumentError, "You must specify a subject" if options[:subject].blank?
|
71
|
+
|
72
|
+
message.template_id = template_id
|
73
|
+
message.reply_to_id = options[:reply_to_id]
|
74
|
+
message.reference = options[:reference]
|
75
|
+
|
76
|
+
subject = options[:subject]
|
77
|
+
headers = options.except([:personalisation, :reply_to_id, :reference])
|
14
78
|
|
15
|
-
|
79
|
+
# we have to render the view for the message and grab the raw source, then we set that as the
|
80
|
+
# body in the personalisation for sending to the Notify API.
|
81
|
+
body = mail(headers).body.raw_source
|
82
|
+
|
83
|
+
# The 'view mail' works by sending a subject and body as personalisation options, these are
|
84
|
+
# then used in the Notify template to provide content.
|
85
|
+
message.personalisation = {subject: subject, body: body}
|
86
|
+
|
87
|
+
mail(headers) do |format|
|
88
|
+
format.text { nil }
|
89
|
+
format.html { nil }
|
90
|
+
end
|
16
91
|
end
|
17
92
|
|
93
|
+
##
|
94
|
+
# allows blank personalisation options
|
95
|
+
|
18
96
|
def blank_allowed(value)
|
19
|
-
value.
|
97
|
+
value.to_s
|
20
98
|
end
|
21
99
|
end
|
22
100
|
end
|
data/lib/mail/notify/message.rb
CHANGED
data/lib/mail/notify/version.rb
CHANGED
data/lib/mail/notify.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
require "notifications/client"
|
4
4
|
|
5
5
|
require "mail/notify/version"
|
6
|
-
require "mail/notify/
|
6
|
+
require "mail/notify/engine" if defined? Rails
|
7
7
|
require "mail/notify/delivery_method"
|
8
|
-
require "mail/notify/personalisation"
|
9
8
|
require "mail/notify/mailer"
|
10
9
|
require "mail/notify/message"
|
11
|
-
require "mail/notify/
|
10
|
+
require "mail/notify/mail_notify_previews_controller"
|
11
|
+
require "mail/notify/mail_notify_preview_interceptor"
|
12
12
|
|
13
13
|
Mail::Message.include Mail::Notify::Message
|
14
14
|
|
data/mail-notify.gemspec
CHANGED
@@ -7,10 +7,10 @@ require "mail/notify/version"
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "mail-notify"
|
9
9
|
spec.version = Mail::Notify::VERSION
|
10
|
-
spec.authors = ["Stuart Harrison"]
|
10
|
+
spec.authors = ["Stuart Harrison", "Meyric Rawlings"]
|
11
11
|
spec.email = ["pezholio@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary = "
|
13
|
+
spec.summary = "Rails plugin, send and preview email with GOV.UK Notify"
|
14
14
|
spec.homepage = "https://github.com/dxw/mail-notify"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -26,20 +26,21 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
29
|
-
spec.add_development_dependency "
|
29
|
+
spec.add_development_dependency "simplecov", "~> 0.21"
|
30
|
+
spec.add_development_dependency "simplecov-lcov"
|
30
31
|
spec.add_development_dependency "pry", "~> 0.14.1"
|
31
|
-
spec.add_development_dependency "rails", "
|
32
|
-
spec.add_development_dependency "rake", "~> 13.
|
32
|
+
spec.add_development_dependency "rails", "7.0.8"
|
33
|
+
spec.add_development_dependency "rake", "~> 13.2.1"
|
33
34
|
spec.add_development_dependency "rspec-rails", "~> 5.1"
|
34
35
|
spec.add_development_dependency "standard", "~> 1"
|
35
|
-
spec.add_development_dependency "sqlite3", "~> 1.
|
36
|
-
spec.add_development_dependency "webmock", "~> 3.
|
37
|
-
spec.add_development_dependency "rspec-mocks", "~> 3.
|
36
|
+
spec.add_development_dependency "sqlite3", "~> 1.7.2"
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.23.0"
|
38
|
+
spec.add_development_dependency "rspec-mocks", "~> 3.13.0"
|
38
39
|
|
39
|
-
spec.add_dependency "actionmailer", ">= 5.2.4.6"
|
40
|
-
spec.add_dependency "activesupport", ">= 5.2.4.6"
|
41
|
-
spec.add_dependency "actionpack", ">= 5.2.7.1"
|
42
|
-
spec.add_dependency "actionview", ">= 5.2.7.1"
|
43
|
-
spec.add_dependency "notifications-ruby-client", "~> 5.1"
|
44
40
|
spec.add_dependency "rack", ">= 2.1.4.1"
|
41
|
+
spec.add_dependency "actionmailer", ">= 5.2.8.1"
|
42
|
+
spec.add_dependency "activesupport", ">= 5.2.8.1"
|
43
|
+
spec.add_dependency "actionpack", ">= 5.2.8.1"
|
44
|
+
spec.add_dependency "actionview", ">= 5.2.8.1"
|
45
|
+
spec.add_dependency "notifications-ruby-client", "~> 6.0"
|
45
46
|
end
|
data/renovate.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Harrison
|
8
|
+
- Meyric Rawlings
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2024-04-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -25,19 +26,33 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '2.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: simplecov
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
34
|
+
version: '0.21'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
41
|
+
version: '0.21'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: simplecov-lcov
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: pry
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,30 +71,30 @@ dependencies:
|
|
56
71
|
name: rails
|
57
72
|
requirement: !ruby/object:Gem::Requirement
|
58
73
|
requirements:
|
59
|
-
- -
|
74
|
+
- - '='
|
60
75
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
76
|
+
version: 7.0.8
|
62
77
|
type: :development
|
63
78
|
prerelease: false
|
64
79
|
version_requirements: !ruby/object:Gem::Requirement
|
65
80
|
requirements:
|
66
|
-
- -
|
81
|
+
- - '='
|
67
82
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
83
|
+
version: 7.0.8
|
69
84
|
- !ruby/object:Gem::Dependency
|
70
85
|
name: rake
|
71
86
|
requirement: !ruby/object:Gem::Requirement
|
72
87
|
requirements:
|
73
88
|
- - "~>"
|
74
89
|
- !ruby/object:Gem::Version
|
75
|
-
version: 13.
|
90
|
+
version: 13.2.1
|
76
91
|
type: :development
|
77
92
|
prerelease: false
|
78
93
|
version_requirements: !ruby/object:Gem::Requirement
|
79
94
|
requirements:
|
80
95
|
- - "~>"
|
81
96
|
- !ruby/object:Gem::Version
|
82
|
-
version: 13.
|
97
|
+
version: 13.2.1
|
83
98
|
- !ruby/object:Gem::Dependency
|
84
99
|
name: rspec-rails
|
85
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,126 +129,126 @@ dependencies:
|
|
114
129
|
requirements:
|
115
130
|
- - "~>"
|
116
131
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
132
|
+
version: 1.7.2
|
118
133
|
type: :development
|
119
134
|
prerelease: false
|
120
135
|
version_requirements: !ruby/object:Gem::Requirement
|
121
136
|
requirements:
|
122
137
|
- - "~>"
|
123
138
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
139
|
+
version: 1.7.2
|
125
140
|
- !ruby/object:Gem::Dependency
|
126
141
|
name: webmock
|
127
142
|
requirement: !ruby/object:Gem::Requirement
|
128
143
|
requirements:
|
129
144
|
- - "~>"
|
130
145
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.
|
146
|
+
version: 3.23.0
|
132
147
|
type: :development
|
133
148
|
prerelease: false
|
134
149
|
version_requirements: !ruby/object:Gem::Requirement
|
135
150
|
requirements:
|
136
151
|
- - "~>"
|
137
152
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.
|
153
|
+
version: 3.23.0
|
139
154
|
- !ruby/object:Gem::Dependency
|
140
155
|
name: rspec-mocks
|
141
156
|
requirement: !ruby/object:Gem::Requirement
|
142
157
|
requirements:
|
143
158
|
- - "~>"
|
144
159
|
- !ruby/object:Gem::Version
|
145
|
-
version: 3.
|
160
|
+
version: 3.13.0
|
146
161
|
type: :development
|
147
162
|
prerelease: false
|
148
163
|
version_requirements: !ruby/object:Gem::Requirement
|
149
164
|
requirements:
|
150
165
|
- - "~>"
|
151
166
|
- !ruby/object:Gem::Version
|
152
|
-
version: 3.
|
167
|
+
version: 3.13.0
|
153
168
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
169
|
+
name: rack
|
155
170
|
requirement: !ruby/object:Gem::Requirement
|
156
171
|
requirements:
|
157
172
|
- - ">="
|
158
173
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
174
|
+
version: 2.1.4.1
|
160
175
|
type: :runtime
|
161
176
|
prerelease: false
|
162
177
|
version_requirements: !ruby/object:Gem::Requirement
|
163
178
|
requirements:
|
164
179
|
- - ">="
|
165
180
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
181
|
+
version: 2.1.4.1
|
167
182
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
183
|
+
name: actionmailer
|
169
184
|
requirement: !ruby/object:Gem::Requirement
|
170
185
|
requirements:
|
171
186
|
- - ">="
|
172
187
|
- !ruby/object:Gem::Version
|
173
|
-
version: 5.2.
|
188
|
+
version: 5.2.8.1
|
174
189
|
type: :runtime
|
175
190
|
prerelease: false
|
176
191
|
version_requirements: !ruby/object:Gem::Requirement
|
177
192
|
requirements:
|
178
193
|
- - ">="
|
179
194
|
- !ruby/object:Gem::Version
|
180
|
-
version: 5.2.
|
195
|
+
version: 5.2.8.1
|
181
196
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
197
|
+
name: activesupport
|
183
198
|
requirement: !ruby/object:Gem::Requirement
|
184
199
|
requirements:
|
185
200
|
- - ">="
|
186
201
|
- !ruby/object:Gem::Version
|
187
|
-
version: 5.2.
|
202
|
+
version: 5.2.8.1
|
188
203
|
type: :runtime
|
189
204
|
prerelease: false
|
190
205
|
version_requirements: !ruby/object:Gem::Requirement
|
191
206
|
requirements:
|
192
207
|
- - ">="
|
193
208
|
- !ruby/object:Gem::Version
|
194
|
-
version: 5.2.
|
209
|
+
version: 5.2.8.1
|
195
210
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
211
|
+
name: actionpack
|
197
212
|
requirement: !ruby/object:Gem::Requirement
|
198
213
|
requirements:
|
199
214
|
- - ">="
|
200
215
|
- !ruby/object:Gem::Version
|
201
|
-
version: 5.2.
|
216
|
+
version: 5.2.8.1
|
202
217
|
type: :runtime
|
203
218
|
prerelease: false
|
204
219
|
version_requirements: !ruby/object:Gem::Requirement
|
205
220
|
requirements:
|
206
221
|
- - ">="
|
207
222
|
- !ruby/object:Gem::Version
|
208
|
-
version: 5.2.
|
223
|
+
version: 5.2.8.1
|
209
224
|
- !ruby/object:Gem::Dependency
|
210
|
-
name:
|
225
|
+
name: actionview
|
211
226
|
requirement: !ruby/object:Gem::Requirement
|
212
227
|
requirements:
|
213
|
-
- - "
|
228
|
+
- - ">="
|
214
229
|
- !ruby/object:Gem::Version
|
215
|
-
version:
|
230
|
+
version: 5.2.8.1
|
216
231
|
type: :runtime
|
217
232
|
prerelease: false
|
218
233
|
version_requirements: !ruby/object:Gem::Requirement
|
219
234
|
requirements:
|
220
|
-
- - "
|
235
|
+
- - ">="
|
221
236
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
237
|
+
version: 5.2.8.1
|
223
238
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
239
|
+
name: notifications-ruby-client
|
225
240
|
requirement: !ruby/object:Gem::Requirement
|
226
241
|
requirements:
|
227
|
-
- - "
|
242
|
+
- - "~>"
|
228
243
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
244
|
+
version: '6.0'
|
230
245
|
type: :runtime
|
231
246
|
prerelease: false
|
232
247
|
version_requirements: !ruby/object:Gem::Requirement
|
233
248
|
requirements:
|
234
|
-
- - "
|
249
|
+
- - "~>"
|
235
250
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
251
|
+
version: '6.0'
|
237
252
|
description:
|
238
253
|
email:
|
239
254
|
- pezholio@gmail.com
|
@@ -241,11 +256,11 @@ executables: []
|
|
241
256
|
extensions: []
|
242
257
|
extra_rdoc_files: []
|
243
258
|
files:
|
244
|
-
- ".coveralls.yml"
|
245
259
|
- ".github/dependabot.yml"
|
246
260
|
- ".github/setup-rubygems.sh"
|
247
|
-
- ".github/workflows/
|
261
|
+
- ".github/workflows/ci.yml"
|
248
262
|
- ".github/workflows/publish.yml"
|
263
|
+
- ".github/workflows/rails-integration-tests.yml"
|
249
264
|
- ".gitignore"
|
250
265
|
- ".rspec"
|
251
266
|
- ".rubocop.yml"
|
@@ -253,21 +268,24 @@ files:
|
|
253
268
|
- CHANGELOG.md
|
254
269
|
- CODE_OF_CONDUCT.md
|
255
270
|
- CONTRIBUTING.md
|
271
|
+
- Dockerfile
|
256
272
|
- Gemfile
|
257
273
|
- LICENSE.txt
|
258
274
|
- README.md
|
259
275
|
- Rakefile
|
276
|
+
- app/views/layouts/govuk_notify_layout.html.erb
|
260
277
|
- bin/console
|
278
|
+
- bin/rspec
|
261
279
|
- bin/setup
|
280
|
+
- bin/standardrb
|
262
281
|
- docs/screenshot.png
|
263
282
|
- lib/mail/notify.rb
|
264
283
|
- lib/mail/notify/delivery_method.rb
|
265
|
-
- lib/mail/notify/
|
284
|
+
- lib/mail/notify/engine.rb
|
285
|
+
- lib/mail/notify/mail_notify_preview_interceptor.rb
|
286
|
+
- lib/mail/notify/mail_notify_previews_controller.rb
|
266
287
|
- lib/mail/notify/mailer.rb
|
267
|
-
- lib/mail/notify/mailers_controller.rb
|
268
288
|
- lib/mail/notify/message.rb
|
269
|
-
- lib/mail/notify/personalisation.rb
|
270
|
-
- lib/mail/notify/railtie.rb
|
271
289
|
- lib/mail/notify/version.rb
|
272
290
|
- mail-notify.gemspec
|
273
291
|
- renovate.json
|
@@ -293,5 +311,5 @@ requirements: []
|
|
293
311
|
rubygems_version: 3.1.6
|
294
312
|
signing_key:
|
295
313
|
specification_version: 4
|
296
|
-
summary:
|
314
|
+
summary: Rails plugin, send and preview email with GOV.UK Notify
|
297
315
|
test_files: []
|
data/.coveralls.yml
DELETED
File without changes
|
data/.github/workflows/build.yml
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
name: Build
|
2
|
-
|
3
|
-
on: [push, pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
|
8
|
-
runs-on: ubuntu-latest
|
9
|
-
|
10
|
-
steps:
|
11
|
-
- uses: actions/checkout@v3
|
12
|
-
- name: Set up Ruby
|
13
|
-
uses: ruby/setup-ruby@v1
|
14
|
-
- name: Set up cache
|
15
|
-
uses: actions/cache@preview
|
16
|
-
with:
|
17
|
-
path: vendor/bundle
|
18
|
-
key: ${{ runner.os }}-gem-${{ hashFiles('**/mail-notify.gemspec') }}
|
19
|
-
restore-keys: |
|
20
|
-
${{ runner.os }}-gem-
|
21
|
-
- name: Build and test with Rake
|
22
|
-
run: |
|
23
|
-
sudo apt-get update
|
24
|
-
sudo apt-get install sqlite3 libsqlite3-dev
|
25
|
-
gem install bundler
|
26
|
-
bundle install --jobs 4 --retry 3 --path ./vendor/bundle
|
27
|
-
bundle exec rake
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mail
|
4
|
-
module Notify
|
5
|
-
module MailersController
|
6
|
-
def preview
|
7
|
-
@email_action = File.basename(params[:path])
|
8
|
-
return super unless @preview.email_exists?(@email_action)
|
9
|
-
|
10
|
-
@email = @preview.call(@email_action, params)
|
11
|
-
|
12
|
-
return super unless notify?
|
13
|
-
|
14
|
-
return render_part if params[:part]
|
15
|
-
|
16
|
-
render_preview_wrapper
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def render_part
|
22
|
-
# Add the current directory to the view path so that Rails can find
|
23
|
-
# the `govuk_notify_layout` layout
|
24
|
-
append_view_path(__dir__)
|
25
|
-
|
26
|
-
response.content_type = "text/html"
|
27
|
-
render html: @email.preview.html.html_safe, layout: "govuk_notify_layout"
|
28
|
-
end
|
29
|
-
|
30
|
-
def render_preview_wrapper
|
31
|
-
@part = @email
|
32
|
-
render action: "email", layout: false, formats: %i[html]
|
33
|
-
end
|
34
|
-
|
35
|
-
def notify?
|
36
|
-
@email.delivery_method.instance_of?(Mail::Notify::DeliveryMethod)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mail
|
4
|
-
module Notify
|
5
|
-
class Personalisation
|
6
|
-
BLANK = Object.new
|
7
|
-
|
8
|
-
def initialize(mail)
|
9
|
-
@body = mail.body.raw_source
|
10
|
-
@subject = mail.subject
|
11
|
-
@personalisation = mail[:personalisation]&.unparsed_value || {}
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_h
|
15
|
-
merged_options
|
16
|
-
.reject { |_k, v| v.blank? }
|
17
|
-
.transform_values { |value| (value == BLANK) ? "" : value }
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def merged_options
|
23
|
-
{
|
24
|
-
body: @body,
|
25
|
-
subject: @subject
|
26
|
-
}.merge(@personalisation)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|