pg_rails 7.0.8.pre.alpha.108 → 7.0.8.pre.alpha.109

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: 5174c715d280ab0c7e5581bd88d2e6cf7ee11507fc739f6369d959fc6d858acd
4
- data.tar.gz: 87f88575ab82c80780fd12a5a65a7dc8c308d5aa828451cdd010121bf9ea8e00
3
+ metadata.gz: 0ea0a25a34ed115022c43283c50cd8678d9ebde034abbfcd65f149fa486d2004
4
+ data.tar.gz: 6ad0a841b8d2b3c73513c8890a7f2642598c78341ef1b79567a9e049b5cd8882
5
5
  SHA512:
6
- metadata.gz: badbc2f74fe7d8b706e9cb2c38284dd92a99f43732fb8162449094ac3b9627d03a91245351e2eb7a1286acf50a82991584ae04ce777326eba975c43e3626d187
7
- data.tar.gz: a2b4ad07bfe5398f89c76490caaa092253f0956d2d7762d6800d99d0bc483cdff7e22a528f3159f6277ab9fdad3b3922e181b29909c66e1a48dd1c922898c7be
6
+ metadata.gz: 7b24cbce39c6cce5ec0ed5d21dc45c61de0cb6986c40bcc04c5495ae2a5fa7cb12934a3609eec80d0008b860ed69a67c6f45df3969771907da4381258a26ac6f
7
+ data.tar.gz: e59deaa85466ff3e49dae7effe311fe77025b9bbdfc97c9667ce97f3ff48efdd20e6428d4e830993e895f0633b0144d6c6a73505a072f92f297972a2cd898b15
@@ -4,13 +4,32 @@ module Admin
4
4
 
5
5
  add_breadcrumb 'Eventos'
6
6
 
7
+ before_action do
8
+ @notifier_types = %w[
9
+ EmailUserNotifier
10
+ SimpleUserNotifier
11
+ ]
12
+ end
13
+
7
14
  def index
8
15
  @events = Noticed::Event.order(id: :desc)
9
16
  end
10
17
 
18
+ # rubocop:disable Metrics/AbcSize
11
19
  def new
12
- @event = Evento.new(type: SimpleUserNotifier.to_s)
20
+ @event = Evento.new(type: 'SimpleUserNotifier')
21
+ return if params[:event_id].blank?
22
+
23
+ reference = Noticed::Event.find(params[:event_id])
24
+ @event.type = reference.type
25
+ @event.message = reference.params[:message]
26
+ @event.message_text = reference.params[:message_text]
27
+ @event.tooltip = reference.params[:tooltip]
28
+ @event.subject = reference.params[:subject]
29
+ @event.record_type = reference.record_type
30
+ @event.record_id = reference.record_id
13
31
  end
32
+ # rubocop:enable Metrics/AbcSize
14
33
 
15
34
  # rubocop:disable Metrics/MethodLength
16
35
  def create # rubocop:disable Metrics/AbcSize
@@ -21,16 +40,22 @@ module Admin
21
40
  return
22
41
  end
23
42
  json_params_for_event = {
43
+ record: @event.record,
24
44
  message: @event.message,
25
- tooltip: @event.tooltip
45
+ message_text: @event.message_text,
46
+ tooltip: @event.tooltip,
47
+ subject: @event.subject
26
48
  }
27
49
  notifier_class = @event.type.constantize
28
50
  notifier = notifier_class.with(json_params_for_event)
29
51
 
30
- if @event.target == 'todos'
52
+ case @event.target
53
+ when 'todos'
31
54
  notifier.deliver(User.all)
32
- elsif @event.target == 'devs'
55
+ when 'devs'
33
56
  notifier.deliver(User.where(developer: true))
57
+ when 'user_ids'
58
+ notifier.deliver(User.where(email: @event.user_ids.split(',')))
34
59
  else
35
60
  # :nocov:
36
61
  'shouldnt happen'
@@ -50,7 +75,8 @@ module Admin
50
75
 
51
76
  def event_params
52
77
  params.require(:evento).permit(
53
- :type, :message, :tooltip, :record_type, :record_id, :target
78
+ :type, :message, :tooltip, :record_type, :record_id, :target, :subject,
79
+ :user_ids, :message_text
54
80
  )
55
81
  end
56
82
  end
@@ -92,6 +92,7 @@ module PgEngine
92
92
 
93
93
  if Current.user.present?
94
94
  @notifications = Current.user.notifications.order(id: :desc)
95
+ .where(type: 'SimpleUserNotifier::Notification')
95
96
  unseen = @notifications.unseen.any?
96
97
  tooltip = @notifications.unseen.map(&:tooltip).first
97
98
  @notifications_bell = NotificationsBellComponent.new(
@@ -0,0 +1,12 @@
1
+ module PgEngine
2
+ class UserMailer < ApplicationMailer
3
+ # default delivery_method: :smtp
4
+
5
+ def notification
6
+ recipient = params[:notification].recipient
7
+ @html = params[:message].html_safe
8
+ @text = params[:message_text]
9
+ mail(to: recipient.email, subject: params[:subject])
10
+ end
11
+ end
12
+ end
@@ -3,9 +3,25 @@ class Evento
3
3
  include ActionText::Attribute
4
4
  extend Enumerize
5
5
 
6
- attr_accessor :tooltip, :target, :message, :type, :record_type, :record_id
6
+ attr_accessor :tooltip, :target, :message, :message_text, :type,
7
+ :record_type, :record_id,
8
+ :subject, :user_ids
7
9
 
8
10
  validates :target, :type, :message, presence: true
9
11
 
10
- enumerize :target, in: { todos: 0, devs: 1 }
12
+ enumerize :target, in: { todos: 0, devs: 1, user_ids: 2 }
13
+
14
+ validates :message_text, :subject, presence: true, if: lambda {
15
+ type == 'EmailUserNotifier'
16
+ }
17
+
18
+ validates :user_ids, presence: true, if: lambda {
19
+ target == 'user_ids'
20
+ }
21
+
22
+ def record
23
+ return if record_id.blank?
24
+
25
+ record_type.constantize.find(record_id)
26
+ end
11
27
  end
@@ -0,0 +1,8 @@
1
+ class EmailUserNotifier < ApplicationNotifier
2
+ deliver_by :email do |config|
3
+ config.mailer = 'PgEngine::UserMailer'
4
+ config.method = 'notification'
5
+ end
6
+
7
+ required_param :message, :subject
8
+ end
@@ -1,13 +1,16 @@
1
1
  = pg_form_for @event, url: admin_eventos_path do |f|
2
2
  = f.mensajes_de_error
3
3
 
4
- = f.input :type, as: :select, collection: ApplicationNotifier.descendants.map(&:to_s)
4
+ = f.input :type, as: :select, collection: @notifier_types
5
5
  - if params[:plain_text]
6
6
  = f.input :message, as: :text
7
7
  - else
8
8
  = f.rich_text_area :message
9
+ = f.input :message_text, as: :text
9
10
  = f.input :tooltip
11
+ = f.input :subject
10
12
  = f.input :record_type
11
13
  = f.input :record_id
12
14
  = f.input :target
15
+ = f.input :user_ids, label: 'User emails'
13
16
  = f.submit
@@ -17,7 +17,7 @@ describe PgEngine::Resource do
17
17
  instancia.set_clase_modelo
18
18
  end
19
19
 
20
- fit do
20
+ it do
21
21
  expect { subject }.to raise_error(PgEngine::PageNotFoundError)
22
22
  end
23
23
  end
@@ -9,6 +9,12 @@ describe 'Eventos' do
9
9
  SimpleUserNotifier.with(message: 'New post').deliver(User.all, enqueue_job: false)
10
10
  end
11
11
 
12
+ around do |example|
13
+ perform_enqueued_jobs do
14
+ example.run
15
+ end
16
+ end
17
+
12
18
  it 'renders the event index' do
13
19
  get '/a/eventos'
14
20
 
@@ -21,13 +27,25 @@ describe 'Eventos' do
21
27
  expect(response.body).to include 'Tooltip'
22
28
  post '/a/eventos', params: {
23
29
  evento: {
24
- type: 'SimpleUserNotifier',
30
+ type:,
25
31
  message: 'hola',
32
+ message_text:,
33
+ subject: asunto,
34
+ user_ids:,
35
+ record_type: 'User',
36
+ record_id:,
26
37
  target:
27
38
  }
28
39
  }
40
+ get "/a/eventos/new?event_id=#{Noticed::Event.last.id}"
29
41
  end
30
42
 
43
+ let(:record_id) { nil }
44
+ let(:asunto) { nil }
45
+ let(:user_ids) { nil }
46
+ let(:message_text) { nil }
47
+ let(:type) { 'SimpleUserNotifier' }
48
+
31
49
  context 'cuando se manda a los devs' do
32
50
  let(:target) { 'devs' }
33
51
 
@@ -44,7 +62,36 @@ describe 'Eventos' do
44
62
  end
45
63
  end
46
64
 
65
+ context 'cuando se manda a usuarios específicos por mail' do
66
+ let(:target) { 'user_ids' }
67
+ let(:asunto) { 'subjecttt' }
68
+ let(:user_ids) { 'user@host.com,otro@test.com' }
69
+ let(:message_text) { 'texto' }
70
+ let(:message) { '<h1>html</h1>' }
71
+ let(:type) { 'EmailUserNotifier' }
72
+ let(:record_id) { user.id }
73
+
74
+ before do
75
+ create :user, email: 'user@host.com'
76
+ create :user, email: 'otro@test.com'
77
+ end
78
+
79
+ it do
80
+ expect { subject }.to change(Noticed::Notification, :count).by(2)
81
+ end
82
+ end
83
+
47
84
  context 'cuando hay error' do
85
+ subject do
86
+ post '/a/eventos', params: {
87
+ evento: {
88
+ type:,
89
+ message: 'hola',
90
+ target:
91
+ }
92
+ }
93
+ end
94
+
48
95
  let(:target) { 'bla' }
49
96
 
50
97
  it do
@@ -0,0 +1,7 @@
1
+ <%= yield %>
2
+
3
+ <% if @footer_href.present? %>
4
+ ----------------------
5
+ <%= @footer_image_alt %>
6
+ <%= @footer_href %>
7
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.108'
4
+ VERSION = '7.0.8-alpha.109'
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.108
4
+ version: 7.0.8.pre.alpha.109
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
@@ -1033,6 +1033,7 @@ files:
1033
1033
  - pg_engine/app/lib/pg_form_builder.rb
1034
1034
  - pg_engine/app/mailers/pg_engine/admin_mailer.rb
1035
1035
  - pg_engine/app/mailers/pg_engine/base_mailer.rb
1036
+ - pg_engine/app/mailers/pg_engine/user_mailer.rb
1036
1037
  - pg_engine/app/models/account.rb
1037
1038
  - pg_engine/app/models/current.rb
1038
1039
  - pg_engine/app/models/email.rb
@@ -1043,6 +1044,7 @@ files:
1043
1044
  - pg_engine/app/models/user.rb
1044
1045
  - pg_engine/app/models/user_account.rb
1045
1046
  - pg_engine/app/notifiers/application_notifier.rb
1047
+ - pg_engine/app/notifiers/email_user_notifier.rb
1046
1048
  - pg_engine/app/notifiers/simple_user_notifier.rb
1047
1049
  - pg_engine/app/overrides/activestorage_direct_uploads.rb
1048
1050
  - pg_engine/app/policies/account_policy.rb
@@ -1083,6 +1085,8 @@ files:
1083
1085
  - pg_engine/app/views/pg_engine/base/edit.html.slim
1084
1086
  - pg_engine/app/views/pg_engine/base/index.html.slim
1085
1087
  - pg_engine/app/views/pg_engine/base/new.html.slim
1088
+ - pg_engine/app/views/pg_engine/user_mailer/notification.html.slim
1089
+ - pg_engine/app/views/pg_engine/user_mailer/notification.text.slim
1086
1090
  - pg_engine/app/views/public/mensaje_contactos/_gracias.html.slim
1087
1091
  - pg_engine/app/views/public/mensaje_contactos/new.html.slim
1088
1092
  - pg_engine/config/initializers/action_mailer.rb
@@ -1233,7 +1237,7 @@ files:
1233
1237
  - pg_layout/app/views/layouts/pg_layout/containerized.html.slim
1234
1238
  - pg_layout/app/views/layouts/pg_layout/devise.html.slim
1235
1239
  - pg_layout/app/views/layouts/pg_layout/mailer.html.slim
1236
- - pg_layout/app/views/layouts/pg_layout/mailer.text.slim
1240
+ - pg_layout/app/views/layouts/pg_layout/mailer.text.erb
1237
1241
  - pg_layout/app/views/pg_layout/_flash.html.slim
1238
1242
  - pg_layout/app/views/pg_layout/_navbar.html.erb
1239
1243
  - pg_layout/app/views/pg_layout/_sidebar.html.erb
@@ -1,4 +0,0 @@
1
- = yield
2
-
3
- | PgRails
4
- | https://example.com.ar