Module: ForemanPuppet::HostsAndHostgroupsHelper
- Defined in:
- app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb
Instance Method Summary collapse
- #environment_inherited_by_default?(host) ⇒ Boolean
-
#host_puppet_environment_field(form, select_options = {}, html_options = {}) ⇒ Object
rubocop:enable Rails/HelperInstanceVariable.
- #hostgroup_puppet_environment_field(form, select_options = {}, html_options = {}) ⇒ Object
- #puppet_environment_field(form, environments_choice, select_options = {}, html_options = {}) ⇒ Object
- #puppetclasses_with_parameters_for(obj) ⇒ Object
-
#user_set_environment? ⇒ Boolean
rubocop:disable Rails/HelperInstanceVariable.
Instance Method Details
#environment_inherited_by_default?(host) ⇒ Boolean
3 4 5 6 7 8 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 3 def environment_inherited_by_default?(host) return false unless host.hostgroup && host.hostgroup_id_was.nil? return false if params[:action] == 'clone' return true unless params[:host] !params[:host].dig(:puppet_attributes, :environment_id) end |
#host_puppet_environment_field(form, select_options = {}, html_options = {}) ⇒ Object
rubocop:enable Rails/HelperInstanceVariable
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 22 def host_puppet_environment_field(form, = {}, = {}) form.fields_for(:puppet, form.object.puppet || form.object.build_puppet, include_id: false) do |fields| = { include_blank: true, disable_button: _(::HostsAndHostgroupsHelper::INHERIT_TEXT), disable_button_enabled: environment_inherited_by_default?(form.object), user_set: user_set_environment?, }.deep_merge() = { data: { host: { id: form.object.id, }, }, }.deep_merge() puppet_environment_field( fields, accessible_resource(fields.object, 'ForemanPuppet::Environment', association: :environment), , ) end end |
#hostgroup_puppet_environment_field(form, select_options = {}, html_options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 48 def hostgroup_puppet_environment_field(form, = {}, = {}) form.fields_for(:puppet, form.object.puppet || form.object.build_puppet, include_id: false) do |fields| = { include_blank: blank_or_inherit_f(fields, :environment), }.deep_merge() puppet_environment_field( fields, accessible_resource(fields.object, 'ForemanPuppet::Environment', association: :environment), , ) end end |
#puppet_environment_field(form, environments_choice, select_options = {}, html_options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 63 def puppet_environment_field(form, environments_choice, = {}, = {}) = { onchange: 'tfm.puppetEnc.hostForm.updatePuppetclasses(this)', help_inline: :indicator, }.deep_merge() select_f( form, :environment_id, environments_choice, :id, :to_label, , ) end |
#puppetclasses_with_parameters_for(obj) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 80 def puppetclasses_with_parameters_for(obj) classes = obj.all_puppetclasses ids = classes.reorder(nil).pluck(:id) class_vars = ForemanPuppet::PuppetclassLookupKey.reorder(nil) .joins(:environment_classes) .where(EnvironmentClass.arel_table[:puppetclass_id].in(ids)) .distinct .pluck('environment_classes.puppetclass_id') classes.where(id: class_vars) end |
#user_set_environment? ⇒ Boolean
rubocop:disable Rails/HelperInstanceVariable
11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb', line 11 def user_set_environment? # if the host has no hostgroup return true unless @host&.hostgroup # when editing a host, the values are specified explicitly return true if params[:action] == 'edit' return true if params[:action] == 'clone' # check if the user set the field explicitly despite setting a hostgroup. params[:host] && params[:host][:hostgroup_id] && params[:host].dig(:puppet_attributes, :environment_id) end |