talktome 1.3.2 → 1.3.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 +4 -4
- data/lib/talktome/app.rb +11 -1
- data/lib/talktome/strategy/email.rb +1 -0
- data/lib/talktome/version.rb +1 -1
- data/spec/app/test_app.rb +59 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b3186927b959dff89432173c8144e50805115dfb2ce270cb82c6612797fd21
|
4
|
+
data.tar.gz: 0e2f96a0d4fcbd97e958281d0ee474afdf0dc57483181bc5427eb794c21f47e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 223de995f0f58b54c09039c63228c1a4ffa581b7dbe82cf3dc2b410b03a599c06c3e88bed88ce6e89a5fbf2e78882eb40a8b55e85a88312639c5279d43a4da04
|
7
|
+
data.tar.gz: 83e62ce22e6714376bcef8adaf027ce34e2f490aa88aa80d94e19fe3cd97c47a319ca558679ffc53bf0694825103d84d7a96dc85ec8be4bb3ebeb9451632d49c
|
data/lib/talktome/app.rb
CHANGED
@@ -17,11 +17,18 @@ module Talktome
|
|
17
17
|
|
18
18
|
VALIDATION_SCHEMA = ::Finitio.system(<<~FIO)
|
19
19
|
@import finitio/data
|
20
|
+
Attachment = {
|
21
|
+
mime_type : String
|
22
|
+
content : .Object
|
23
|
+
}
|
20
24
|
Email = String(s | s =~ /^[^@]+@[^@]+$/ )
|
21
25
|
{
|
22
26
|
to :? Email
|
23
27
|
reply_to :? Email
|
24
28
|
in_reply_to :? String
|
29
|
+
attachments :? {
|
30
|
+
... : Attachment
|
31
|
+
}
|
25
32
|
... : .Object
|
26
33
|
}
|
27
34
|
FIO
|
@@ -36,6 +43,9 @@ module Talktome
|
|
36
43
|
settings.talktome.talktome(action, user, info.merge(allvars: as_array, subject: subject, footer: footer), [:email]){|email|
|
37
44
|
email.reply_to = info[:reply_to] if info.has_key?(:reply_to)
|
38
45
|
email.in_reply_to = info[:in_reply_to] if info.has_key?(:in_reply_to)
|
46
|
+
(info[:attachments] || {}).each do |name, att|
|
47
|
+
email.attachments[name.to_s] = att
|
48
|
+
end
|
39
49
|
}
|
40
50
|
[ 200, { "Content-Type" => "text/plain"}, ["Ok"] ]
|
41
51
|
rescue JSON::ParserError
|
@@ -58,7 +68,7 @@ module Talktome
|
|
58
68
|
end
|
59
69
|
|
60
70
|
def load_user_from_info!
|
61
|
-
protected_fields = [:to, :in_reply_to]
|
71
|
+
protected_fields = [:to, :in_reply_to, :attachments]
|
62
72
|
if (info.keys & protected_fields).any?
|
63
73
|
secret = Talktome.env('TALKTOME_BEARER_SECRET')
|
64
74
|
fail!("Missing secret", 400) unless secret
|
data/lib/talktome/version.rb
CHANGED
data/spec/app/test_app.rb
CHANGED
@@ -202,6 +202,65 @@ module Talktome
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
+
context 'POST /support/, regarding the attachments' do
|
206
|
+
class ::Talktome::Message::Template
|
207
|
+
def raise_on_context_miss?
|
208
|
+
false
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'forbids the usage of :attachments unless a secret is provided' do
|
213
|
+
post "/support/", {
|
214
|
+
:to => 'client@company.com',
|
215
|
+
:attachments => {
|
216
|
+
"plain.txt" => {
|
217
|
+
"mime_type" => "plain/text",
|
218
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
222
|
+
expect(last_response.status).to eql(400)
|
223
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'does not allow setting the :attachments without a valid AUTH token' do
|
227
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Invalid secret") do
|
228
|
+
post "/support/", {
|
229
|
+
:to => 'client@company.com',
|
230
|
+
:attachments => {
|
231
|
+
"plain.txt" => {
|
232
|
+
"mime_type" => "plain/text",
|
233
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
237
|
+
expect(last_response.status).to eql(401)
|
238
|
+
expect(Mail::TestMailer.deliveries.length).to eql(0)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "lets customize attachments by passing an array" do
|
243
|
+
Talktome.set_env('TALKTOME_BEARER_SECRET', "Some secret") do
|
244
|
+
header 'Authorization', 'Bearer Some secret'
|
245
|
+
post "/support/", {
|
246
|
+
:to => 'client@company.com',
|
247
|
+
:attachments => {
|
248
|
+
"plain.txt" => {
|
249
|
+
"mime_type" => "plain/text",
|
250
|
+
"content" => Base64.encode64('Some plain/text attachment')
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}.to_json, { "CONTENT_TYPE" => "application/json" }
|
254
|
+
expect(last_response).to be_ok
|
255
|
+
expect(Mail::TestMailer.deliveries.length).to eql(1)
|
256
|
+
mail = Mail::TestMailer.deliveries.first
|
257
|
+
expect(mail.attachments['plain.txt']).to be_a_kind_of(Mail::Part)
|
258
|
+
file = mail.attachments['plain.txt']
|
259
|
+
expect(file).to be_a_kind_of(Mail::Part)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
205
264
|
context 'POST /multi-lingual/en/' do
|
206
265
|
|
207
266
|
it 'works' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talktome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|