Class: HostgroupsController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::HostDetails
Defined in:
app/controllers/hostgroups_controller.rb

Instance Method Summary collapse

Methods included from Foreman::Controller::AutoCompleteSearch

#auto_complete_search, #invalid_search_query

Methods included from Foreman::Controller::HostDetails

#architecture_selected, #domain_selected, #medium_selected, #os_selected, #use_image_selected

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#cloneObject

Clone the hostgroup


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/hostgroups_controller.rb', line 45

def clone
  new = @hostgroup.dup
  load_vars_for_ajax
  new.puppetclasses = @hostgroup.puppetclasses
  new.locations = @hostgroup.locations
  new.organizations = @hostgroup.organizations
  # Clone any parameters as well
  @hostgroup.group_parameters.each{|param| new.group_parameters << param.dup}
  new.name = ""
  new.valid?
  @hostgroup = new
  notice _("The following fields would need reviewing")
  render :action => :new
end

#createObject


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/hostgroups_controller.rb', line 68

def create
  @hostgroup = Hostgroup.new(params[:hostgroup])
  if @hostgroup.save
    # Add the new hostgroup to the user's filters
    @hostgroup.users << User.current unless User.current.admin? or @hostgroup.users.include?(User.current)
    @hostgroup.users << users_in_ancestors

    process_success
  else
    load_vars_for_ajax
    process_error
  end
end

#destroyObject


99
100
101
102
103
104
105
106
# File 'app/controllers/hostgroups_controller.rb', line 99

def destroy
  if @hostgroup.destroy
    process_success
  else
    load_vars_for_ajax
    process_error
  end
end

#editObject


82
83
84
85
86
# File 'app/controllers/hostgroups_controller.rb', line 82

def edit
  auth  = User.current.admin? ? true : Hostgroup.my_groups.include?(@hostgroup)
  not_found and return unless auth
  load_vars_for_ajax
end

#environment_selectedObject


108
109
110
111
112
113
114
# File 'app/controllers/hostgroups_controller.rb', line 108

def environment_selected
  return not_found unless (@environment = Environment.find(params[:environment_id])) if params[:environment_id].to_i > 0

  @hostgroup ||= Hostgroup.new
  @hostgroup.environment = @environment if @environment
  render :partial => 'puppetclasses/class_selection', :locals => {:obj => (@hostgroup)}
end

#indexObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/hostgroups_controller.rb', line 7

def index
  begin
    my_groups = User.current.admin? ? Hostgroup : Hostgroup.my_groups
    values = my_groups.search_for(params[:search], :order => params[:order])
  rescue => e
    error e.to_s
    values = my_groups.search_for ""
  end

  respond_to do |format|
    format.html do
      @hostgroups = values.paginate :page => params[:page]
    end
    format.json { render :json => values }
  end
end

#nestObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/hostgroups_controller.rb', line 28

def nest
  @parent = Hostgroup.find(params[:id])
  @hostgroup = @parent.dup
  #overwrite parent_id and name
  @hostgroup.parent_id = params[:id]
  @hostgroup.name = ""

  load_vars_for_ajax
  @hostgroup.puppetclasses = @parent.puppetclasses
  @hostgroup.locations = @parent.locations
  @hostgroup.organizations = @parent.organizations
  # Clone any parameters as well
  @hostgroup.group_parameters.each{|param| @parent.group_parameters << param.dup}
  render :action => :new
end

#newObject


24
25
26
# File 'app/controllers/hostgroups_controller.rb', line 24

def new
  @hostgroup = Hostgroup.new
end

#process_hostgroupObject


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/hostgroups_controller.rb', line 116

def process_hostgroup

  @parent = Hostgroup.find(params[:hostgroup][:parent_id]) if params[:hostgroup][:parent_id].to_i > 0
  return head(:not_found) unless @parent

  @hostgroup = Hostgroup.new(params[:hostgroup])
  @hostgroup.architecture       ||= @parent.architecture
  @hostgroup.operatingsystem    ||= @parent.operatingsystem
  @hostgroup.domain             ||= @parent.domain
  @hostgroup.subnet             ||= @parent.subnet
  @hostgroup.environment        ||= @parent.environment

  load_vars_for_ajax
  render :partial => "form"
end

#showObject


60
61
62
63
64
65
66
# File 'app/controllers/hostgroups_controller.rb', line 60

def show
  auth  = User.current.admin? ? true : Hostgroup.my_groups.include?(@hostgroup)
  not_found and return unless auth
  respond_to do |format|
    format.json { render :json => @hostgroup }
  end
end

#taxonomy_scopeObject


132
133
134
135
# File 'app/controllers/hostgroups_controller.rb', line 132

def taxonomy_scope
  @organization = Organization.current if SETTINGS[:organizations_enabled]
  @location     = Location.current     if SETTINGS[:locations_enabled]
end

#updateObject


88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/hostgroups_controller.rb', line 88

def update
  # remove from hash :root_pass if blank?
  params[:hostgroup].except!(:root_pass) if params[:hostgroup][:root_pass].blank?
  if @hostgroup.update_attributes(params[:hostgroup])
    process_success
  else
    load_vars_for_ajax
    process_error
  end
end