Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ITI/foreman_notification_send
1 result
Show changes
Commits on Source (2)
---
AllCops:
NewCops: enable
Metrics/AbcSize:
Enabled: false
Style/Documentation:
Enabled: false
# frozen_string_literal: true
module ForemanNotificationSend
module NotificationExtensions
def self.prepended(base)
......@@ -8,20 +9,12 @@ module ForemanNotificationSend
end
def send_notification
if Setting[:notification_send_enable]
sender = SenderBase.create_sender(
backend: :matrix,
hs_url: Setting[:notification_send_target_url],
access_token: Setting[:notification_send_token],
room: Setting[:notification_send_target_room]
)
sender.send_notification(self)
end
send_notification_fallback if Setting[:notification_send_enable]
#NotificationTarget.select { |target| target.should_send?(self) }
# .each { |target| target.send(self) }
rescue StandardError => ex
Foreman::Logging.exception "Failed to send notification #{self}", ex
# NotificationTarget.select { |target| target.should_send?(self) }
# .each { |target| target.send(self) }
rescue StandardError => e
Foreman::Logging.exception "Failed to send notification #{self}", e
end
def level_to_symbol
......@@ -39,18 +32,15 @@ module ForemanNotificationSend
def to_html
unless actions.empty?
action_str = ''
(actions[:links] || []).each do |action|
munged = (actions[:links] || []).map do |action|
next unless action.key?(:href) && action.key?(:title)
url = action[:href]
url = Setting[:foreman_url] + url unless action[:external]
action_str += ' | ' unless action_str.empty?
action_str += "<a href=\"#{url}\">#{action[:title]}</a>"
"<a href=\"#{url}\">#{action[:title]}</a>"
end
action_str = "<br/>[ #{action_str} ]"
action_str = "<br/>[ #{munged.join ' | '} ]"
end
"<b>#{notification_blueprint.group}</b>:<br/>#{level_to_symbol} #{message}#{action_str}"
......@@ -58,20 +48,28 @@ module ForemanNotificationSend
def to_markdown
unless actions.empty?
action_str = ''
(actions[:links] || []).each do |action|
munged = (actions[:links] || []).map do |action|
next unless action.key?(:href) && action.key?(:title)
url = action[:href]
url = Setting[:foreman_url] + url unless action[:external]
action_str += ' | ' unless action_str.empty?
action_str += "[#{action[:title]}](#{url})"
"[#{action[:title]}](#{url})"
end
action_str = " \n\\[ #{action_str}\\ ]"
action_str = " \n\\[ #{munged.join ' | '}\\ ]"
end
"**#{notification_blueprint.group}**:\n#{level_to_symbol} #{message}#{action_str}"
end
private
def send_notification_fallback
SenderBase.create_sender(
backend: :matrix,
hs_url: Setting[:notification_send_target_url],
access_token: Setting[:notification_send_token],
room: Setting[:notification_send_target_room]
).send_notification(self)
end
end
end
......@@ -3,7 +3,7 @@
module ForemanNotificationSend
class NotificationTarget < ApplicationRecord
before_validation do
backend = slugify_backend if backend
# backend = slugify_backend if backend
end
validate :validate_backend
......
# frozen_string_literal: true
require 'matrix_sdk/api'
module ForemanNotificationSend
......
# frozen_string_literal: true
class AddNotificationTargets < ActiveRecord::Migration[5.1]
def change
create_table :notification_targets do |t|
......@@ -11,4 +13,3 @@ class AddNotificationTargets < ActiveRecord::Migration[5.1]
end
end
end
# frozen_string_literal: true
require 'foreman_notification_send/engine'
module ForemanNotificationSend
......
# frozen_string_literal: true
module ForemanNotificationSend
VERSION = '0.1.0'.freeze
VERSION = '0.2.0'
end