Sha256: 9276f955fa5f5b5bbf814643ab68a2885d9586f2c4fafef07c02f32baea5ee63

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module ForemanSalt
  class SaltEnvironment < ApplicationRecord
    include Authorizable
    extend FriendlyId
    friendly_id :name

    has_many :hosts, :class_name => '::Host::Managed'
    has_many :hostgroups, :class_name => '::Hostgroup'

    has_many :salt_module_environments
    has_many :salt_modules, :through => :salt_module_environments, :before_remove => :remove_from_hosts

    validates :name, :uniqueness => true, :presence => true, :format => { :with => /\A[\w\d\.]+\z/, :message => N_('is alphanumeric and cannot contain spaces') }

    scoped_search :on => :name, :complete_value => true
    scoped_search :relation => :hostgroups, :on => :name, :complete_value => true, :rename => :hostgroup
    scoped_search :relation => :hosts, :on => :name, :complete_value => true, :rename => :host

    def self.humanize_class_name(_name = nil)
      _('Salt environment')
    end

    def self.permission_name
      'salt_environments'
    end

    private

    def remove_from_hosts(state)
      HostSaltModule.joins(:host).where(:hosts => { :salt_environment_id => id }, :salt_module_id => state).destroy
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreman_salt-12.0.0 app/models/foreman_salt/salt_environment.rb
foreman_salt-11.0.1 app/models/foreman_salt/salt_environment.rb
foreman_salt-11.0.0 app/models/foreman_salt/salt_environment.rb
foreman_salt-10.3.1 app/models/foreman_salt/salt_environment.rb
foreman_salt-10.3.0 app/models/foreman_salt/salt_environment.rb
foreman_salt-10.2.0 app/models/foreman_salt/salt_environment.rb
foreman_salt-10.1.0 app/models/foreman_salt/salt_environment.rb
foreman_salt-9.0.1 app/models/foreman_salt/salt_environment.rb
foreman_salt-10.0.0 app/models/foreman_salt/salt_environment.rb