Skip to content
Snippets Groups Projects
Verified Commit ed2dedd8 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Convert settings to DSL

parent 4b6dcf20
No related branches found
No related tags found
No related merge requests found
Pipeline #91403 failed
# frozen_string_literal: true
class Setting
class NotificationSend < ::Setting
def self.default_settings
[
set('notification_send_enable', _('Enable'), false, N_('Enable')),
set('notification_send_target_url', _('Target URI'), 'https://matrix.org', N_('Target URI')),
set('notification_send_target_room', _('Target Room'), '#test:matrix.org', N_('Target Room')),
set('notification_send_token', _('Token'), 'abcdefg', N_('Token'))
]
end
def self.load_defaults
# Check the table exists
return unless super
transaction do
default_settings.each do |s|
create! s.update(category: 'Setting::NotificationSend')
end
end
true
end
def self.humanized_category
N_('Notification Send')
end
end
end
# frozen_string_literal: true
class ConvertSettingsToDsl < ActiveRecord::Migration[6.0]
def up
# rubocop:disable Rails/SkipsModelValidations
Settings.where(category: 'Setting::NotificationSend').update_all(category: 'Setting')
# rubocop:enable Rails/SkipsModelValidations
end
end
......@@ -13,18 +13,37 @@ module ForemanNotificationSend
end
end
initializer 'foreman_ipxe.load_default_settings', before: :load_config_initializers do
require_dependency File.expand_path('../../app/models/setting/notification_send.rb', __dir__) if \
begin
Setting.table_exists?
rescue StandardError
(false)
end
end
initializer 'foreman_notification_send.register_plugin', before: :finisher_hook do |_app|
Foreman::Plugin.register :foreman_notification_send do
requires_foreman '>= 1.16'
requires_foreman '>= 3.0'
settings do
category :notification_send, N_('Notification Send') do
setting 'notification_send_enable',
type: :boolean,
description: N_('Enable'),
default: false,
full_name: N_('Enable')
setting 'notification_send_target_url',
type: :string,
description: N_('Target URI'),
default: 'https://matrix.org',
full_name: N_('Target URI')
setting 'notification_send_target_room',
type: :string,
description: N_('Target Room'),
default: '#test:matrix.org',
full_name: N_('Target Room')
setting 'notification_send_token',
type: :string,
description: N_('Token'),
default: 'syt_abcdefg',
full_name: N_('Token')
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment