Class: PoliciesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PoliciesController
- Includes:
- Foreman::Controller::AutoCompleteSearch, Foreman::Controller::Parameters::Policy
- Defined in:
- app/controllers/policies_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #disassociate_multiple_hosts ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #model_of_controller ⇒ Object
- #new ⇒ Object
- #parse ⇒ Object
- #remove_policy_from_multiple_hosts ⇒ Object
- #scap_content_selected ⇒ Object
- #select_multiple_hosts ⇒ Object
- #show ⇒ Object
- #tailoring_file_selected ⇒ Object
- #update ⇒ Object
- #update_multiple_hosts ⇒ Object
Instance Method Details
#create ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/policies_controller.rb', line 32 def create @policy = ::ForemanOpenscap::Policy.new(policy_params) ForemanOpenscap::LookupKeyOverrider.new(@policy).override if @policy.current_step?('Policy Attributes') if @policy.wizard_completed? && @policy.save process_success :success_redirect => policies_path elsif @policy.errors.none? && @policy.valid? render('new') && return else @policy.rewind_step process_error :object => @policy end end |
#destroy ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/controllers/policies_controller.rb', line 56 def destroy if @policy.destroy process_success else process_error :object => @policy end end |
#disassociate_multiple_hosts ⇒ Object
96 97 |
# File 'app/controllers/policies_controller.rb', line 96 def disassociate_multiple_hosts end |
#edit ⇒ Object
45 46 |
# File 'app/controllers/policies_controller.rb', line 45 def edit end |
#index ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/controllers/policies_controller.rb', line 13 def index @policies = resource_base_search_and_page.search_for(params[:search]) .includes(:scap_content, :scap_content_profile, :tailoring_file, :tailoring_file_profile) if @policies.empty? && ForemanOpenscap::ScapContent.unconfigured? redirect_to scap_contents_path end end |
#model_of_controller ⇒ Object
9 10 11 |
# File 'app/controllers/policies_controller.rb', line 9 def model_of_controller ::ForemanOpenscap::Policy end |
#new ⇒ Object
21 22 23 |
# File 'app/controllers/policies_controller.rb', line 21 def new @policy = ::ForemanOpenscap::Policy.new(:wizard_initiated => true) end |
#parse ⇒ Object
28 29 30 |
# File 'app/controllers/policies_controller.rb', line 28 def parse self.response_body = @policy.to_html end |
#remove_policy_from_multiple_hosts ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/policies_controller.rb', line 99 def remove_policy_from_multiple_hosts if (id = params.fetch(:policy, {})[:id]) policy = ::ForemanOpenscap::Policy.find(id) policy.unassign_hosts(@hosts) success _("Updated hosts: Unassigned from compliance policy '%s'") % policy.name else error _('No valid policy ID provided') end redirect_to hosts_path end |
#scap_content_selected ⇒ Object
64 65 66 67 68 69 |
# File 'app/controllers/policies_controller.rb', line 64 def scap_content_selected if params[:scap_content_id] && (@scap_content = ::ForemanOpenscap::ScapContent.find(params[:scap_content_id])) @policy ||= ::ForemanOpenscap::Policy.new render :partial => 'scap_content_results', :locals => { :policy => @policy } end end |
#select_multiple_hosts ⇒ Object
76 77 |
# File 'app/controllers/policies_controller.rb', line 76 def select_multiple_hosts end |
#show ⇒ Object
25 26 |
# File 'app/controllers/policies_controller.rb', line 25 def show end |
#tailoring_file_selected ⇒ Object
71 72 73 74 |
# File 'app/controllers/policies_controller.rb', line 71 def tailoring_file_selected @policy ||= ::ForemanOpenscap::Policy.new render :partial => 'tailoring_file_selected', :locals => { :policy => @policy, :tailoring_file => @tailoring_file } end |
#update ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/policies_controller.rb', line 48 def update if @policy.change_deploy_type(policy_params) process_success :success_redirect => policies_path else process_error :object => @policy end end |
#update_multiple_hosts ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/policies_controller.rb', line 79 def update_multiple_hosts if (id = params['policy']['id']) policy = ::ForemanOpenscap::Policy.find(id) policy.host_ids = policy.host_ids + @hosts.pluck(:id) if policy.save success _("Updated hosts: Assigned with compliance policy: %s") % policy.name # We prefer to go back as this does not lose the current search return redirect_to hosts_path else return process_error :object => policy, :redirect => hosts_path end else error _('No compliance policy selected.') redirect_to(select_multiple_hosts_policies_path) end end |