foreman/app/controllers/concerns/foreman/controller/taxonomy_multiple.rb @ 9d43fc71
2fa95807 | Joseph Mitchell Magen | module Foreman::Controller::TaxonomyMultiple
|
|
extend ActiveSupport::Concern
|
|||
included do
|
|||
68388bc2 | Michael Moll | # TODO: make this before filter work, its not working as the same filter is defined in the hosts controller
|
|
# before_action :find_multiple, :only => [:select_multiple_organization, :update_multiple_organization,
|
|||
2fa95807 | Joseph Mitchell Magen | # :select_multiple_location, :update_multiple_location]
|
|
end
|
|||
feacea35 | Amos Benari | def select_multiple_organization
|
|
acfbc458 | Marek Hulan | @hosts = find_multiple
|
|
feacea35 | Amos Benari | end
|
|
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | def select_multiple_location
|
|
acfbc458 | Marek Hulan | @hosts = find_multiple
|
|
feacea35 | Amos Benari | end
|
|
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | def update_multiple_organization
|
|
acfbc458 | Marek Hulan | @hosts = find_multiple
|
|
feacea35 | Amos Benari | update_multiple_taxonomies(:organization)
|
|
end
|
|||
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | def update_multiple_location
|
|
acfbc458 | Marek Hulan | @hosts = find_multiple
|
|
feacea35 | Amos Benari | update_multiple_taxonomies(:location)
|
|
end
|
|||
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | private
|
|
2fa95807 | Joseph Mitchell Magen | ||
5f029ed6 | Daniel Lobato | def update_multiple_taxonomies(type)
|
|
feacea35 | Amos Benari | # simple validations
|
|
9d43fc71 | Michael Moll | if params[type].nil? || (id = params[type][:id]).blank?
|
|
feacea35 | Amos Benari | error "No #{type.to_s.classify} selected!"
|
|
e263719a | David Davis | redirect_to(hosts_path)
|
|
return
|
|||
feacea35 | Amos Benari | end
|
|
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | taxonomy = Taxonomy.find_by_id(id)
|
|
2fa95807 | Joseph Mitchell Magen | ||
feacea35 | Amos Benari | if params[type][:optimistic_import] == 'yes'
|
|
@hosts.update_all("#{type}_id".to_sym => taxonomy.id)
|
|||
68388bc2 | Michael Moll | # hosts location needs to be updated before import missing ids
|
|
feacea35 | Amos Benari | taxonomy.import_missing_ids
|
|
else
|
|||
if taxonomy.need_to_be_selected_ids.count == 0
|
|||
@hosts.update_all("#{type}_id".to_sym => taxonomy.id)
|
|||
671b45e9 | Joseph Mitchell Magen | else
|
|
feacea35 | Amos Benari | error "Cannot update #{taxonomy.type} to #{taxonomy.name} because of mismatch in settings"
|
|
redirect_back_or_to hosts_path
|
|||
return
|
|||
2fa95807 | Joseph Mitchell Magen | end
|
|
end
|
|||
cf94f62e | Avi Sharvit | success "Updated hosts: Changed #{type.to_s.classify}"
|
|
feacea35 | Amos Benari | redirect_back_or_to hosts_path
|
|
2fa95807 | Joseph Mitchell Magen | end
|
|
acfbc458 | Marek Hulan | end
|