pg_rails 7.6.15 → 7.6.17

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: 3db6eee59bbd35a8a834cb9d09b7a6a1d04fe49026661b4dba7d66dd02580484
4
- data.tar.gz: e4aca63a466bba3b75d01db82a4146b79d7f25de228afcede2568c072edd3808
3
+ metadata.gz: a05ebc7aa2578ab2c32a72e68dc56b958aa0787216c6703764af4d906eba4aff
4
+ data.tar.gz: 43e3d8a43d5d4b6b490de9aec4f1b122051905c81c40f699868e2015b2db314f
5
5
  SHA512:
6
- metadata.gz: a8b824b4d410a79f47b13696748dcbcfc051a762a6b9e2a0a400f33d58f1ed6db699e4bbcb6c77c1920f5f5601c0e81caa4c161487e6dc274388ba154af5a22c
7
- data.tar.gz: a7f81b4a9bdc9e86ee4595b5d64af8f11992f09e089c14f0e9468a41cd982b6f5106b382c05051986689504bc8156ab46f7cee9ce5397972f74ed14c5a83d39c
6
+ metadata.gz: 2c9d7e326b078d50d6b5e7b8ac04f8aecfbe6217d6eb5d6984139cf1a9a9ab4f8f06e423e2b2babbfbd51266100bdd6191960a79d4b7a9a2c351f8647d3493a4
7
+ data.tar.gz: dea6b0686fe63c661a129b17a880d4158fec6fcc0430e96aaaace4444fddffd84818dabd164dee2523906824babded554cb0a10c49ed419da73b8d2c4a44baff
@@ -0,0 +1,76 @@
1
+ module Admin
2
+ class SimpleUserNotifiersController < AdminController
3
+ include PgEngine::Resource
4
+
5
+ self.clase_modelo = SimpleUserNotifier
6
+
7
+ before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
8
+
9
+ def column_options_for(object, attribute)
10
+ case attribute
11
+ when :message
12
+ { class: 'column-truncate-30', title: object.send(attribute).to_s }
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ # rubocop:disable Metrics/MethodLength
19
+ def create
20
+ @simple_user_notifier = SimpleUserNotifier.new(modelo_params)
21
+ # @simple_user_notifier.message.save!
22
+ unless @simple_user_notifier.valid?
23
+ render :new, status: :unprocessable_entity
24
+ return
25
+ end
26
+ json_params_for_event = {
27
+ message: @simple_user_notifier.message,
28
+ tooltip: @simple_user_notifier.tooltip
29
+ }
30
+ notifier = SimpleUserNotifier.with(json_params_for_event)
31
+
32
+ case @simple_user_notifier.target
33
+ when 'todos'
34
+ notifier.deliver(User.all)
35
+ when 'devs'
36
+ notifier.deliver(User.where(developer: true))
37
+ when 'user_ids'
38
+ notifier.deliver(User.where(email: @simple_user_notifier.user_ids.split(',')))
39
+ else
40
+ # :nocov:
41
+ 'shouldnt happen'
42
+ # :nocov:
43
+ end
44
+
45
+ redirect_to admin_simple_user_notifiers_path
46
+ rescue StandardError => e
47
+ # :nocov:
48
+ flash.now[:alert] = e.to_s
49
+ # @simple_user_notifier = @simple_user_notifier.decorate
50
+ render :new, status: :unprocessable_entity
51
+ # :nocov:
52
+ end
53
+ # rubocop:enable Metrics/MethodLength
54
+
55
+ private
56
+
57
+ def atributos_permitidos
58
+ %i[
59
+ type message tooltip record_type record_id target subject
60
+ user_ids message_text
61
+ ]
62
+ end
63
+
64
+ def atributos_para_buscar
65
+ %i[]
66
+ end
67
+
68
+ def atributos_para_listar
69
+ %i[message tooltip created_at notifications_count]
70
+ end
71
+
72
+ def atributos_para_mostrar
73
+ %i[tooltip]
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,50 @@
1
+ module PgEngine
2
+ module Naming
3
+ def gender
4
+ self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
5
+ end
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ # This is a per class variable, all subclasses of BaseRecord inherit it
13
+ # BUT **the values are independent between all of them**
14
+ attr_accessor :default_modal, :inline_editable_fields
15
+
16
+ def inline_editable?(attribute)
17
+ inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
18
+ end
19
+
20
+ def ransackable_associations(_auth_object = nil)
21
+ authorizable_ransackable_associations
22
+ end
23
+
24
+ def ransackable_attributes(_auth_object = nil)
25
+ authorizable_ransackable_attributes
26
+ end
27
+
28
+ def nombre_plural
29
+ model_name.human(count: 2)
30
+ end
31
+
32
+ def nombre_singular
33
+ model_name.human(count: 1)
34
+ end
35
+
36
+ def human_attribute_name(attribute, options = {})
37
+ # Remove suffixes
38
+ if attribute.to_s.ends_with?('_text')
39
+ # Si es un enumerized
40
+ super(attribute[0..-6], options)
41
+ elsif attribute.to_s.ends_with?('_f')
42
+ # Si es un decorated method
43
+ super(attribute[0..-3], options)
44
+ else
45
+ super
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -7,58 +7,17 @@ module PgEngine
7
7
  extend Enumerize
8
8
  include PrintHelper
9
9
  include PostgresHelper
10
+ include Naming
10
11
 
11
12
  self.abstract_class = true
12
13
 
13
14
  before_create :setear_creado_y_actualizado_por
14
15
  before_update :setear_actualizado_por
15
16
 
16
- class << self
17
- # This is a per class variable, all subclasses of BaseRecord inherit it
18
- # BUT **the values are independent between all of them**
19
- attr_accessor :default_modal, :inline_editable_fields
20
-
21
- def inline_editable?(attribute)
22
- inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
23
- end
24
- end
25
-
26
17
  # ransacker :search do |parent|
27
18
  # parent.table[:nombre]
28
19
  # end
29
20
 
30
- def self.ransackable_associations(_auth_object = nil)
31
- authorizable_ransackable_associations
32
- end
33
-
34
- def self.ransackable_attributes(_auth_object = nil)
35
- authorizable_ransackable_attributes
36
- end
37
-
38
- def gender
39
- self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
40
- end
41
-
42
- def self.nombre_plural
43
- model_name.human(count: 2)
44
- end
45
-
46
- def self.nombre_singular
47
- model_name.human(count: 1)
48
- end
49
-
50
- def self.human_attribute_name(attribute, options = {})
51
- if attribute.to_s.ends_with?('_text')
52
- # Si es un enumerized
53
- super(attribute[0..-6], options)
54
- elsif attribute.to_s.ends_with?('_f')
55
- # Si es un decorated method
56
- super(attribute[0..-3], options)
57
- else
58
- super
59
- end
60
- end
61
-
62
21
  def actions_component
63
22
  ActionsComponent.new(self)
64
23
  end
@@ -29,4 +29,25 @@ class SimpleUserNotifier < ApplicationNotifier
29
29
  # Add required params
30
30
  #
31
31
  required_param :message
32
+
33
+ attr_accessor :target, :user_ids
34
+
35
+ enumerize :target, in: { todos: 0, devs: 1, user_ids: 2 }
36
+
37
+ %i[message message_text tooltip subject].each do |field|
38
+ define_method :"#{field}" do
39
+ params[field]
40
+ end
41
+ define_method :"#{field}=" do |value|
42
+ params[field] = value
43
+ end
44
+ end
45
+
46
+ def self.policy_class
47
+ ApplicationPolicy
48
+ end
49
+
50
+ def self.decorator_class
51
+ PgEngine::BaseRecordDecorator
52
+ end
32
53
  end
@@ -0,0 +1,14 @@
1
+ = pg_form_for @simple_user_notifier.decorate do |f|
2
+ - if params[:plain_text]
3
+ = link_to 'Change to rich text', url_for
4
+ = f.input :message, as: :text
5
+ - else
6
+ = link_to 'Change to plain text', url_for(plain_text: true)
7
+ = f.rich_text_area :message
8
+ = f.input :tooltip
9
+ / = f.input :record_type
10
+ / = f.input :record_id
11
+ - unless @simple_user_notifier.persisted?
12
+ = f.input :target
13
+ = f.input :user_ids, label: 'User emails'
14
+ = f.submit
@@ -0,0 +1,29 @@
1
+ - content_for :actions do
2
+ = @simple_user_notifier.destroy_link_redirect
3
+ .ms-1
4
+ = @simple_user_notifier.edit_link
5
+
6
+ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
7
+ - atributos_para_mostrar.each do |att|
8
+ tr
9
+ th = @clase_modelo.human_attribute_name(att)
10
+ td = render InlineShowComponent.new(@simple_user_notifier.object, att)
11
+ tr
12
+ th = t('attributes.created_at')
13
+ td = @simple_user_notifier.created_at
14
+ tr
15
+ th = t('attributes.updated_at')
16
+ td = @simple_user_notifier.updated_at
17
+
18
+ .bg-secondary-subtle.p-4.mt-3.trix-content
19
+ = @simple_user_notifier.message.html_safe
20
+
21
+ div style="max-width: 30em"
22
+ table.table.table-sm
23
+ tr
24
+ th Destinatario
25
+ th Visto
26
+ - @simple_user_notifier.notifications.order('seen_at desc nulls last').each do |notification|
27
+ tr
28
+ td = notification.recipient
29
+ td = dmy_time notification.seen_at
@@ -42,7 +42,7 @@ Rails.application.routes.draw do
42
42
 
43
43
  namespace :admin, path: 'a' do
44
44
  pg_resource(:emails)
45
- pg_resource(:eventos)
45
+ pg_resource(:simple_user_notifiers)
46
46
  pg_resource(:email_logs) do
47
47
  collection do
48
48
  post :mailgun_sync
@@ -27,6 +27,10 @@ module PgEngine
27
27
  ActsAsTenant.without_tenant(&)
28
28
  end
29
29
  end
30
+ Noticed::ApplicationRecord.class_eval do
31
+ extend Enumerize
32
+ include PgEngine::Naming
33
+ end
30
34
  end
31
35
 
32
36
  initializer 'pg_engine.set_exceptions_app' do
@@ -39,7 +39,7 @@ module PgEngine
39
39
 
40
40
  navbar.add_item('sidebar.signed_in', {
41
41
  name: 'Eventos',
42
- path: 'admin_eventos_path'
42
+ path: 'admin_simple_user_notifiers_path'
43
43
  })
44
44
  navbar.add_item('sidebar.signed_in', {
45
45
  name: 'Emails',
@@ -12,4 +12,16 @@ describe PgEngine::BaseRecord do
12
12
  expect(obj).to eq described_class.human_attribute_name('bla')
13
13
  end
14
14
  end
15
+
16
+ describe '#default_modal' do
17
+ it 'the values are independent from each class' do
18
+ model_class = Class.new(described_class)
19
+ another_model_class = Class.new(described_class)
20
+ model_class.default_modal = true
21
+ another_model_class.default_modal = false
22
+ expect(model_class.default_modal).to be true
23
+ expect(another_model_class.default_modal).to be false
24
+ expect(described_class.default_modal).to be_nil
25
+ end
26
+ end
15
27
  end
@@ -16,28 +16,23 @@ describe 'Eventos' do
16
16
  end
17
17
 
18
18
  it 'renders the event index' do
19
- get '/a/eventos'
19
+ get '/a/simple_user_notifiers'
20
20
 
21
- expect(response.body).to include 'New post'
21
+ expect(response.body).to include 'Crear simple user notifier'
22
22
  end
23
23
 
24
24
  describe 'posting events' do
25
25
  subject do
26
- get '/a/eventos/new'
26
+ get '/a/simple_user_notifiers/new'
27
27
  expect(response.body).to include 'Tooltip'
28
- post '/a/eventos', params: {
29
- evento: {
30
- type:,
28
+ post '/a/simple_user_notifiers', params: {
29
+ simple_user_notifier: {
31
30
  message: 'hola',
32
- message_text:,
33
- subject: asunto,
34
31
  user_ids:,
35
- record_type: 'User',
36
- record_id:,
37
32
  target:
38
33
  }
39
34
  }
40
- get "/a/eventos/new?event_id=#{Noticed::Event.last.id}"
35
+ # get "/a/eventos/new?event_id=#{Noticed::Event.last.id}"
41
36
  end
42
37
 
43
38
  let(:record_id) { nil }
@@ -83,10 +78,9 @@ describe 'Eventos' do
83
78
 
84
79
  context 'cuando hay error' do
85
80
  subject do
86
- post '/a/eventos', params: {
87
- evento: {
88
- type:,
89
- message: 'hola',
81
+ post '/a/simple_user_notifiers', params: {
82
+ simple_user_notifier: {
83
+ message: nil,
90
84
  target:
91
85
  }
92
86
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.6.15'
4
+ VERSION = '7.6.17'
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.6.15
4
+ version: 7.6.17
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-10-11 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -693,7 +693,7 @@ files:
693
693
  - pg_engine/app/controllers/admin/accounts_controller.rb
694
694
  - pg_engine/app/controllers/admin/email_logs_controller.rb
695
695
  - pg_engine/app/controllers/admin/emails_controller.rb
696
- - pg_engine/app/controllers/admin/eventos_controller.rb
696
+ - pg_engine/app/controllers/admin/simple_user_notifiers_controller.rb
697
697
  - pg_engine/app/controllers/admin/user_accounts_controller.rb
698
698
  - pg_engine/app/controllers/admin/users_controller.rb
699
699
  - pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb
@@ -743,10 +743,10 @@ files:
743
743
  - pg_engine/app/mailers/pg_engine/base_mailer.rb
744
744
  - pg_engine/app/mailers/pg_engine/user_mailer.rb
745
745
  - pg_engine/app/models/account.rb
746
+ - pg_engine/app/models/concerns/pg_engine/naming.rb
746
747
  - pg_engine/app/models/current.rb
747
748
  - pg_engine/app/models/email.rb
748
749
  - pg_engine/app/models/email_log.rb
749
- - pg_engine/app/models/evento.rb
750
750
  - pg_engine/app/models/mensaje_contacto.rb
751
751
  - pg_engine/app/models/pg_engine/base_record.rb
752
752
  - pg_engine/app/models/user.rb
@@ -776,8 +776,8 @@ files:
776
776
  - pg_engine/app/views/admin/emails/_form.html.slim
777
777
  - pg_engine/app/views/admin/emails/_send.html.slim
778
778
  - pg_engine/app/views/admin/emails/show.html.slim
779
- - pg_engine/app/views/admin/eventos/index.html.slim
780
- - pg_engine/app/views/admin/eventos/new.html.slim
779
+ - pg_engine/app/views/admin/simple_user_notifiers/_form.html.slim
780
+ - pg_engine/app/views/admin/simple_user_notifiers/show.html.slim
781
781
  - pg_engine/app/views/admin/user_accounts/_form.html.slim
782
782
  - pg_engine/app/views/admin/user_accounts/_user_account.html.slim
783
783
  - pg_engine/app/views/admin/user_accounts/edit.html.slim
@@ -1,83 +0,0 @@
1
- module Admin
2
- class EventosController < AdminController
3
- layout 'pg_layout/containerized'
4
-
5
- add_breadcrumb 'Eventos'
6
-
7
- before_action do
8
- @notifier_types = %w[
9
- EmailUserNotifier
10
- SimpleUserNotifier
11
- ]
12
- end
13
-
14
- def index
15
- @events = Noticed::Event.order(id: :desc)
16
- end
17
-
18
- # rubocop:disable Metrics/AbcSize
19
- def new
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
31
- end
32
- # rubocop:enable Metrics/AbcSize
33
-
34
- # rubocop:disable Metrics/MethodLength
35
- def create # rubocop:disable Metrics/AbcSize
36
- @event = Evento.new(event_params)
37
- # @event.message.save!
38
- unless @event.valid?
39
- render :new, status: :unprocessable_entity
40
- return
41
- end
42
- json_params_for_event = {
43
- record: @event.record,
44
- message: @event.message,
45
- message_text: @event.message_text,
46
- tooltip: @event.tooltip,
47
- subject: @event.subject
48
- }
49
- notifier_class = @event.type.constantize
50
- notifier = notifier_class.with(json_params_for_event)
51
-
52
- case @event.target
53
- when 'todos'
54
- notifier.deliver(User.all)
55
- when 'devs'
56
- notifier.deliver(User.where(developer: true))
57
- when 'user_ids'
58
- notifier.deliver(User.where(email: @event.user_ids.split(',')))
59
- else
60
- # :nocov:
61
- 'shouldnt happen'
62
- # :nocov:
63
- end
64
-
65
- redirect_to admin_eventos_path
66
- rescue StandardError => e
67
- # :nocov:
68
- flash.now[:alert] = e.to_s
69
- render :new, status: :unprocessable_entity
70
- # :nocov:
71
- end
72
- # rubocop:enable Metrics/MethodLength
73
-
74
- private
75
-
76
- def event_params
77
- params.require(:evento).permit(
78
- :type, :message, :tooltip, :record_type, :record_id, :target, :subject,
79
- :user_ids, :message_text
80
- )
81
- end
82
- end
83
- end
@@ -1,27 +0,0 @@
1
- class Evento
2
- include ActiveModel::API
3
- include ActionText::Attribute
4
- extend Enumerize
5
-
6
- attr_accessor :tooltip, :target, :message, :message_text, :type,
7
- :record_type, :record_id,
8
- :subject, :user_ids
9
-
10
- validates :target, :type, :message, presence: true
11
-
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
27
- end
@@ -1,6 +0,0 @@
1
- - content_for :actions do
2
- = link_to 'Nuevo', new_admin_evento_path
3
- h1 Eventos
4
-
5
- - @events.each do |event|
6
- pre.mb-5 = JSON.pretty_generate event.as_json
@@ -1,16 +0,0 @@
1
- = pg_form_for @event, url: admin_eventos_path do |f|
2
- = f.input :type, as: :select, collection: @notifier_types
3
- - if params[:plain_text]
4
- = link_to 'Change to rich text', url_for
5
- = f.input :message, as: :text
6
- - else
7
- = link_to 'Change to plain text', url_for(plain_text: true)
8
- = f.rich_text_area :message
9
- = f.input :message_text, as: :text, hint: 'Solo para emails, para la plain/text part'
10
- = f.input :tooltip
11
- = f.input :subject
12
- = f.input :record_type
13
- = f.input :record_id
14
- = f.input :target
15
- = f.input :user_ids, label: 'User emails'
16
- = f.submit