Class: Katello::Api::V2::ContentViewsController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #resource_class, #scoped_search, #skip_session
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
#bulk_delete_versions ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 203
def bulk_delete_versions
params[:bulk_content_view_version_ids] ||= {}
versions = find_bulk_items(bulk_params: params[:bulk_content_view_version_ids],
model_scope: ::Katello::ContentViewVersion.where(content_view_id: @content_view.id),
key: :id)
cv_envs = ContentViewEnvironment.where(:content_view_version_id => versions.pluck(:id),
:content_view_id => @content_view.id
)
if !params[:destroy_content_view] && cv_envs.empty? && versions.empty?
fail _("There either were no environments nor versions specified or there were invalid environments/versions specified. "\
"Please check environment_ids and content_view_version_ids parameters.")
end
options = params.slice(:system_content_view_id,
:system_environment_id,
:key_content_view_id,
:key_environment_id
).reject { |_k, v| v.nil? }.to_unsafe_h
options[:content_view_versions] = versions
options[:content_view_environments] = cv_envs
task = async_task(::Actions::Katello::ContentView::Remove, @content_view, options)
respond_for_async :resource => task
end
|
#copy ⇒ Object
247
248
249
250
251
252
253
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 247
def copy
@content_view = Katello::ContentView.readable.find_by(:id => params[:id])
throw_resource_not_found(name: 'content_view', id: params[:id]) if @content_view.blank?
ensure_non_default
new_content_view = @content_view.copy(params[:content_view][:name])
respond_for_create :resource => new_content_view
end
|
#create ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 88
def create
@content_view = ContentView.create!(view_params) do |view|
view.organization = @organization
view.label ||= labelize_params(params[:content_view])
end
respond :resource => @content_view
end
|
#destroy ⇒ Object
239
240
241
242
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 239
def destroy
task = async_task(::Actions::Katello::ContentView::Destroy, @content_view)
respond_for_async :resource => task
end
|
#filtered_associations ⇒ Object
41
42
43
44
45
46
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 41
def filtered_associations
{
:component_ids => Katello::ContentViewVersion,
:repository_ids => Katello::Repository
}
end
|
#index ⇒ Object
61
62
63
64
65
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 61
def index
content_view_includes = [:activation_keys, :content_view_versions,
:environments, :organization, :repositories]
respond(:collection => scoped_search(index_relation.distinct, :name, :asc, :includes => content_view_includes))
end
|
#index_relation ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 67
def index_relation
content_views = ContentView.readable
content_views = content_views.ignore_generated unless Foreman::Cast.to_bool(params[:include_generated])
content_views = content_views.where(:organization_id => @organization.id) if @organization
content_views = content_views.in_environment(@environment) if @environment
content_views = ::Foreman::Cast.to_bool(params[:nondefault]) ? content_views.non_default : content_views.default if params[:nondefault]
content_views = ::Foreman::Cast.to_bool(params[:noncomposite]) ? content_views.non_composite : content_views.composite if params[:noncomposite]
content_views = ::Foreman::Cast.to_bool(params[:composite]) ? content_views.composite : content_views.non_composite if params[:composite]
content_views = content_views.where(:name => params[:name]) if params[:name]
content_views = content_views.where(:label => params[:label]) if params[:label]
content_views = content_views.where("#{ContentView.table_name}.id NOT IN (?)", params[:without]) if params[:without]
content_views
end
|
#publish ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 117
def publish
if params[:repos_units].present? && @content_view.composite?
fail HttpErrors::BadRequest, _("Directly setting package lists on composite content views is not allowed. Please " \
"update the components, then re-publish the composite.")
end
if params[:major].present? && params[:minor].present? && ContentViewVersion.find_by(:content_view_id => params[:id], :major => params[:major], :minor => params[:minor]).present?
fail HttpErrors::BadRequest, _("A CV version already exists with the same major and minor version (%{major}.%{minor})") % {:major => params[:major], :minor => params[:minor]}
end
if params[:major].present? && params[:minor].nil? || params[:major].nil? && params[:minor].present?
fail HttpErrors::BadRequest, _("Both major and minor parameters have to be used to override a CV version")
end
task = async_task(::Actions::Katello::ContentView::Publish, @content_view, params[:description],
:environment_ids => params[:environment_ids],
:is_force_promote => params[:is_force_promote],
:major => params[:major],
:minor => params[:minor],
:repos_units => params[:repos_units])
respond_for_async :resource => task
end
|
#remove ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 167
def remove
if params[:destroy_content_view]
cv_envs = @content_view.content_view_environments
versions = @content_view.versions
else
cv_envs = ContentViewEnvironment.where(:environment_id => params[:environment_ids],
:content_view_id => params[:id]
)
versions = @content_view.versions.where(:id => params[:content_view_version_ids])
end
if !params[:destroy_content_view] && cv_envs.empty? && versions.empty?
fail _("There either were no environments nor versions specified or there were invalid environments/versions specified. "\
"Please check environment_ids and content_view_version_ids parameters.")
end
options = params.slice(:system_content_view_id,
:system_environment_id,
:key_content_view_id,
:key_environment_id,
:destroy_content_view
).reject { |_k, v| v.nil? }.to_unsafe_h
options[:content_view_versions] = versions
options[:content_view_environments] = cv_envs
task = async_task(::Actions::Katello::ContentView::Remove, @content_view, options)
respond_for_async :resource => task
end
|
#remove_filters ⇒ Object
232
233
234
235
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 232
def remove_filters
Katello::ContentViewFilter.where(id: params[:filter_ids]).try(:destroy_all)
respond_for_show(:resource => @content_view)
end
|
#remove_from_environment ⇒ Object
148
149
150
151
152
153
154
155
156
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 148
def remove_from_environment
unless @content_view.environments.include?(@environment)
fail HttpErrors::BadRequest, _("Content view '%{view}' is not in lifecycle environment '%{env}'.") %
{view: @content_view.name, env: @environment.name}
end
task = async_task(::Actions::Katello::ContentView::RemoveFromEnvironment, @content_view, @environment)
respond_for_async :resource => task
end
|
#show ⇒ Object
141
142
143
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 141
def show
respond :resource => @content_view
end
|
#update ⇒ Object
101
102
103
104
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 101
def update
sync_task(::Actions::Katello::ContentView::Update, @content_view, view_params)
respond :resource => @content_view.reload
end
|