pg_rails 7.0.8.pre.alpha.57 → 7.0.8.pre.alpha.58
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/pg_engine/app/controllers/admin/emails_controller.rb +3 -7
- data/pg_engine/app/decorators/email_decorator.rb +4 -2
- data/pg_engine/app/mailers/pg_engine/base_mailer.rb +8 -2
- data/pg_engine/app/models/email.rb +4 -14
- data/pg_engine/app/policies/email_policy.rb +0 -4
- data/pg_engine/config/routes.rb +1 -6
- data/pg_engine/db/migrate/20240506194106_create_emails.rb +0 -1
- data/pg_engine/lib/pg_engine/email_observer.rb +3 -2
- data/pg_engine/spec/controllers/admin/emails_controller_spec.rb +1 -13
- data/pg_engine/spec/factories/emails.rb +0 -1
- data/pg_rails/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418b790d06e3fdd8000b1722d68c479728e29eca73c1181544cf9241aed5745a
|
4
|
+
data.tar.gz: ec5ae58ada69aacb782c37374051022747b41049bd8cdd4824dac3f278a92325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2b01bcb36204063d7374404571501f387adeec187364b16b014e9d81f20ed892ffc576af1cb69e967bef31008a90f197e412e6760ce02f493610b0ae8fe5eac
|
7
|
+
data.tar.gz: edfa1fbf40e2846af7c980f1bcbac849af13fe22ba5e4632ae7473795527a3da4b606f7e722d0dfc921017b71409f22010a79612bbcc34b7c137aa0815e51176
|
@@ -10,14 +10,10 @@ module Admin
|
|
10
10
|
|
11
11
|
before_action(only: :index) { authorize Email }
|
12
12
|
|
13
|
-
before_action :set_instancia_modelo, only: %i[new create show edit update destroy
|
13
|
+
before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
|
14
14
|
|
15
15
|
add_breadcrumb Email.nombre_plural, :admin_emails_path
|
16
16
|
|
17
|
-
def content_eml
|
18
|
-
send_data @email.content_eml, filename: "email_#{@email.id}.txt", disposition: :inline
|
19
|
-
end
|
20
|
-
|
21
17
|
private
|
22
18
|
|
23
19
|
def atributos_permitidos
|
@@ -25,7 +21,7 @@ module Admin
|
|
25
21
|
end
|
26
22
|
|
27
23
|
def atributos_para_buscar
|
28
|
-
%i[accepted_at delivered_at opened_at from_address from_name reply_to to subject body_input tags
|
24
|
+
%i[accepted_at delivered_at opened_at from_address from_name reply_to to subject body_input tags
|
29
25
|
message_id mailer status_detail status]
|
30
26
|
end
|
31
27
|
|
@@ -35,7 +31,7 @@ module Admin
|
|
35
31
|
|
36
32
|
def atributos_para_mostrar
|
37
33
|
%i[message_id status status_detail accepted_at delivered_at opened_at from_address
|
38
|
-
from_name reply_to to subject body_input tags associated mailer
|
34
|
+
from_name reply_to to subject body_input tags associated mailer encoded_eml_link]
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
@@ -14,7 +14,9 @@ class EmailDecorator < PgEngine::BaseDecorator
|
|
14
14
|
# end
|
15
15
|
# end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def encoded_eml_link
|
18
|
+
return if object.encoded_eml.blank?
|
19
|
+
|
20
|
+
link_to 'Download', helpers.rails_blob_path(object.encoded_eml), target: :_blank, rel: :noopener
|
19
21
|
end
|
20
22
|
end
|
@@ -11,13 +11,19 @@ module PgEngine
|
|
11
11
|
|
12
12
|
layout 'pg_layout/mailer'
|
13
13
|
|
14
|
+
# default delivery_method: :smtp
|
15
|
+
|
16
|
+
# TODO: rescue from StandardError? from PgEngine::Error?
|
17
|
+
|
14
18
|
rescue_from MailNotDelivered do |err|
|
15
19
|
# FIXME: marcar el Email en la DB como fallido
|
16
20
|
pg_err err
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
protected
|
24
|
+
|
25
|
+
def mail(*args)
|
26
|
+
super(*args).tap do |message|
|
21
27
|
# message.mailgun_options = {
|
22
28
|
# 'tag' => email.tags,
|
23
29
|
# 'tracking-opens' => true
|
@@ -8,14 +8,13 @@
|
|
8
8
|
# accepted_at :datetime
|
9
9
|
# associated_type :string indexed => [associated_id]
|
10
10
|
# body_input :string
|
11
|
-
# content_eml :string
|
12
11
|
# delivered_at :datetime
|
13
12
|
# from_address :string not null
|
14
13
|
# from_name :string
|
15
14
|
# mailer :string
|
16
15
|
# opened_at :datetime
|
17
16
|
# reply_to :string
|
18
|
-
# status :integer default(
|
17
|
+
# status :integer default("pending"), not null
|
19
18
|
# status_detail :string
|
20
19
|
# subject :string
|
21
20
|
# tags :string is an Array
|
@@ -32,11 +31,12 @@
|
|
32
31
|
# fk_rails_... (actualizado_por_id => users.id)
|
33
32
|
# fk_rails_... (creado_por_id => users.id)
|
34
33
|
#
|
35
|
-
# generado con pg_rails
|
36
34
|
|
37
35
|
class Email < ApplicationRecord
|
38
36
|
audited
|
39
37
|
|
38
|
+
has_one_attached :encoded_eml
|
39
|
+
|
40
40
|
belongs_to :associated, polymorphic: true, optional: true
|
41
41
|
|
42
42
|
belongs_to :creado_por, optional: true, class_name: 'User'
|
@@ -66,16 +66,6 @@ class Email < ApplicationRecord
|
|
66
66
|
after_initialize do
|
67
67
|
self.from_address = ENV.fetch('DEFAULT_MAIL_FROM') if from_address.blank?
|
68
68
|
end
|
69
|
-
# validates_format_of :subject, with: /\A[[[:alpha:]]\(\)\w\s.,;!¡?¿-]+\z/
|
70
|
-
# def strip_all(input)
|
71
|
-
# return if input.blank?
|
72
|
-
|
73
|
-
# strip_tags(input.strip)
|
74
|
-
# end
|
75
69
|
|
76
|
-
#
|
77
|
-
# return if input.blank?
|
78
|
-
|
79
|
-
# input.gsub("\n", '<br>').html_safe
|
80
|
-
# end
|
70
|
+
# validates_format_of :subject, with: /\A[[[:alpha:]]\(\)\w\s.,;!¡?¿-]+\z/
|
81
71
|
end
|
data/pg_engine/config/routes.rb
CHANGED
@@ -9,11 +9,7 @@ Rails.application.routes.draw do
|
|
9
9
|
registrations: 'users/registrations'
|
10
10
|
}
|
11
11
|
namespace :admin, path: 'a' do
|
12
|
-
pg_resource(:emails)
|
13
|
-
member do
|
14
|
-
get :content_eml
|
15
|
-
end
|
16
|
-
end
|
12
|
+
pg_resource(:emails)
|
17
13
|
pg_resource(:users)
|
18
14
|
pg_resource(:accounts)
|
19
15
|
pg_resource(:user_accounts)
|
@@ -98,7 +94,6 @@ end
|
|
98
94
|
# POST /users/unlock(.:format) devise/unlocks#create
|
99
95
|
# abrir_modal_admin_emails GET /a/emails/abrir_modal(.:format) admin/emails#abrir_modal
|
100
96
|
# buscar_admin_emails POST /a/emails/buscar(.:format) admin/emails#buscar
|
101
|
-
# content_eml_admin_email GET /a/emails/:id/content_eml(.:format) admin/emails#content_eml
|
102
97
|
# admin_emails GET /a/emails(.:format) admin/emails#index
|
103
98
|
# POST /a/emails(.:format) admin/emails#create
|
104
99
|
# new_admin_email GET /a/emails/new(.:format) admin/emails#new
|
@@ -12,13 +12,14 @@ module PgEngine
|
|
12
12
|
message_id = message.message_id
|
13
13
|
mailer = message.delivery_handler.to_s
|
14
14
|
status = get_status(message)
|
15
|
-
content_eml = message.encoded
|
16
15
|
return if message['email'].blank?
|
17
16
|
|
18
17
|
# El objeto Email ya estaba creado. Agarro ese objeto y le actualizo las cosas
|
19
18
|
email = message['email'].unparsed_value
|
20
19
|
|
21
|
-
email.
|
20
|
+
email.encoded_eml.attach({ io: StringIO.new(message.encoded), filename: "email-#{email.id}.eml" })
|
21
|
+
|
22
|
+
email.update_columns(message_id:, mailer:, status:) # rubocop:disable Rails/SkipsModelValidations
|
22
23
|
# else
|
23
24
|
# TODO: crear email
|
24
25
|
# pg_warn 'El mail no tenía objeto Email asociado, se creó uno on the fly.', :warn
|
@@ -55,19 +55,6 @@ RSpec.describe Admin::EmailsController do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe 'GET #content_eml' do
|
59
|
-
subject do
|
60
|
-
get :content_eml, params: { id: email.id }
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:email) { create :email }
|
64
|
-
|
65
|
-
it do
|
66
|
-
subject
|
67
|
-
expect(response).to have_http_status(:ok)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
58
|
describe 'GET #index' do
|
72
59
|
subject do
|
73
60
|
get :index, params: {}
|
@@ -104,6 +91,7 @@ RSpec.describe Admin::EmailsController do
|
|
104
91
|
describe 'GET #show' do
|
105
92
|
it 'returns a success response' do
|
106
93
|
email = create(:email)
|
94
|
+
email.encoded_eml.attach({ io: StringIO.new(Faker::Lorem.sentence), filename: 'email.eml' })
|
107
95
|
get :show, params: { id: email.to_param }
|
108
96
|
expect(response).to be_successful
|
109
97
|
end
|
@@ -15,7 +15,6 @@ FactoryBot.define do
|
|
15
15
|
body_input { Faker::Lorem.sentence }
|
16
16
|
# tags { Faker::Lorem.sentence }
|
17
17
|
# associated
|
18
|
-
# content_eml { Faker::Lorem.sentence }
|
19
18
|
# message_id { Faker::Lorem.sentence }
|
20
19
|
# mailer { Faker::Lorem.sentence }
|
21
20
|
# status_detail { Faker::Lorem.sentence }
|
data/pg_rails/lib/version.rb
CHANGED