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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49e6cb9913064fd946d0ed5100572a31e6e39b7b4c0c5efeb8ca8ca520d9e75b
4
- data.tar.gz: 206b926af17474e1ce20b6d76724729b60a6ee10955b3b459191949d72bcd3ed
3
+ metadata.gz: 418b790d06e3fdd8000b1722d68c479728e29eca73c1181544cf9241aed5745a
4
+ data.tar.gz: ec5ae58ada69aacb782c37374051022747b41049bd8cdd4824dac3f278a92325
5
5
  SHA512:
6
- metadata.gz: 66dd233f281b67cf4557acdcc839095b6cf4327972f2bde48544a025fadf8ad272b5e6b15aea8fc000e7a8d4cb2dec37af3512d5326d23cf774dfef172a38147
7
- data.tar.gz: '091b62e7722d9bdabb8df428074ac5f4a796cb1c2a4b058a86c6fd235a88b11dc160b1b30a5b34bd3f807a533c0c7337d61b8d92327028843c2ec1a2f8fd313a'
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 content_eml]
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 content_eml
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 content_eml_link]
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 content_eml_link
18
- link_to 'Download', helpers.content_eml_admin_email_path(object), target: :_blank, rel: :noopener
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
- def mail
20
- super.tap do |message|
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(0), not null
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
- # def convert_br(input)
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
@@ -28,8 +28,4 @@ class EmailPolicy < ApplicationPolicy
28
28
  # def acceso_total?
29
29
  # user.developer?
30
30
  # end
31
-
32
- def content_eml?
33
- acceso_total?
34
- end
35
31
  end
@@ -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) do
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
@@ -14,7 +14,6 @@ class CreateEmails < ActiveRecord::Migration[7.1]
14
14
  t.string :body_input
15
15
  t.string :tags, array: true
16
16
  t.references :associated, polymorphic: true, index: true
17
- t.string :content_eml
18
17
  t.string :message_id
19
18
  t.string :mailer
20
19
  t.string :status_detail
@@ -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.update_columns(message_id:, mailer:, status:, content_eml:) # rubocop:disable Rails/SkipsModelValidations
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.57'
4
+ VERSION = '7.0.8-alpha.58'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.8.pre.alpha.57
4
+ version: 7.0.8.pre.alpha.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso