Class: Katello::Api::V2::HostCollectionsController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#full_result_response, #resource_class, #scoped_search
Methods included from Rendering
#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template
#api_version
Instance Method Details
#add_hosts ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 87
def add_hosts
@hosts = ::Host::Managed.authorized(:edit_host).where(:id => params[:host_ids])
@editable_hosts = @hosts.authorized(:edit_host)
@host_collection.host_ids = (@host_collection.host_ids + @editable_hosts.collect { |s| s.id }).uniq
@host_collection.save!
messages = format_bulk_action_messages(
:success => _("Successfully added %s Host(s)."),
:error => _("You were not allowed to add %s"),
:models => @hosts,
:authorized => @editable_hosts
)
respond_for_show :template => 'bulk_action', :resource_name => 'common',
:resource => { 'displayMessages' => messages }
end
|
#copy ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 134
def copy
new_host_collection = HostCollection.new
new_host_collection.name = params[:host_collection][:name]
new_host_collection.organization = @host_collection.organization
new_host_collection.description = @host_collection.description
new_host_collection.max_hosts = @host_collection.max_hosts
new_host_collection.unlimited_hosts = @host_collection.unlimited_hosts
new_host_collection.hosts = @host_collection.hosts
new_host_collection.save!
respond_for_create :resource => new_host_collection
end
|
#create ⇒ Object
68
69
70
71
72
73
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 68
def create
@host_collection = HostCollection.new(host_collection_params_with_host_ids)
@host_collection.organization = @organization
@host_collection.save!
respond_for_show(:resource => @host_collection)
end
|
#destroy ⇒ Object
126
127
128
129
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 126
def destroy
@host_collection.destroy
respond_for_destroy
end
|
#index ⇒ Object
37
38
39
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 37
def index
respond(:collection => scoped_search(index_relation.uniq, :name, :desc))
end
|
#index_relation ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 41
def index_relation
if @host
query = @host.host_collections
if params[:available_for] == "host"
query = Katello::HostCollection.readable.where(:organization_id => @organization.id)
if @host.host_collections.count > 0
query = query.where("#{Katello::HostCollection.table_name}.id NOT IN (?)", @host.host_collection_ids)
end
end
elsif @activation_key
query = @activation_key.host_collections
elsif @organization
query = HostCollection.readable.where(:organization_id => @organization.id)
else
query = HostCollection.readable
end
query = query.where(:name => params[:name]) if params[:name]
query
end
|
#remove_hosts ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 107
def remove_hosts
@hosts = ::Host::Managed.authorized(:edit_host).where(:id => params[:host_ids])
@editable_hosts = @hosts.authorized(:edit_host)
@host_collection.host_ids = (@host_collection.host_ids - @editable_hosts.collect { |s| s.id }).uniq
@host_collection.save!
messages = format_bulk_action_messages(
:success => _("Successfully removed %s Host(s)."),
:error => _("You were not allowed to sync %s"),
:models => @hosts,
:authorized => @editable_hosts
)
respond_for_show :template => 'bulk_action', :resource_name => 'common',
:resource => { 'displayMessages' => messages }
end
|
#show ⇒ Object
22
23
24
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 22
def show
respond
end
|
#update ⇒ Object
79
80
81
82
|
# File 'app/controllers/katello/api/v2/host_collections_controller.rb', line 79
def update
@host_collection.update_attributes!(host_collection_params_with_host_ids)
respond
end
|