katello 3.18.0.rc1 → 3.18.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of katello might be problematic. Click here for more details.

Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/katello/api/v2/content_view_filters_controller.rb +17 -8
  3. data/app/controllers/katello/api/v2/content_view_versions_controller.rb +5 -2
  4. data/app/controllers/katello/api/v2/content_views_controller.rb +10 -1
  5. data/app/controllers/katello/api/v2/host_debs_controller.rb +1 -0
  6. data/app/controllers/katello/api/v2/host_errata_controller.rb +2 -2
  7. data/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb +18 -6
  8. data/app/controllers/katello/api/v2/products_bulk_actions_controller.rb +1 -1
  9. data/app/controllers/katello/api/v2/products_controller.rb +9 -9
  10. data/app/controllers/katello/api/v2/repository_sets_controller.rb +24 -14
  11. data/app/controllers/katello/concerns/api/v2/authorization.rb +10 -0
  12. data/app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb +22 -18
  13. data/app/controllers/katello/concerns/registration_controller_extensions.rb +16 -0
  14. data/app/lib/actions/helpers/smart_proxy_sync_history_helper.rb +24 -0
  15. data/app/lib/actions/katello/capsule_content/sync_capsule.rb +16 -7
  16. data/app/lib/actions/katello/content_view/publish.rb +5 -4
  17. data/app/lib/actions/katello/content_view_version/import.rb +3 -10
  18. data/app/lib/actions/katello/host/upload_package_profile.rb +3 -1
  19. data/app/lib/actions/katello/host/upload_profiles.rb +8 -6
  20. data/app/lib/actions/katello/repository/import_upload.rb +2 -0
  21. data/app/lib/actions/katello/repository/remove_content.rb +1 -1
  22. data/app/lib/actions/katello/repository/sync.rb +3 -1
  23. data/app/lib/actions/katello/repository/update.rb +1 -0
  24. data/app/lib/actions/katello/repository/upload_files.rb +1 -0
  25. data/app/lib/actions/middleware/record_smart_proxy_sync_history.rb +15 -0
  26. data/app/lib/actions/pulp/consumer/sync_capsule.rb +4 -2
  27. data/app/lib/actions/pulp/repository/distributor_publish.rb +1 -1
  28. data/app/lib/actions/pulp3/abstract_async_task.rb +1 -0
  29. data/app/lib/actions/pulp3/capsule_content/sync.rb +1 -0
  30. data/app/lib/actions/pulp3/content_view_version/export.rb +5 -1
  31. data/app/lib/actions/pulp3/orchestration/content_view_version/export.rb +23 -6
  32. data/app/lib/actions/pulp3/orchestration/repository/generate_metadata.rb +4 -1
  33. data/app/models/katello/authorization/content_view_filter.rb +15 -0
  34. data/app/models/katello/concerns/smart_proxy_extensions.rb +2 -0
  35. data/app/models/katello/content_view.rb +25 -4
  36. data/app/models/katello/content_view_filter.rb +5 -0
  37. data/app/models/katello/content_view_puppet_module.rb +8 -0
  38. data/app/models/katello/content_view_repository.rb +13 -1
  39. data/app/models/katello/ping.rb +8 -3
  40. data/app/models/katello/repository.rb +26 -0
  41. data/app/models/katello/smart_proxy_sync_history.rb +8 -0
  42. data/app/services/katello/pulp3/content_view_version/export.rb +64 -6
  43. data/app/services/katello/pulp3/content_view_version/import.rb +2 -27
  44. data/app/services/katello/pulp3/content_view_version/import_export_common.rb +6 -0
  45. data/app/services/katello/pulp3/content_view_version/import_validator.rb +107 -0
  46. data/app/services/katello/pulp3/migration.rb +7 -1
  47. data/app/services/katello/pulp3/repository/yum.rb +1 -2
  48. data/app/services/katello/pulp3/task.rb +3 -3
  49. data/app/services/katello/pulp3/task_group.rb +6 -0
  50. data/app/services/katello/repository_type.rb +2 -1
  51. data/app/services/katello/smart_proxy_helper.rb +9 -0
  52. data/app/views/foreman/hosts/_registration.html.erb +12 -0
  53. data/app/views/katello/api/v2/content_views/base.json.rabl +1 -0
  54. data/db/migrate/20200929200357_create_katello_smart_proxy_sync_history.rb +13 -0
  55. data/db/migrate/20201021150008_add_import_only_to_katello_content_view.rb +5 -0
  56. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.controller.js +6 -2
  57. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/content-view-details.controller.js +12 -0
  58. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-details.html +7 -7
  59. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-info.html +7 -1
  60. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/new/content-view-new.controller.js +17 -3
  61. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/new/views/content-view-new.html +16 -2
  62. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/views/content-views.html +5 -0
  63. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/repository-types.service.js +8 -1
  64. data/lib/katello/engine.rb +1 -0
  65. data/lib/katello/permission_creator.rb +11 -11
  66. data/lib/katello/plugin.rb +6 -1
  67. data/lib/katello/tasks/pulp3_migration_abort.rake +17 -0
  68. data/lib/katello/version.rb +1 -1
  69. data/webpack/scenes/Subscriptions/Manifest/ManageManifestModal.js +13 -11
  70. data/webpack/test-utils/react-testing-lib-wrapper.js +3 -0
  71. metadata +12 -3
  72. data/webpack/__mocks__/foremanReact/components/common/Fill/GlobalFill.js +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7163fd6dce0ae11188b016225be2effa59131c5bcc4a4b3482a749dfba7ef545
4
- data.tar.gz: 202f81621e52adce6d318faa95fa9a527c0e3fc0f25bab3c3cb2ca7133cb12e3
3
+ metadata.gz: 31984263518369ed740c74cc962e0a3726d173f56f39beeff760737391520ba5
4
+ data.tar.gz: 87110c33c153b8dbb60062382e4afbe36e72ce826b4655fc64bdce3adf639e2f
5
5
  SHA512:
6
- metadata.gz: 29f15645418ab0683328f83b804dc3fdf45d7f93ce4d23578a558310e0f1ad3cb7f2d98fe74ba3d16181505df56f081092aacb2bb028364995ac15413674862a
7
- data.tar.gz: 99b0a150d0d689951d63b2acb37a0bbab702bfb5a13739572e764f9b49eeda60bb3451b6cc6a7aae4c20886755b499637213afef91eb565a92e2c887a4dcc376
6
+ metadata.gz: e34e20b1885f1e552101ed27f9a002844ef460213fe6f0b57efb507bae174a84fd1dc04c6b9bd9caac5af2a81c88e60dddd7e135c236e5f8a4bd3b022620596c
7
+ data.tar.gz: f33c6fd1f711801f238631c3eda95c5d3c2c2305b5f1a6c4de8c15226d5c6cf717e2827a5552723b2d84edf427ee890c7c933c4d8d632686b5e68a2ba5dba230
@@ -2,9 +2,9 @@ module Katello
2
2
  class Api::V2::ContentViewFiltersController < Api::V2::ApiController
3
3
  include Katello::Concerns::FilteredAutoCompleteSearch
4
4
 
5
- before_action :find_content_view
5
+ before_action :find_editable_content_view, :only => [:create, :update, :destroy]
6
+ before_action :find_readable_content_view, :only => [:show, :index, :auto_complete_search]
6
7
  before_action :find_filter, :except => [:index, :create, :auto_complete_search]
7
-
8
8
  wrap_parameters :include => (ContentViewFilter.attribute_names + %w(repository_ids))
9
9
 
10
10
  api :get, "/content_views/:content_view_id/filters", N_("list filters")
@@ -73,7 +73,7 @@ module Katello
73
73
  respond :resource => @filter
74
74
  end
75
75
 
76
- api :delete, "/content_views/:content_view_id/filters/:id", N_("delete a filter")
76
+ api :delefind_filterte, "/content_views/:content_view_id/filters/:id", N_("delete a filter")
77
77
  api :delete, "/content_view_filters/:id", N_("delete a filter")
78
78
  param :content_view_id, :number, :desc => N_("content view identifier")
79
79
  param :id, :number, :desc => N_("filter identifier"), :required => true
@@ -84,18 +84,27 @@ module Katello
84
84
 
85
85
  private
86
86
 
87
- def find_content_view
88
- @view = ContentView.find(params[:content_view_id]) if params[:content_view_id]
87
+ def find_readable_content_view
88
+ @view = ContentView.readable.find_by(id: params[:content_view_id]) if params[:content_view_id]
89
+ throw_resource_not_found(name: 'content view', id: params[:content_view_id]) if params[:content_view_id] && @view.nil?
90
+ end
91
+
92
+ def find_editable_content_view
93
+ @view = ContentView.editable.find_by(id: params[:content_view_id]) if params[:content_view_id]
94
+ throw_resource_not_found(name: 'content view', id: params[:content_view_id]) if params[:content_view_id] && @view.nil?
89
95
  end
90
96
 
91
97
  def find_filter
92
98
  if @view
93
99
  @filter = @view.filters.find_by(:id => params[:id])
94
- fail HttpErrors::NotFound, _("Couldn't find ContentViewFilter with id=%s") % params[:id] unless @filter
100
+ elsif params[:action] == 'show'
101
+ @filter = ContentViewFilter.readable.find_by(id: params[:id])
102
+ @view = @filter&.content_view
95
103
  else
96
- @filter = ContentViewFilter.find(params[:id])
97
- @view = @filter.content_view
104
+ @filter = ContentViewFilter.editable.find_by(id: params[:id])
105
+ @view = @filter&.content_view
98
106
  end
107
+ fail HttpErrors::NotFound, _("Couldn't find ContentViewFilter with id=%s") % params[:id] unless @filter
99
108
  end
100
109
 
101
110
  def filter_params
@@ -127,7 +127,7 @@ module Katello
127
127
  param :path, String, :desc => N_("Directory containing the exported Content View Version"), :required => true
128
128
  param :metadata, Hash, :desc => N_("Metadata taken from the upstream export history for this Content View Version"), :required => true
129
129
  def import
130
- task = async_task(::Actions::Katello::ContentViewVersion::Import, @view, path: params[:path], metadata: metadata_params)
130
+ task = async_task(::Actions::Katello::ContentViewVersion::Import, @view, path: params[:path], metadata: metadata_params&.to_h)
131
131
  respond_for_async :resource => task
132
132
  end
133
133
 
@@ -355,8 +355,11 @@ module Katello
355
355
  fail HttpErrors::BadRequest, _("Destination Server Name required for Pulp3 repositories")
356
356
  end
357
357
 
358
+ history = ::Katello::ContentViewVersionExportHistory.find(params[:from_history_id]) unless params[:from_history_id].blank?
359
+
358
360
  async_task(::Actions::Pulp3::Orchestration::ContentViewVersion::Export, @version, destination_server: params[:destination_server],
359
- chunk_size: params[:chunk_size_mb])
361
+ chunk_size: params[:chunk_size_mb],
362
+ from_history: history)
360
363
  end
361
364
 
362
365
  def metadata_params
@@ -21,6 +21,7 @@ module Katello
21
21
  param :component_ids, Array, :desc => N_("List of component content view version ids for composite views")
22
22
  param :auto_publish, :bool, :desc => N_("Enable/Disable auto publish of composite view")
23
23
  param :solve_dependencies, :bool, :desc => N_("Solve RPM dependencies by default on Content View publish, defaults to false")
24
+ param :import_only, :bool, :desc => N_("Designate this Content View for importing from upstream servers only. Defaults to false") if pulp3_yum?
24
25
  end
25
26
 
26
27
  def filtered_associations
@@ -30,6 +31,10 @@ module Katello
30
31
  }
31
32
  end
32
33
 
34
+ def self.pulp3_yum?
35
+ SmartProxy.pulp_primary&.pulp3_repository_type_support?(Katello::Repository::YUM_TYPE)
36
+ end
37
+
33
38
  api :GET, "/organizations/:organization_id/content_views", N_("List content views")
34
39
  api :GET, "/content_views", N_("List content views")
35
40
  param :organization_id, :number, :desc => N_("organization identifier")
@@ -67,6 +72,10 @@ module Katello
67
72
  param :composite, :bool, :desc => N_("Composite content view")
68
73
  param_group :content_view
69
74
  def create
75
+ if ::Foreman::Cast.to_bool(params[:content_view][:import_only])
76
+ fail HttpErrors::BadRequest, _("Import-only content views will be available in a future version.") unless self.class.pulp3_yum?
77
+ end
78
+
70
79
  @content_view = ContentView.create!(view_params) do |view|
71
80
  view.organization = @organization
72
81
  view.label ||= labelize_params(params[:content_view])
@@ -237,7 +246,7 @@ module Katello
237
246
  end
238
247
 
239
248
  def view_params
240
- attrs = [:name, :description, :force_puppet_environment, :auto_publish, :solve_dependencies,
249
+ attrs = [:name, :description, :force_puppet_environment, :auto_publish, :solve_dependencies, :import_only,
241
250
  :default, :created_at, :updated_at, :next_version, {:component_ids => []}]
242
251
  attrs.push(:label, :composite) if action_name == "create"
243
252
  if (!@content_view || !@content_view.composite?)
@@ -29,6 +29,7 @@ module Katello
29
29
 
30
30
  def find_host
31
31
  @host = resource_finder(::Host::Managed.authorized(:view_hosts, ::Host::Managed), params[:host_id])
32
+ throw_resource_not_found(name: 'host', id: params[:host_id]) if @host.nil?
32
33
  end
33
34
  end
34
35
  end
@@ -125,13 +125,13 @@ module Katello
125
125
 
126
126
  def find_host
127
127
  @host = resource_finder(::Host::Managed.authorized("view_hosts"), params[:host_id])
128
- fail HttpErrors::NotFound, _("Couldn't find host '%s'") % params[:host_id] if @host.nil?
128
+ throw_resource_not_found(name: 'host', id: params[:host_id]) if @host.nil?
129
129
  @host
130
130
  end
131
131
 
132
132
  def find_host_editable
133
133
  @host = resource_finder(::Host::Managed.authorized("edit_hosts"), params[:host_id])
134
- fail HttpErrors::NotFound, _("Couldn't find host '%s'") % params[:host_id] if @host.nil?
134
+ throw_resource_not_found(name: 'host', id: params[:host_id]) if @host.nil?
135
135
  @host
136
136
  end
137
137
 
@@ -7,11 +7,12 @@ module Katello
7
7
  before_action :find_host_collections, :only => [:bulk_add_host_collections, :bulk_remove_host_collections]
8
8
  before_action :find_environment, :only => [:environment_content_view]
9
9
  before_action :find_content_view, :only => [:environment_content_view]
10
- before_action :find_editable_hosts, :except => [:destroy_hosts, :applicable_errata, :installable_errata, :resolve_traces]
10
+ before_action :find_editable_hosts, :except => [:destroy_hosts, :resolve_traces]
11
11
  before_action :find_deletable_hosts, :only => [:destroy_hosts]
12
12
  before_action :find_readable_hosts, :only => [:applicable_errata, :installable_errata, :available_incremental_updates]
13
13
  before_action :find_errata, :only => [:available_incremental_updates]
14
14
  before_action :find_organization, :only => [:add_subscriptions]
15
+ before_action :find_traces, :only => [:resolve_traces]
15
16
  before_action :deprecate_katello_agent, :only => [:install_content, :update_content, :remove_content]
16
17
 
17
18
  before_action :validate_content_action, :only => [:install_content, :update_content, :remove_content]
@@ -241,8 +242,7 @@ module Katello
241
242
  param_group :bulk_params
242
243
  param :trace_ids, Array, :required => true, :desc => N_("Array of Trace IDs")
243
244
  def resolve_traces
244
- traces = Katello::HostTracer.resolvable.where(id: params[:trace_ids])
245
- result = Katello::HostTraceManager.resolve_traces(traces)
245
+ result = Katello::HostTraceManager.resolve_traces(@traces)
246
246
 
247
247
  render json: result
248
248
  end
@@ -314,7 +314,9 @@ module Katello
314
314
  end
315
315
 
316
316
  def find_host_collections
317
- @host_collections = HostCollection.where(:id => params[:host_collection_ids])
317
+ throw_resources_not_found(name: 'host collection', expected_ids: params[:host_collection_ids]) do
318
+ @host_collections = HostCollection.editable.where(id: params[:host_collection_ids])
319
+ end
318
320
  end
319
321
 
320
322
  def find_readable_hosts
@@ -377,11 +379,21 @@ module Katello
377
379
  end
378
380
 
379
381
  def find_environment
380
- @environment = KTEnvironment.find(params[:environment_id])
382
+ @environment = KTEnvironment.editable.find(params[:environment_id])
383
+ throw_resource_not_found(name: 'lifecycle environment', id: params[:environment_id]) unless @environment
384
+ @environment
381
385
  end
382
386
 
383
387
  def find_content_view
384
- @view = ContentView.find(params[:content_view_id])
388
+ @view = ContentView.editable.find(params[:content_view_id])
389
+ throw_resource_not_found(name: 'content view', id: params[:content_view_id]) unless @view
390
+ @view
391
+ end
392
+
393
+ def find_traces
394
+ throw_resources_not_found(name: 'host trace', expected_ids: params[:trace_ids]) do
395
+ @traces = Katello::HostTracer.resolvable.where(id: params[:trace_ids])
396
+ end
385
397
  end
386
398
 
387
399
  def disable_erratum_hosts_count
@@ -107,7 +107,7 @@ module Katello
107
107
 
108
108
  def find_products
109
109
  params.require(:ids)
110
- @products = Product.where(:id => params[:ids])
110
+ @products = Product.readable.where(:id => params[:ids])
111
111
  end
112
112
  end
113
113
  end
@@ -4,7 +4,7 @@ module Katello
4
4
 
5
5
  before_action :find_activation_key, :only => [:index]
6
6
  before_action :find_organization, :only => [:create, :index, :auto_complete_search]
7
- before_action :find_product, :only => [:update, :destroy, :sync]
7
+ before_action :find_authorized_katello_resource, :only => [:update, :destroy, :sync]
8
8
  before_action :find_organization_from_product, :only => [:update]
9
9
  before_action :authorize_gpg_key, :only => [:update, :create]
10
10
  before_action :authorize_ssl_ca_cert, :only => [:update, :create]
@@ -131,14 +131,14 @@ module Katello
131
131
  protected
132
132
 
133
133
  def find_product(options = {})
134
- @product = Product.includes(options[:includes] || []).find_by(:id => params[:id])
135
- fail HttpErrors::NotFound, _("Couldn't find product '%s'") % params[:id] unless @product
134
+ @product = Product.includes(options[:includes] || []).readable.find_by(:id => params[:id])
135
+ throw_resource_not_found(name: 'product', id: params[:id]) if @product.nil?
136
136
  end
137
137
 
138
138
  def find_activation_key
139
139
  if params[:activation_key_id]
140
- @activation_key = ActivationKey.find_by(:id => params[:activation_key_id])
141
- fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:activation_key_id] if @activation_key.nil?
140
+ @activation_key = ActivationKey.readable.find_by(:id => params[:activation_key_id])
141
+ throw_resource_not_found(name: 'Activation Key', id: params[:activation_key_id]) if @activation_key.nil?
142
142
  @organization = @activation_key.organization
143
143
  end
144
144
  end
@@ -151,7 +151,7 @@ module Katello
151
151
  gpg_key_id = product_params[:gpg_key_id]
152
152
  if gpg_key_id
153
153
  gpg_key = GpgKey.readable.where(:id => gpg_key_id, :organization_id => @organization).first
154
- fail HttpErrors::NotFound, _("Couldn't find gpg key '%s'") % gpg_key_id if gpg_key.nil?
154
+ throw_resource_not_found(name: 'gpg key', id: gpg_key_id) if gpg_key.nil?
155
155
  end
156
156
  end
157
157
 
@@ -159,7 +159,7 @@ module Katello
159
159
  ssl_ca_cert_id = product_params[:ssl_ca_cert_id]
160
160
  if ssl_ca_cert_id
161
161
  ssl_ca_cert = GpgKey.readable.where(:id => ssl_ca_cert_id, :organization_id => @organization).first
162
- fail HttpErrors::NotFound, _("Couldn't find ssl ca cert '%s'") % ssl_ca_cert_id if ssl_ca_cert.nil?
162
+ throw_resource_not_found(name: 'ssl ca cert', id: ssl_ca_cert_id) if ssl_ca_cert.nil?
163
163
  end
164
164
  end
165
165
 
@@ -167,7 +167,7 @@ module Katello
167
167
  ssl_client_cert_id = product_params[:ssl_client_cert_id]
168
168
  if ssl_client_cert_id
169
169
  ssl_client_cert = GpgKey.readable.where(:id => ssl_client_cert_id, :organization_id => @organization).first
170
- fail HttpErrors::NotFound, _("Couldn't find ssl client cert '%s'") % ssl_client_cert_id if ssl_client_cert.nil?
170
+ throw_resource_not_found(name: 'ssl client cert', id: ssl_client_cert_id) if ssl_client_cert.nil?
171
171
  end
172
172
  end
173
173
 
@@ -175,7 +175,7 @@ module Katello
175
175
  ssl_client_key_id = product_params[:ssl_client_key_id]
176
176
  if ssl_client_key_id
177
177
  ssl_client_key = GpgKey.readable.where(:id => ssl_client_key_id, :organization_id => @organization).first
178
- fail HttpErrors::NotFound, _("Couldn't find ssl client key '%s'") % ssl_client_key_id if ssl_client_key.nil?
178
+ throw_resource_not_found(name: 'ssl client key', id: ssl_client_key_id) if ssl_client_key.nil?
179
179
  end
180
180
  end
181
181
 
@@ -4,8 +4,11 @@ module Katello
4
4
 
5
5
  include Katello::Concerns::FilteredAutoCompleteSearch
6
6
 
7
- before_action :find_product_or_organization
7
+ before_action :set_readable_product_scope, only: [:index, :show, :available_repositories, :auto_complete_search]
8
+ before_action :set_editable_product_scope, only: [:enable, :disable]
9
+ before_action :find_product
8
10
  before_action :custom_product?
11
+ before_action :find_organization
9
12
  before_action :find_product_content, :except => [:index, :auto_complete_search]
10
13
 
11
14
  resource_description do
@@ -102,7 +105,8 @@ module Katello
102
105
 
103
106
  def index_relation
104
107
  if @product.nil?
105
- relation = @organization.product_contents.displayable
108
+ authorized_product_contents = Katello::ProductContent.joins(:product).merge(@product_scope)
109
+ relation = @organization.product_contents.merge(authorized_product_contents).displayable
106
110
  else
107
111
  relation = @product.displayable_product_contents
108
112
  end
@@ -125,25 +129,31 @@ module Katello
125
129
  if @product.present?
126
130
  @product_content = @product.product_content_by_id(params[:id])
127
131
  else
128
- content = Katello::Content.find_by(:cp_content_id => params[:id], :organization_id => @organization[:id])
129
- @product_content = Katello::ProductContent.find_by(:content_id => content.id)
132
+ content = Katello::Content.where(cp_content_id: params[:id], organization: @organization)
133
+ authorized_product_contents = Katello::ProductContent.joins(:product).merge(@product_scope)
134
+ @product_content = authorized_product_contents.joins(:content).merge(content).first
135
+ @product = @product_content&.product
130
136
  end
131
- fail HttpErrors::NotFound, _("Couldn't find repository set with id '%s'.") % params[:id] if @product_content.nil?
132
- @product = @product_content.product if @product.nil?
137
+ throw_resource_not_found(name: 'repository set', id: params[:id]) if @product_content.nil?
133
138
  end
134
139
 
135
- def find_product_or_organization
140
+ def find_product
136
141
  if params[:product_id]
137
- find_product
138
- else
139
- @organization = find_organization
142
+ @product = @product_scope.find_by(id: params[:product_id])
143
+ throw_resource_not_found(name: 'product', id: params[:product_id]) if @product.nil?
140
144
  end
141
145
  end
142
146
 
143
- def find_product
144
- @product = Product.find_by(:id => params[:product_id])
145
- fail HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil?
146
- @organization = @product.organization
147
+ def set_readable_product_scope
148
+ @product_scope = Katello::Product.readable
149
+ end
150
+
151
+ def set_editable_product_scope
152
+ @product_scope = Katello::Product.editable
153
+ end
154
+
155
+ def find_organization
156
+ @organization = @product&.organization || super
147
157
  end
148
158
 
149
159
  def custom_product?
@@ -42,6 +42,16 @@ module Katello
42
42
  fail HttpErrors::NotFound, _("Could not find %{name} resource with id %{id}") % {id: id, name: name}
43
43
  end
44
44
 
45
+ def throw_resources_not_found(name:, expected_ids: [])
46
+ resources = yield
47
+ found_ids = resources.map(&:id)
48
+ missing_ids = expected_ids.map(&:to_i) - found_ids
49
+
50
+ if missing_ids.any?
51
+ fail HttpErrors::NotFound, _("Could not find %{name} resources with ids %{ids}") % {ids: missing_ids.join(', '), name: name}
52
+ end
53
+ end
54
+
45
55
  def check_association_ids
46
56
  if filtered_associations
47
57
  wrapped_params = params[self._wrapper_options.name]
@@ -3,37 +3,41 @@ module Katello
3
3
  module Api::V2::BulkHostsExtensions
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ def bulk_hosts_relation(permission, org)
7
+ relation = ::Host::Managed.authorized(permission)
8
+ relation = relation.where(organization: org) if org
9
+ relation
10
+ end
11
+
6
12
  def find_bulk_hosts(permission, bulk_params, restrict_to = nil)
7
13
  #works on a structure of param_group bulk_params and transforms it into a list of systems
8
- find_organization
9
14
  bulk_params[:included] ||= {}
10
15
  bulk_params[:excluded] ||= {}
11
- @hosts = []
12
16
 
13
- unless bulk_params[:included][:ids].blank?
14
- @hosts = ::Host::Managed.authorized(permission).where(:id => bulk_params[:included][:ids])
15
- @hosts = @hosts.where(:organization_id => @organization.id) if @organization
17
+ if bulk_params[:included][:ids].blank? && bulk_params[:included][:search].nil?
18
+ fail HttpErrors::BadRequest, _("No hosts have been specified.")
19
+ end
20
+
21
+ find_organization
22
+ @hosts = bulk_hosts_relation(permission, @organization)
23
+
24
+ if bulk_params[:included][:ids].present?
25
+ @hosts = @hosts.where(id: bulk_params[:included][:ids])
16
26
  end
17
27
 
18
28
  if bulk_params[:included][:search]
19
- search_hosts = ::Host::Managed.authorized(permission)
20
- search_hosts = search_hosts.where(:organization_id => @organization.id) if @organization
21
- search_hosts = search_hosts.search_for(bulk_params[:included][:search])
22
- if @hosts.any?
23
- @hosts = ::Host.where(id: @hosts).or(::Host.where(id: search_hosts))
24
- else
25
- @hosts = search_hosts
26
- end
29
+ search_hosts = bulk_hosts_relation(permission, @organization).search_for(bulk_params[:included][:search])
30
+ @hosts = @hosts.merge(search_hosts)
27
31
  end
28
32
 
29
33
  @hosts = restrict_to.call(@hosts) if restrict_to
30
- @hosts = @hosts.where.not(id: bulk_params[:excluded][:ids]) unless bulk_params[:excluded][:ids].blank?
31
34
 
32
- if bulk_params[:included][:ids].blank? && bulk_params[:included][:search].nil?
33
- fail HttpErrors::BadRequest, _("No hosts have been specified.")
34
- elsif @hosts.empty?
35
- fail HttpErrors::Forbidden, _("Action unauthorized to be performed on selected hosts.")
35
+ if bulk_params[:excluded][:ids].present?
36
+ @hosts = @hosts.where.not(id: bulk_params[:excluded][:ids])
36
37
  end
38
+
39
+ fail HttpErrors::Forbidden, _("Action unauthorized to be performed on selected hosts.") if @hosts.empty?
40
+
37
41
  @hosts
38
42
  end
39
43
 
@@ -0,0 +1,16 @@
1
+ module Katello
2
+ module Concerns
3
+ module RegistrationControllerExtensions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :format_activation_key, only: [:create]
8
+ end
9
+
10
+ def format_activation_key
11
+ return if params[:activation_key].blank?
12
+ params[:activation_key] = params[:activation_key].split(',').map(&:strip).reject(&:blank?).join(',')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module Actions
2
+ module Helpers
3
+ module SmartProxySyncHistoryHelper
4
+ def self.included(base)
5
+ base.middleware.use ::Actions::Middleware::RecordSmartProxySyncHistory
6
+ end
7
+
8
+ def done?
9
+ is_done = super
10
+ if is_done
11
+ ::Katello::SmartProxySyncHistory.where(:id => output[:smart_proxy_history_id], :finished_at => nil).update_all(finished_at: Time.now)
12
+ end
13
+ is_done
14
+ end
15
+
16
+ def rescue_external_task(error)
17
+ if output[:smart_proxy_history_id]
18
+ ::Katello::SmartProxySyncHistory.where(:id => output[:smart_proxy_history_id], :finished_at => nil).delete_all
19
+ end
20
+ super
21
+ end
22
+ end
23
+ end
24
+ end