pg_rails 7.0.8.pre.alpha.57 → 7.0.8.pre.alpha.59

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49e6cb9913064fd946d0ed5100572a31e6e39b7b4c0c5efeb8ca8ca520d9e75b
4
- data.tar.gz: 206b926af17474e1ce20b6d76724729b60a6ee10955b3b459191949d72bcd3ed
3
+ metadata.gz: b3d8524d771ec24a2b2728686f3823fe5f4d52ead73f969e99ba003361572b55
4
+ data.tar.gz: 2d6efcc793a2b907ba38b974c6b437bae06e1fb9a4bf15554d2d90434a13dc9e
5
5
  SHA512:
6
- metadata.gz: 66dd233f281b67cf4557acdcc839095b6cf4327972f2bde48544a025fadf8ad272b5e6b15aea8fc000e7a8d4cb2dec37af3512d5326d23cf774dfef172a38147
7
- data.tar.gz: '091b62e7722d9bdabb8df428074ac5f4a796cb1c2a4b058a86c6fd235a88b11dc160b1b30a5b34bd3f807a533c0c7337d61b8d92327028843c2ec1a2f8fd313a'
6
+ metadata.gz: 7fb40a82f52722779c7ac1dc58bc7c1d4c637ceed424861f8c927c7915c19d6c462e8800ee1e67dfcd9f5983052a7618967ffd84ee70ba8ba17771150b3bd677
7
+ data.tar.gz: 378f705720ae31579b3105c88e0d9d422ed8ad4c26b88bd5140b5fb3830fbcd005c6285681b19065576bd2be91f12feb5b52c6d943d2f29bcdcf6bed2ba0d365
@@ -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,17 @@ module PgEngine
11
11
 
12
12
  layout 'pg_layout/mailer'
13
13
 
14
+ # default delivery_method: :smtp
15
+
14
16
  rescue_from MailNotDelivered do |err|
15
- # FIXME: marcar el Email en la DB como fallido
16
- pg_err err
17
+ pg_warn err, :error
18
+ @email.update_columns(status: :failed, status_detail: err.to_s) # rubocop:disable Rails/SkipsModelValidations
17
19
  end
18
20
 
19
- def mail
20
- super.tap do |message|
21
+ protected
22
+
23
+ def mail(*args)
24
+ super(*args).tap do |message|
21
25
  # message.mailgun_options = {
22
26
  # 'tag' => email.tags,
23
27
  # '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'
@@ -45,7 +45,7 @@ class Email < ApplicationRecord
45
45
  kredis_unique_list :logs
46
46
 
47
47
  # TODO: y el fallido temporario?
48
- enumerize :status, in: { pending: 0, blocked: 1, sent: 2, accepted: 3, delivered: 4, rejected: 5 }
48
+ enumerize :status, in: { pending: 0, failed: 1, sent: 2, accepted: 3, delivered: 4, rejected: 5 }
49
49
 
50
50
  validates :from_address, :to, :status, presence: true
51
51
 
@@ -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
@@ -3,64 +3,28 @@
3
3
  module PgEngine
4
4
  class EmailObserver
5
5
  def self.delivered_email(message)
6
- # content = get_content(message)
7
- # subject = message.subject
8
-
9
- # message.to puede ser un string o un array de strings
10
- # to = [message.to].flatten.join(', ')
11
-
12
6
  message_id = message.message_id
13
7
  mailer = message.delivery_handler.to_s
14
8
  status = get_status(message)
15
- content_eml = message.encoded
16
- return if message['email'].blank?
17
-
18
- # El objeto Email ya estaba creado. Agarro ese objeto y le actualizo las cosas
19
- email = message['email'].unparsed_value
20
9
 
21
- email.update_columns(message_id:, mailer:, status:, content_eml:) # rubocop:disable Rails/SkipsModelValidations
22
- # else
23
- # TODO: crear email
24
- # pg_warn 'El mail no tenía objeto Email asociado, se creó uno on the fly.', :warn
25
- # # No hay objeto Email, entonces le creo uno para que quede logueado.
26
- # # TODO: el content puede ser TXT
27
- # Email.create!(message_id: message.message_id, body_html: message.encoded,
28
- # subject: subject, recipient: recipient,
29
- # date: DateTime.now, mailer: message.delivery_handler.to_s, associated: associated(message),
30
- # status: get_status(message), observations: get_observations(message))
10
+ if message['email'].present?
11
+ email = message['email'].unparsed_value
12
+ email.update_columns(message_id:, mailer:, status:) # rubocop:disable Rails/SkipsModelValidations
13
+ email.encoded_eml.attach({ io: StringIO.new(message.encoded), filename: "email-#{email.id}.eml" })
14
+ else
15
+ pg_warn 'El mail no tenía objeto Email asociado.', :warn
16
+ # FIX: el content puede ser TXT
17
+ # Email.create!(message_id: message.message_id, body_html: message.encoded,
18
+ # subject: subject, recipient: recipient,
19
+ # date: DateTime.now, mailer: message.delivery_handler.to_s, associated: associated(message),
20
+ # status: get_status(message), observations: get_observations(message))
21
+ end
22
+ rescue StandardError => e
23
+ pg_warn e, :error
31
24
  end
32
25
 
33
26
  def self.get_status(message)
34
27
  message.perform_deliveries ? :sent : :blocked
35
28
  end
36
-
37
- # def self.get_html_or_text(message)
38
- # message.body.parts.find { |p| p.content_type.match(/multipart/).present? }
39
- # part = message.body.parts.find { |p| p.content_type.match(/html/).present? }
40
- # part = message.body.parts.find { |p| p.content_type.match(/text/).present? } if part.nil?
41
- # part = message if part.nil?
42
- # part.body.raw_source
43
- # end
44
-
45
- # def self.associated(message)
46
- # return if message['associated'].blank?
47
-
48
- # message['associated'].unparsed_value
49
- # end
50
-
51
- # def self.get_observations(message)
52
- # return if message['observations'].blank?
53
-
54
- # message['observations'].unparsed_value
55
- # end
56
-
57
- # def self.get_content(message)
58
- # multipart = message.body.parts.find { |p| p.content_type.match(/multipart/).present? }
59
- # part = multipart.presence || message
60
- # get_html_or_text(part)
61
- # rescue StandardError => e
62
- # pg_err e
63
- # ''
64
- # end
65
29
  end
66
30
  end
@@ -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.59'
5
5
  end
@@ -7,3 +7,5 @@ $danger-bg-subtle: tint-color($danger, 98%);
7
7
  // $info-border-subtle: tint-color($info, 60%);
8
8
  $warning-border-subtle: tint-color($warning, 20%);
9
9
  // $danger-border-subtle: tint-color($danger, 60%);
10
+
11
+ $btn-close-focus-shadow: none;
metadata CHANGED
@@ -1,14 +1,14 @@
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.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails