Module: ForemanProxmox::HostsHelperExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb

Instance Method Summary collapse

Instance Method Details

#display_proxmox_if_authorized(name, options = {}, html_options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb', line 29

def display_proxmox_if_authorized(name, options = {}, html_options = {})
  if is_authorized(options)
    link_to(name, proxmox_url(options), html_options)
  else
    ""
  end
end

#host_title_actions_with_proxmox(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb', line 11

def host_title_actions_with_proxmox(*args)
  title_actions(
      if Virtualmachine.where("host_id = '#{@host.id}'").first != nil
      button_group(
          display_proxmox_if_authorized(_("VM details"), {:controller => 'foreman_proxmox/virtualmachines', :action => 'show', :id => @host.id}, :class => 'btn')
      )
      end,
        button_group(
          select_action_button(_('Power Control'),{},
          display_proxmox_if_authorized(_('Start VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'start_vm', :id => @host.id}, :class => 'btn'),
          display_proxmox_if_authorized(_('Stop VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'stop_vm', :id => @host.id}, :class => 'btn'),
          display_proxmox_if_authorized(_('Reboot VM'), {:controller => 'foreman_proxmox/virtualmachines', :action => 'reboot_vm', :id => @host.id}, :class => 'btn')
          )
        )
  )
  host_title_actions_without_proxmox(*args)
end

#is_authorized(options) ⇒ Object



41
42
43
# File 'app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb', line 41

def is_authorized(options)
  User.current.allowed_to?(options)
end

#proxmox_url(options) ⇒ Object



37
38
39
# File 'app/helpers/concerns/foreman_proxmox/hosts_helper_extensions.rb', line 37

def proxmox_url(options)
  ForemanProxmox::Engine.routes.url_for(options.merge(:only_path => true, :script_name => foreman_proxmox_path))
end