Module: PoliciesHelper

Defined in:
app/helpers/policies_helper.rb

Instance Method Summary collapse

Instance Method Details

#config_inline_help(help_hash) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/policies_helper.rb', line 32

def config_inline_help(help_hash)
  link = if help_hash[:route_helper_method] && respond_to?(help_hash[:route_helper_method])
           link_to_if_authorized help_hash[:replace_text], public_send(help_hash[:route_helper_method])
         else
           help_hash[:replace_text]
         end
  text = help_hash[:text]
  text = text.split(help_hash[:replace_text], 2).join(link) if help_hash.key?(:replace_text)
  text.html_safe
end

#days_of_week_hashObject



132
133
134
# File 'app/helpers/policies_helper.rb', line 132

def days_of_week_hash
  Hash[*Date::DAYNAMES.map { |day| [day.downcase, day] }.flatten]
end

#deploy_by_radio_checked(policy, tool) ⇒ Object



43
44
45
46
# File 'app/helpers/policies_helper.rb', line 43

def deploy_by_radio_checked(policy, tool)
  type = policy.deploy_by ? policy.deploy_by.to_sym : :puppet
  tool.type == type
end

#deploy_by_radios(f, policy) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/policies_helper.rb', line 12

def deploy_by_radios(f, policy)
  ForemanOpenscap::ConfigNameService.new.configs.map do |tool|
    popover_block = popover("", config_inline_help(tool.inline_help))

    label = label_tag('', :class => 'col-md-2 control-label') do
      tool.type.to_s.capitalize.html_safe + ' ' + popover_block.html_safe
    end

    radio = (:div, :class => "col-md-2") do
      f.radio_button(:deploy_by, tool.type, :disabled => !tool.available?, :checked => deploy_by_radio_checked(policy, tool))
    end

    (:div, :class => "clearfix") do
      (:div, :class => "form-group") do
        label.html_safe + radio.html_safe
      end
    end
  end.join('').html_safe
end

#effective_policy_profile(policy) ⇒ Object



48
49
50
# File 'app/helpers/policies_helper.rb', line 48

def effective_policy_profile(policy)
  policy.tailoring_file ? policy.tailoring_file_profile.title : policy_profile_from_scap_content(policy)
end

#policy_breadcrumbsObject



140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/helpers/policies_helper.rb', line 140

def policy_breadcrumbs
  if @policy
    breadcrumbs(:resource_url => api_compliance_policies_path,
                :name_field => 'name',
                :items => [
                  { :caption => _('Policies'),
                    :url => url_for(policies_path) },
                  { :caption => @policy.name,
                    :url => (edit_policy_path(@policy) if authorized_for(hash_for_edit_policy_path(@policy))) }
                ])
  end
end

#policy_profile_from_scap_content(policy) ⇒ Object



8
9
10
# File 'app/helpers/policies_helper.rb', line 8

def policy_profile_from_scap_content(policy)
  policy.scap_content_profile.nil? ? "Default" : policy.scap_content_profile.title
end


125
126
127
128
129
130
# File 'app/helpers/policies_helper.rb', line 125

def previous_link(form)
  previous = (:span, "", :class => 'glyphicon glyphicon-chevron-left')
  (:div, :class => 'pull-left') do
    link_to(previous.html_safe, '#', :class => 'btn btn-default', :onclick => "previous_step('#{@policy.previous_step}')")
  end
end

#profiles_selectionObject



2
3
4
5
6
# File 'app/helpers/policies_helper.rb', line 2

def profiles_selection
  return @scap_content.scap_content_profiles if @scap_content.present?
  return @policy.scap_content.scap_content_profiles if @policy.scap_content.present?
  return []
end

#scap_content_profile_selector(form) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/policies_helper.rb', line 68

def scap_content_profile_selector(form)
  if profiles_selection.length == 1
    select_f form, :scap_content_profile_id, profiles_selection, :id, :title,
             { :selected => @policy.scap_content_profile_id },
             { :label => _("XCCDF Profile"),
               :disabled => profiles_selection.empty? ? true : false,
               :help_inline => :indicator }
  else
    select_f form, :scap_content_profile_id, profiles_selection, :id, :title,
             { :selected => @policy.scap_content_profile_id,
               :include_blank => _("Default XCCDF profile") },
             { :label => _("XCCDF Profile"),
               :disabled => profiles_selection.empty? ? true : false,
               :help_inline => :indicator }
  end
end

#scap_content_selector(form) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/policies_helper.rb', line 52

def scap_content_selector(form)
  scap_contents = ::ForemanOpenscap::ScapContent.authorized(:view_scap_contents).all
  if scap_contents.length > 1
    select_f form, :scap_content_id, scap_contents, :id, :title,
             { :include_blank => _("Choose existing SCAP Content") },
             { :label => _("SCAP Content"),
               :onchange => 'scap_content_selected(this);',
               :'data-url' => method_path('scap_content_selected') }
  else
    select_f form, :scap_content_id, scap_contents, :id, :title,
             { :label => _("SCAP Content"),
               :onchange => 'scap_content_selected(this);',
               :'data-url' => method_path('scap_content_selected') }
  end
end

#show_partial_wizard(step) ⇒ Object



121
122
123
# File 'app/helpers/policies_helper.rb', line 121

def show_partial_wizard(step)
  @policy.current_step == step ? 'show-pane' : 'hide-pane'
end

#submit_or_cancel_policy(form, overwrite = nil, args = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/helpers/policies_helper.rb', line 105

def submit_or_cancel_policy(form, overwrite = nil, args = {})
  args[:cancel_path] ||= send("#{controller_name}_path")
  (:div, :class => "clearfix") do
    (:div, :class => "form-actions") do
      text    = overwrite ? overwrite : _("Submit")
      options = { :class => "btn btn-primary" }
      previous = form.object.first_step? ? ' ' : previous_link(form)
      cancel_and_submit = (:div, :class => "pull-right") do
        link_to(_("Cancel"), args[:cancel_path], :class => "btn btn-default") + ' ' +
            form.submit(text, options)
      end
      (previous + cancel_and_submit).html_safe
    end
  end
end

#tailoring_file_profile_selector(form, tailoring_file) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/policies_helper.rb', line 93

def tailoring_file_profile_selector(form, tailoring_file)
  if tailoring_file
    select_f form, :tailoring_file_profile_id, tailoring_file.scap_content_profiles, :id, :title,
             { :selected => tailoring_file.scap_content_profiles.first.id },
             { :label => _("XCCDF Profile in Tailoring File"),
               :help_inline => _("This profile will be used to override the one from scap content") }
  else
    # to make sure tailoring profile id is nil when tailoring file is deselected
    form.hidden_field(:tailoring_file_profile_id, :value => nil)
  end
end

#tailoring_file_selector(form) ⇒ Object



85
86
87
88
89
90
91
# File 'app/helpers/policies_helper.rb', line 85

def tailoring_file_selector(form)
  select_f form, :tailoring_file_id, ForemanOpenscap::TailoringFile.all.authorized(:view_tailoring_files), :id, :name,
           { :include_blank => _('Choose Tailoring File') },
           { :label => _('Tailoring File'),
             :onchange => 'tailoring_file_selected(this)',
             :'data-url' => method_path('tailoring_file_selected') }
end

#translate_steps(policy) ⇒ Object



136
137
138
# File 'app/helpers/policies_helper.rb', line 136

def translate_steps(policy)
  policy.steps.map { |step| _(step) }
end