Sha256: 0e5e366da199fabc874b4149563ddc5a3fced401a6b66848ef52a3a5bb4b8d6e

Contents?: true

Size: 1.38 KB

Versions: 40

Compression:

Stored size: 1.38 KB

Contents

module ForemanPuppet
  class ConfigGroup < ApplicationRecord
    self.table_name = 'config_groups'

    audited
    include Authorizable
    include Parameterizable::ByIdName

    validates_lengths_from_database

    has_many :config_group_classes, dependent: :destroy
    has_many :puppetclasses, through: :config_group_classes
    has_many :host_config_groups, dependent: :destroy
    has_many_hosts through: :host_config_groups, source: :host, source_type: 'Host::Managed'
    has_many :hostgroups, through: :host_config_groups, source: :host, source_type: 'Hostgroup'

    validates :name, presence: true, uniqueness: true

    scoped_search on: :name, complete_value: true
    scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']

    default_scope -> { order('config_groups.name') }

    # the following methods are required for app/views/puppetclasses/_class_selection.html.erb
    alias_method :classes, :puppetclasses
    alias_method :individual_puppetclasses, :puppetclasses

    def available_puppetclasses
      Puppetclass.where(nil)
    end

    # for auditing
    def to_label
      name
    end

    def hosts_count
      ::Host::Managed.authorized.search_for(%(config_group="#{name}")).size
    end

    def hostgroups_count
      ::Hostgroup.authorized.search_for(%(config_group="#{name}")).size
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
foreman_puppet-3.0.4 app/models/foreman_puppet/config_group.rb
foreman_puppet-2.0.4 app/models/foreman_puppet/config_group.rb
foreman_puppet-3.0.3 app/models/foreman_puppet/config_group.rb
foreman_puppet-3.0.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-2.0.3 app/models/foreman_puppet/config_group.rb
foreman_puppet-3.0.1 app/models/foreman_puppet/config_group.rb
foreman_puppet-2.0.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-2.0.0 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.5 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.4 app/models/foreman_puppet/config_group.rb
foreman_puppet-2.0.0.alpha.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.3 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.1 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.0 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.0.rc.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-1.0.0.rc.1 app/models/foreman_puppet/config_group.rb
foreman_puppet-0.1.0 app/models/foreman_puppet/config_group.rb
foreman_puppet-0.0.2 app/models/foreman_puppet/config_group.rb
foreman_puppet-0.0.1 app/models/foreman_puppet/config_group.rb