pg_rails 7.6.14 → 7.6.16
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 +4 -4
 - data/pg_engine/app/controllers/admin/simple_user_notifiers_controller.rb +75 -0
 - data/pg_engine/app/notifiers/simple_user_notifier.rb +17 -0
 - data/pg_engine/app/views/admin/simple_user_notifiers/_form.html.slim +14 -0
 - data/pg_engine/app/views/admin/simple_user_notifiers/show.html.slim +29 -0
 - data/pg_engine/config/routes.rb +1 -1
 - data/pg_engine/lib/pg_engine/navigator.rb +1 -1
 - data/pg_layout/app/javascript/application.js +6 -4
 - data/pg_rails/lib/version.rb +1 -1
 - metadata +5 -6
 - data/pg_engine/app/controllers/admin/eventos_controller.rb +0 -83
 - data/pg_engine/app/models/evento.rb +0 -27
 - data/pg_engine/app/views/admin/eventos/index.html.slim +0 -6
 - data/pg_engine/app/views/admin/eventos/new.html.slim +0 -16
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f1be39ed176491e2f5da66a9a1764f6c2f8c8509c7510999f72007cd0a1bb0f7
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 591fe03520a040b5651b3a8153d7bdc7bc42afd6c8b6b44cfbf5a6525d883e89
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 06c346252f40b648dc108ada25a3a4ab7dda9cb8ead20964d835aa19231063b165e56c2565d7b854ca8aa073245346c7b269852e4f392ae5d1139acef3cbe629
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 619cc8ab8f5ef3ab61f8e825b9c3ca3ba8767a77ee35ebe7e0f6dc23add99b33075d8049f89f2022d42417a94b06ec19c81fc5b36fb8271d42132183d32fce08
         
     | 
| 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
                  @event = SimpleUserNotifier.new(modelo_params)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @event.message.save!
         
     | 
| 
      
 22 
     | 
    
         
            +
                  unless @event.valid?
         
     | 
| 
      
 23 
     | 
    
         
            +
                    render :new, status: :unprocessable_entity
         
     | 
| 
      
 24 
     | 
    
         
            +
                    return
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  json_params_for_event = {
         
     | 
| 
      
 27 
     | 
    
         
            +
                    message: @event.message,
         
     | 
| 
      
 28 
     | 
    
         
            +
                    tooltip: @event.tooltip
         
     | 
| 
      
 29 
     | 
    
         
            +
                  }
         
     | 
| 
      
 30 
     | 
    
         
            +
                  notifier = SimpleUserNotifier.with(json_params_for_event)
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  case @event.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: @event.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 
     | 
    
         
            +
                  render :new, status: :unprocessable_entity
         
     | 
| 
      
 50 
     | 
    
         
            +
                  # :nocov:
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
                # rubocop:enable Metrics/MethodLength
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                private
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                def atributos_permitidos
         
     | 
| 
      
 57 
     | 
    
         
            +
                  %i[
         
     | 
| 
      
 58 
     | 
    
         
            +
                    type message tooltip record_type record_id target subject
         
     | 
| 
      
 59 
     | 
    
         
            +
                    user_ids message_text
         
     | 
| 
      
 60 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def atributos_para_buscar
         
     | 
| 
      
 64 
     | 
    
         
            +
                  %i[]
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                def atributos_para_listar
         
     | 
| 
      
 68 
     | 
    
         
            +
                  %i[message tooltip created_at notifications_count]
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                def atributos_para_mostrar
         
     | 
| 
      
 72 
     | 
    
         
            +
                  %i[tooltip]
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
              end
         
     | 
| 
      
 75 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -29,4 +29,21 @@ 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
         
     | 
| 
       32 
49 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            = pg_form_for @simple_user_notifier 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
         
     | 
    
        data/pg_engine/config/routes.rb
    CHANGED
    
    
| 
         @@ -48,10 +48,12 @@ document.addEventListener('pg:record-created', (ev) => { 
     | 
|
| 
       48 
48 
     | 
    
         
             
            })
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
            document.addEventListener('pg:record-updated', (ev) => {
         
     | 
| 
       51 
     | 
    
         
            -
               
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                 
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
              if (!ev.data.dataset.inline) {
         
     | 
| 
      
 52 
     | 
    
         
            +
                Turbo.visit(window.location)
         
     | 
| 
      
 53 
     | 
    
         
            +
                setTimeout(() => {
         
     | 
| 
      
 54 
     | 
    
         
            +
                  Turbo.cache.clear()
         
     | 
| 
      
 55 
     | 
    
         
            +
                }, 1000)
         
     | 
| 
      
 56 
     | 
    
         
            +
              }
         
     | 
| 
       55 
57 
     | 
    
         
             
            })
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
       57 
59 
     | 
    
         
             
            document.addEventListener('pg:record-destroyed', (ev) => {
         
     | 
    
        data/pg_rails/lib/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 7.6.16
         
     | 
| 
       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 
     | 
    
         
            +
            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/ 
     | 
| 
      
 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
         
     | 
| 
         @@ -746,7 +746,6 @@ files: 
     | 
|
| 
       746 
746 
     | 
    
         
             
            - pg_engine/app/models/current.rb
         
     | 
| 
       747 
747 
     | 
    
         
             
            - pg_engine/app/models/email.rb
         
     | 
| 
       748 
748 
     | 
    
         
             
            - pg_engine/app/models/email_log.rb
         
     | 
| 
       749 
     | 
    
         
            -
            - pg_engine/app/models/evento.rb
         
     | 
| 
       750 
749 
     | 
    
         
             
            - pg_engine/app/models/mensaje_contacto.rb
         
     | 
| 
       751 
750 
     | 
    
         
             
            - pg_engine/app/models/pg_engine/base_record.rb
         
     | 
| 
       752 
751 
     | 
    
         
             
            - pg_engine/app/models/user.rb
         
     | 
| 
         @@ -776,8 +775,8 @@ files: 
     | 
|
| 
       776 
775 
     | 
    
         
             
            - pg_engine/app/views/admin/emails/_form.html.slim
         
     | 
| 
       777 
776 
     | 
    
         
             
            - pg_engine/app/views/admin/emails/_send.html.slim
         
     | 
| 
       778 
777 
     | 
    
         
             
            - pg_engine/app/views/admin/emails/show.html.slim
         
     | 
| 
       779 
     | 
    
         
            -
            - pg_engine/app/views/admin/ 
     | 
| 
       780 
     | 
    
         
            -
            - pg_engine/app/views/admin/ 
     | 
| 
      
 778 
     | 
    
         
            +
            - pg_engine/app/views/admin/simple_user_notifiers/_form.html.slim
         
     | 
| 
      
 779 
     | 
    
         
            +
            - pg_engine/app/views/admin/simple_user_notifiers/show.html.slim
         
     | 
| 
       781 
780 
     | 
    
         
             
            - pg_engine/app/views/admin/user_accounts/_form.html.slim
         
     | 
| 
       782 
781 
     | 
    
         
             
            - pg_engine/app/views/admin/user_accounts/_user_account.html.slim
         
     | 
| 
       783 
782 
     | 
    
         
             
            - 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,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
         
     |