foreman-tasks 8.1.1 → 8.1.3
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/app/lib/actions/check_long_running_tasks.rb +8 -6
- data/app/lib/actions/deliver_long_running_tasks_notification.rb +4 -0
- data/app/lib/actions/middleware/load_setting_values.rb +5 -0
- data/app/models/foreman_tasks/concerns/user_extensions.rb +17 -0
- data/app/views/tasks_mailer/long_tasks.html.erb +6 -6
- data/app/views/tasks_mailer/long_tasks.text.erb +6 -6
- data/db/seeds.d/95-mail_notifications.rb +14 -0
- data/lib/foreman_tasks/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6b47d3165d26d95f9799243481ff75c14aaa59ec3966edcf8afe95ee1da77a97
         | 
| 4 | 
            +
              data.tar.gz: 2b0eb29411d81b496169b970f0edb93abda50f6a109ee13d21830f918e52e29f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 686ecd66afcaab661bb7916746547dad1a8b33dc9087a2dfd874a87e87d0d426b4fe05f9807337be8fcd13a2861a02dc98c4ae03326df482a7970eed89745fa9
         | 
| 7 | 
            +
              data.tar.gz: 4424d6de0469d10129d6c53d5abc190307e497524b6a80a4349be630a383ce1c4fcde172241c64567ea843ba5ef0f804e3c93d7e54ff5f36dd350c12a3ba289a
         | 
| @@ -8,12 +8,10 @@ module Actions | |
| 8 8 | 
             
                def plan
         | 
| 9 9 | 
             
                  time = Time.now.utc
         | 
| 10 10 | 
             
                  cutoff = time - INTERVAL
         | 
| 11 | 
            -
                   | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                              .where( | 
| 15 | 
            -
                              .or(User.where(admin: true))
         | 
| 16 | 
            -
                              .or(User.where(id: UserRole.where(id: [org_admin_role.id] + org_admin_role.cloned_role_ids).select(:owner_id)))
         | 
| 11 | 
            +
                  users = User.joins(:mail_notifications)
         | 
| 12 | 
            +
                              .where(mail_enabled: true, mail_notifications: { name: 'long_running_tasks' })
         | 
| 13 | 
            +
                              .where.not(mail: [nil, ''])
         | 
| 14 | 
            +
                              .where(disabled: [nil, false])
         | 
| 17 15 |  | 
| 18 16 | 
             
                  query = "state ^ (#{STATES.join(', ')}) AND state_updated_at <= \"#{cutoff}\""
         | 
| 19 17 | 
             
                  users.each do |user|
         | 
| @@ -41,5 +39,9 @@ module Actions | |
| 41 39 | 
             
                def humanized_name
         | 
| 42 40 | 
             
                  _('Check for long running tasks')
         | 
| 43 41 | 
             
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def rescue_strategy_for_self
         | 
| 44 | 
            +
                  Dynflow::Action::Rescue::Skip
         | 
| 45 | 
            +
                end
         | 
| 44 46 | 
             
              end
         | 
| 45 47 | 
             
            end
         | 
| @@ -8,6 +8,23 @@ module ForemanTasks | |
| 8 8 | 
             
                    has_many :tasks, :dependent => :nullify,
         | 
| 9 9 | 
             
                                     :class_name => ::ForemanTasks::Task.name
         | 
| 10 10 | 
             
                    # rubocop:enable Rails/ReflectionClassName
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    before_validation :attach_task_mail_notifications, on: :create
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def attach_task_mail_notifications
         | 
| 16 | 
            +
                    org_admin_role = Role.find_by(name: 'Organization admin')
         | 
| 17 | 
            +
                    admin_role_ids = ([org_admin_role.id] + org_admin_role.cloned_role_ids)
         | 
| 18 | 
            +
                    role_ids = roles.map(&:id)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    return unless admin || (role_ids & admin_role_ids).any?
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    notification = MailNotification.find_by(name: 'long_running_tasks')
         | 
| 23 | 
            +
                    return if notification.nil?
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    if user_mail_notifications.none? { |n| n.mail_notification_id == notification.id }
         | 
| 26 | 
            +
                      user_mail_notifications.build(mail_notification_id: notification.id, interval: 'Subscribe')
         | 
| 27 | 
            +
                    end
         | 
| 11 28 | 
             
                  end
         | 
| 12 29 | 
             
                end
         | 
| 13 30 | 
             
              end
         | 
| @@ -8,11 +8,11 @@ | |
| 8 8 | 
             
            <div class="dashboard">
         | 
| 9 9 | 
             
              <table>
         | 
| 10 10 | 
             
                <tr>
         | 
| 11 | 
            -
                  <th | 
| 12 | 
            -
                  <th | 
| 13 | 
            -
                  <th | 
| 14 | 
            -
                  <th | 
| 15 | 
            -
                  <th | 
| 11 | 
            +
                  <th><%= _("ID") %></th>
         | 
| 12 | 
            +
                  <th><%= _("Action") %></th>
         | 
| 13 | 
            +
                  <th><%= _("Label") %></th>
         | 
| 14 | 
            +
                  <th><%= _("State") %></th>
         | 
| 15 | 
            +
                  <th><%= _("State updated at") %></th>
         | 
| 16 16 | 
             
                </tr>
         | 
| 17 17 | 
             
                <% @report.tasks.each do |task| %>
         | 
| 18 18 | 
             
                  <tr>
         | 
| @@ -26,4 +26,4 @@ | |
| 26 26 | 
             
              </table>
         | 
| 27 27 | 
             
            </div>
         | 
| 28 28 |  | 
| 29 | 
            -
            <%= link_to 'More details', foreman_tasks_tasks_url(search: @report.query) %>
         | 
| 29 | 
            +
            <%= link_to _('More details'), foreman_tasks_tasks_url(search: @report.query) %>
         | 
| @@ -6,11 +6,11 @@ | |
| 6 6 | 
             
            More details: <%= foreman_tasks_tasks_url(search: @report.query) %>
         | 
| 7 7 |  | 
| 8 8 | 
             
            <% @report.tasks.each do |task| %>
         | 
| 9 | 
            -
            ID | 
| 10 | 
            -
            Action | 
| 11 | 
            -
            Label | 
| 12 | 
            -
            State | 
| 13 | 
            -
            State updated at | 
| 14 | 
            -
            Details | 
| 9 | 
            +
            <%= _('ID') %>: <%= task.id %>
         | 
| 10 | 
            +
            <%= _('Action') %>: <%= task.action %>
         | 
| 11 | 
            +
            <%= _('Label') %>: <%= task.label %>
         | 
| 12 | 
            +
            <%= _('State') %>: <%= task.state %>
         | 
| 13 | 
            +
            <%= _('State updated at') %>: <%= task.state_updated_at %>
         | 
| 14 | 
            +
            <%= _('Details') %>: <%= foreman_tasks_task_url(task) %>
         | 
| 15 15 |  | 
| 16 16 | 
             
            <% end %>
         | 
| @@ -20,5 +20,19 @@ notifications.each do |notification| | |
| 20 20 | 
             
                  raise ::Foreman::Exception.new(N_("Unable to create mail notification: %s"),
         | 
| 21 21 | 
             
                                                 SeedHelper.format_errors(created_notification))
         | 
| 22 22 | 
             
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                org_admin_role = Role.find_by(name: 'Organization admin')
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                users = User.left_joins(:roles)
         | 
| 27 | 
            +
                            .joins(:auth_source)
         | 
| 28 | 
            +
                            .where(admin: true)
         | 
| 29 | 
            +
                            .or(User.where(id: UserRole.where(id: [org_admin_role.id] + org_admin_role.cloned_role_ids).select(:owner_id)))
         | 
| 30 | 
            +
                            .where.not(auth_source: { name: 'Hidden' })
         | 
| 31 | 
            +
                users.each do |user|
         | 
| 32 | 
            +
                  mail = UserMailNotification.create(mail_notification_id: created_notification.id, user_id: user.id, interval: 'Subscribe')
         | 
| 33 | 
            +
                  if mail.nil? || mail.errors.any?
         | 
| 34 | 
            +
                    raise ::Foreman::Exception.new(N_("Unable to enable mail notification to user '%s': %s"), user.login, SeedHelper.format_errors(mail))
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 23 37 | 
             
              end
         | 
| 24 38 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: foreman-tasks
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 8.1. | 
| 4 | 
            +
              version: 8.1.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ivan Nečas
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023- | 
| 11 | 
            +
            date: 2023-10-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: dynflow
         |