Class: Katello::Api::V2::ContentViewsController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#empty_search_query?, #full_result_response, #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
200
201
202
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 200
def bulk_delete_versions
if @content_view.rolling?
fail HttpErrors::BadRequest, _("It's not possible to bulk remove versions from a rolling content view.")
end
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
254
255
256
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 247
def copy
@content_view = Katello::ContentView.readable.find_by(:id => params[:id])
if @content_view.rolling?
fail HttpErrors::BadRequest, _("It's not possible to copy a rolling content view.")
end
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
91
92
93
94
95
96
97
98
99
100
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 91
def create
validate_environment_ids!(params[:rolling])
@content_view = ContentView.create!(view_params) do |view|
view.organization = @organization
view.label ||= labelize_params(params[:content_view])
end
sync_task(::Actions::Katello::ContentView::Create, @content_view, sanitized_environment_ids)
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
#index ⇒ Object
63
64
65
66
67
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 63
def index
content_view_includes = [:activation_keys, :content_view_versions, :content_view_components,
:environments, :organization, :repositories]
respond(:collection => scoped_search(index_relation.distinct, :name, :asc, :includes => content_view_includes))
end
|
#index_relation ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 69
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
124
125
126
127
128
129
130
131
132
133
134
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 124
def publish
validate_publish_params!
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
164
165
166
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
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 164
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
145
146
147
148
149
150
151
152
153
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 145
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
138
139
140
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 138
def show
respond :resource => @content_view
end
|
#update ⇒ Object
106
107
108
109
110
|
# File 'app/controllers/katello/api/v2/content_views_controller.rb', line 106
def update
validate_environment_ids!(@content_view.rolling?)
sync_task(::Actions::Katello::ContentView::Update, @content_view, view_params, sanitized_environment_ids)
respond :resource => @content_view.reload
end
|