pg_rails 7.0.8.pre.alpha.107 → 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: 1f5edf4d4749811c99ded6408e1b226c551629bac864ba616c3887505b2239fb
4
- data.tar.gz: f6f158eb4fdc879080ea5d349de6ad5ecebe42136ffca60ec87787210939b4c5
3
+ metadata.gz: 0ea0a25a34ed115022c43283c50cd8678d9ebde034abbfcd65f149fa486d2004
4
+ data.tar.gz: 6ad0a841b8d2b3c73513c8890a7f2642598c78341ef1b79567a9e049b5cd8882
5
5
  SHA512:
6
- metadata.gz: a6338a8c896422e27b9879d5b3bcdb871406c6d11c51858671d5eb7cd8da950da4637c3eadb0a8c2a3c8d55f6256e8ba5045f96e60bfcb949ce3a0f66f03d16a
7
- data.tar.gz: 5208e12befd8c75cfe1e3b51ced749857259a239c07fe461c9daccd1261e3532683d241a66176ef051fd74fc9e33b370aa0eecdc45d4143b32732ef9c696b678
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(
@@ -11,7 +11,7 @@ module PgEngine
11
11
  end
12
12
 
13
13
  def configure_permitted_parameters
14
- devise_parameter_sanitizer.permit(:sign_up, keys: %i[nombre apellido])
14
+ devise_parameter_sanitizer.permit(:sign_up, keys: %i[nombre apellido accept_terms])
15
15
  devise_parameter_sanitizer.permit(:account_update, keys: %i[nombre apellido])
16
16
  end
17
17
  end
@@ -34,7 +34,6 @@ module PgEngine
34
34
  end
35
35
 
36
36
  def html_status(color:)
37
- # rubocop:disable Rails/OutputSafety
38
37
  %(<!DOCTYPE html><html><body style="background-color: #{color}"></body></html>).html_safe
39
38
  # rubocop:enable Rails/OutputSafety
40
39
  end
@@ -87,7 +87,6 @@ module PgEngine
87
87
  fields: fields.gsub("\n", '')
88
88
  }
89
89
  ) do
90
- # rubocop:disable Rails/OutputSafety
91
90
  "<i class=\"bi bi-plus-lg\"></i> #{name}".html_safe
92
91
  # rubocop:enable Rails/OutputSafety
93
92
  end
@@ -34,7 +34,7 @@ class PgFormBuilder < SimpleForm::FormBuilder
34
34
  base_message = (base_errors.map(&:to_s).join('<br>') if base_errors.present?)
35
35
  base_tag = error_notification(message: base_message, class: 'alert alert-danger') if base_message
36
36
 
37
- "#{title}#{base_tag}".html_safe # rubocop:disable Rails/OutputSafety
37
+ "#{title}#{base_tag}".html_safe
38
38
  end
39
39
 
40
40
  def mensaje
@@ -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
@@ -50,6 +50,10 @@ class User < ApplicationRecord
50
50
  validates_length_of :password, if: :password_required?, within: 6..128,
51
51
  message: 'es demasiado corta (6 caracteres mínimo)'
52
52
 
53
+ validates :accept_terms, acceptance: {
54
+ message: 'Para crear una cuenta es necesario que aceptes los términos y condiciones'
55
+ }
56
+
53
57
  attr_accessor :orphan
54
58
 
55
59
  after_create do
@@ -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
@@ -11,6 +11,7 @@ es:
11
11
  confirmed_at: Fecha de confirmación
12
12
  actualizado_por: Actualizado por
13
13
  creado_por: Creado por
14
+ accept_terms: Acepto los <a href="/terminos_y_condiciones" target="_blank">Términos y condiciones</a>
14
15
  enumerize:
15
16
  email:
16
17
  status:
@@ -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
@@ -22,13 +22,33 @@ describe 'Al Registrarse' do
22
22
  fill_in 'user_apellido', with: Faker::Name.name
23
23
  fill_in 'user_password', with: 'admin123'
24
24
  fill_in 'user_password_confirmation', with: 'admin123'
25
+
26
+ accept_terms
27
+
25
28
  instance_exec('input[type=submit]', &find_scroll).click
29
+ end
30
+ end
31
+
32
+ context 'cuando acepta los términos' do
33
+ let(:accept_terms) do
34
+ check 'user_accept_terms'
35
+ end
36
+
37
+ it 'guarda el user' do
38
+ expect { subject }.to change(User, :count).by(1)
26
39
  expect(page).to have_text('Te enviamos un correo electrónico con instrucciones')
27
40
  end
28
41
  end
29
42
 
30
- it 'guarda el user' do
31
- expect { subject }.to change(User, :count).by(1)
43
+ context 'si no acepta los terms' do
44
+ let(:accept_terms) do
45
+ nil
46
+ end
47
+
48
+ it do
49
+ subject
50
+ expect(page).to have_text 'es necesario que aceptes los términos y condiciones'
51
+ end
32
52
  end
33
53
  end
34
54
 
@@ -34,7 +34,7 @@ class Navbar
34
34
  bar_data.map do |item|
35
35
  {
36
36
  title: item['name'],
37
- attributes: item['attributes']&.html_safe, # rubocop:disable Rails/OutputSafety
37
+ attributes: item['attributes']&.html_safe,
38
38
  path: eval(item['path']),
39
39
  show: item['policy'] ? eval(item['policy']) : true
40
40
  }
@@ -16,6 +16,7 @@
16
16
  <%= f.input :password_confirmation,
17
17
  required: true,
18
18
  input_html: { autocomplete: "new-password" } %>
19
+ <%= f.input :accept_terms, as: :boolean, label: t('attributes.accept_terms').html_safe, error_prefix: '' %>
19
20
  </div>
20
21
 
21
22
  <div class="form-actions">
@@ -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.107'
4
+ VERSION = '7.0.8-alpha.109'
5
5
  end
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.107
4
+ version: 7.0.8.pre.alpha.109
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-07-01 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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