Skip to content

Commit

Permalink
Fixes #34796 - Fixes for Rails 6.1 upgrade
Browse files Browse the repository at this point in the history
Changes:
- loading of host extension helper
- Rails 6 'where.not' use NAND instead of NOR [0]

[0] rails/rails#36029
  • Loading branch information
stejskalleos authored and adamruzicka committed May 11, 2022
1 parent 5770fd3 commit ac35a30
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 40 deletions.
19 changes: 19 additions & 0 deletions app/helpers/foreman_ansible/hosts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module ForemanAnsible
module HostsHelper
def ansible_hosts_multiple_actions
return [] unless User.current.can?(:create_job_invocations) &&
User.current.can?(:play_roles_on_host)

[{ action: [_('Run all Ansible roles'),
multiple_play_roles_hosts_path,
false], priority: 1000 }]
end

def ansible_roles_present?(host)
host.ansible_roles.present? ||
host.inherited_ansible_roles.present?
end
end
end
30 changes: 0 additions & 30 deletions app/helpers/foreman_ansible/hosts_helper_extensions.rb

This file was deleted.

18 changes: 9 additions & 9 deletions app/services/foreman_ansible/variables_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ def get_variables_names(role_name)
end

def import_variables(role_variables, new_roles)
detect_changes(
role_variables.map do |role_name, variables|
next if variables.blank?
role = import_new_role(role_name, new_roles)
next if role.blank?
initialize_variables(variables, role)
end.select(&:present?).flatten.compact
)
detect_changes(role_variables.map do |role_name, variables|
next if variables.blank?
role = import_new_role(role_name, new_roles)
next if role.blank?
initialize_variables(variables, role)
end.select(&:present?).flatten.compact)
end

def import_variables_roles(roles)
Expand Down Expand Up @@ -96,7 +94,9 @@ def detect_changes(imported)
persisted, changes[:new] = imported.partition { |var| var.id.present? }
changed, _old = persisted.partition(&:changed?)
_overriden, changes[:update] = changed.partition(&:override?)
changes[:obsolete] = AnsibleVariable.where.not(:id => persisted.pluck(:id), :imported => false)
changes[:obsolete] = AnsibleVariable.where.not(id: persisted.pluck(:id)).
where.not(imported: false)

changes
end

Expand Down
1 change: 0 additions & 1 deletion lib/foreman_ansible/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class Engine < ::Rails::Engine
config.to_prepare do
::Host::Managed.prepend ForemanAnsible::HostManagedExtensions
::Hostgroup.include ForemanAnsible::HostgroupExtensions
::HostsHelper.include ForemanAnsible::HostsHelperExtensions
::HostsController.include ForemanAnsible::Concerns::HostsControllerExtensions
::Api::V2::HostsController.include ForemanAnsible::Api::V2::HostsControllerExtensions
::Api::V2::HostsController.include ForemanAnsible::Api::V2::HostsParamGroupExtensions
Expand Down
4 changes: 4 additions & 0 deletions lib/foreman_ansible/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,8 @@ def ansible_variables_with_overrides
register_report_scanner ForemanAnsible::AnsibleReportScanner
register_report_origin 'Ansible', 'ConfigReport'
end

describe_host do
multiple_actions_provider :ansible_hosts_multiple_actions
end
end

0 comments on commit ac35a30

Please sign in to comment.