foreman-tasks 8.2.0 → 8.3.1

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: b4f35490448b3b8f50b3632eae9f565b954642055c8d81726e0774cbf0d5fbc5
4
- data.tar.gz: f837f11d4a5e7c1d5d4fcc831bd20139d822374cb0289e5d9990f64830eac2f9
3
+ metadata.gz: 93c84b1a1d6185d2831ad1c1c19968cf32b6e44afc494cc17fdca86e3ed20122
4
+ data.tar.gz: 1bb7bfd14c8f17758bf0c787e0f5877b00d05bc8cae8851b217ae974bdd1376a
5
5
  SHA512:
6
- metadata.gz: 83be04fc0573f35f6caa81af65adb8a5e81dbde915fa6f7465837d580dce1abe5e92fad16a4d3970e16170a0c195e08067d1e6fc2af97719f4e51bd7364c09af
7
- data.tar.gz: ac31f6183e48f5dd4040e4679c2dc394afdc624bee2d0bf2beab8c94ca7661f8e72f165b92177551f1bb097bfb676669e5fa4c248c856b1bea2bd6080d3d54aa
6
+ metadata.gz: c1d8fb885b03ff508cd96d1c4b97c00ce562d77df8a9cdd6a839b142a7db865996ce6141c793f039ad4b64cd9789e741f62a58d8ad2733648a29053fea6dd98c
7
+ data.tar.gz: 36416c3c59724ce2a71e71ba68601f570c2da1f3608c5835c7cd8705ab425cacddcfdfd228be73834b15ebe15690ec8a2521baf9afb2430511e58dba7042316a
@@ -8,12 +8,10 @@ module Actions
8
8
  def plan
9
9
  time = Time.now.utc
10
10
  cutoff = time - INTERVAL
11
- notification = ::ForemanTasks::TasksMailNotification.find_by(name: "long_running_tasks")
12
- org_admin_role = Role.find_by(name: 'Organization admin')
13
- users = User.left_joins(:roles)
14
- .where(id: UserMailNotification.where(mail_notification_id: notification.id).select(:role_id))
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
@@ -18,5 +18,9 @@ module Actions
18
18
  def humanized_name
19
19
  _('Deliver notifications about long running tasks')
20
20
  end
21
+
22
+ def rescue_strategy_for_self
23
+ ::Dynflow::Action::Rescue::Skip
24
+ end
21
25
  end
22
26
  end
@@ -36,7 +36,7 @@ module Actions
36
36
  end
37
37
 
38
38
  def event_names
39
- [event_name_base + '_' + event_name_suffix(:success)]
39
+ [:success, :failure].map { |suffix| event_name_base + '_' + event_name_suffix(suffix) }
40
40
  end
41
41
 
42
42
  def namespaced_event_names
@@ -51,7 +51,16 @@ module Actions
51
51
  def self.included(base)
52
52
  base.extend ClassMethods
53
53
  base.include ::Foreman::Observable
54
- base.execution_plan_hooks.use :emit_event, :on => :success
54
+ base.execution_plan_hooks.use :emit_event_success, :on => :success
55
+ base.execution_plan_hooks.use :emit_event_failure, :on => :failure
56
+ end
57
+
58
+ def emit_event_success(execution_plan)
59
+ emit_event(execution_plan, :success)
60
+ end
61
+
62
+ def emit_event_failure(execution_plan)
63
+ emit_event(execution_plan, :failure)
55
64
  end
56
65
 
57
66
  def emit_event(execution_plan, hook = :success)
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ForemanTasks
2
- VERSION = '8.2.0'.freeze
2
+ VERSION = '8.3.1'.freeze
3
3
  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.2.0
4
+ version: 8.3.1
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-08-28 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynflow