Class: Setting::Content

Inherits:
Setting
  • Object
show all
Defined in:
app/models/setting/content.rb

Class Method Summary collapse

Class Method Details

.ensure_sync_notificationObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/setting/content.rb', line 24

def self.ensure_sync_notification
  include Rails.application.routes.url_helpers

  resource = Runcible::Resources::EventNotifier
  url      = events_repositories_url(:only_path => false, :host => Setting[:foreman_url])
  type     = '*' #resource::EventTypes::REPO_SYNC_COMPLETE
  notifs   = resource.list

  #delete any similar tasks with the wrong url (in case it changed)
  notifs.select { |n| n['event_types'] == [type] && n['notifier_config']['url'] != url }.each do |e|
    resource.delete(e['id'])
  end

  #only create a notifier if one doesn't exist with the correct url
  exists = notifs.select { |n| n['event_types'] == [type] && n['notifier_config']['url'] == url }
  resource.create(resource::NotifierTypes::REST_API, { :url => url }, [type]) if exists.empty?
end

.load_defaultsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/setting/content.rb', line 7

def self.load_defaults
  return unless ActiveRecord::Base.connection.table_exists?('settings')
  return unless super

  Setting.transaction do
    [
      self.set('use_pulp', "Use Pulp to manage content", true),
      self.set('pulp_url', "Pulp URL", "https://127.0.0.1/pulp/api/v2/"),
      self.set('pulp_oauth_secret', "Pulp OAuth Secret", ""),
      self.set('pulp_oauth_key', "Pulp OAuth Key", ""),
    ].compact.each { |s| self.create s.update(:category => "Setting::Content") }
  end

  true

end