katello 3.4.2 → 3.4.4

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb +1 -1
  3. data/app/controllers/katello/api/v2/api_controller.rb +10 -2
  4. data/app/controllers/katello/api/v2/capsule_content_controller.rb +1 -1
  5. data/app/controllers/katello/api/v2/docker_manifests_controller.rb +4 -0
  6. data/app/controllers/katello/api/v2/docker_tags_controller.rb +4 -5
  7. data/app/controllers/katello/api/v2/errata_controller.rb +3 -2
  8. data/app/controllers/katello/api/v2/host_packages_controller.rb +1 -1
  9. data/app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb +2 -2
  10. data/app/controllers/katello/api/v2/repositories_controller.rb +1 -1
  11. data/app/controllers/katello/application_controller.rb +9 -501
  12. data/app/controllers/katello/concerns/api/v2/repository_content_controller.rb +8 -10
  13. data/app/helpers/katello/hosts_and_hostgroups_helper.rb +3 -3
  14. data/app/helpers/katello/layout_helper.rb +2 -0
  15. data/app/lib/actions/candlepin/consumer/update.rb +1 -0
  16. data/app/lib/actions/candlepin/import_pool_handler.rb +1 -1
  17. data/app/lib/actions/katello/capsule_content/remove_unneeded_repos.rb +1 -1
  18. data/app/lib/actions/katello/capsule_content/sync.rb +24 -14
  19. data/app/lib/actions/katello/content_view/capsule_generate_and_sync.rb +5 -4
  20. data/app/lib/actions/katello/content_view/errata_mail.rb +1 -1
  21. data/app/lib/actions/katello/content_view_puppet_environment/create.rb +3 -1
  22. data/app/lib/actions/katello/host/update.rb +18 -10
  23. data/app/lib/actions/katello/host/upload_package_profile.rb +4 -2
  24. data/app/lib/actions/katello/organization/manifest_refresh.rb +16 -9
  25. data/app/lib/actions/katello/repository/capsule_generate_and_sync.rb +5 -3
  26. data/app/lib/actions/katello/repository/errata_mail.rb +1 -1
  27. data/app/lib/actions/katello/repository/refresh_repository.rb +3 -3
  28. data/app/lib/actions/pulp/abstract_async_task_group.rb +18 -0
  29. data/app/lib/actions/pulp/consumer/sync_capsule.rb +2 -1
  30. data/app/lib/katello/resources/candlepin.rb +9 -6
  31. data/app/lib/katello/util/support.rb +1 -1
  32. data/app/models/katello/authorization/repository.rb +3 -3
  33. data/app/models/katello/concerns/operatingsystem_extensions.rb +2 -2
  34. data/app/models/katello/concerns/pulp_database_unit.rb +1 -1
  35. data/app/models/katello/docker_manifest.rb +5 -1
  36. data/app/models/katello/docker_meta_tag.rb +108 -0
  37. data/app/models/katello/docker_tag.rb +19 -1
  38. data/app/models/katello/erratum.rb +16 -6
  39. data/app/models/katello/glue/candlepin/candlepin_object.rb +12 -11
  40. data/app/models/katello/glue/candlepin/subscription.rb +3 -1
  41. data/app/models/katello/glue/provider.rb +4 -4
  42. data/app/models/katello/glue/pulp/repo.rb +25 -0
  43. data/app/models/katello/host/content_facet.rb +1 -1
  44. data/app/models/katello/host/subscription_facet.rb +1 -1
  45. data/app/models/katello/pool.rb +1 -1
  46. data/app/models/katello/repository.rb +8 -0
  47. data/app/models/katello/sync_plan.rb +2 -2
  48. data/app/models/setting/content.rb +1 -0
  49. data/app/overrides/add_about_page.rb +0 -7
  50. data/app/views/common/400.html +9 -0
  51. data/app/views/katello/api/v2/content_views/base.json.rabl +1 -1
  52. data/app/views/katello/api/v2/docker_tags/_base.json.rabl +11 -1
  53. data/app/views/katello/api/v2/repositories/base.json.rabl +1 -1
  54. data/config/routes/api/rhsm.rb +1 -0
  55. data/db/migrate/20170523182831_create_docker_meta_tag.rb +13 -0
  56. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/content-host-modal-helper.service.js +71 -0
  57. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/content-hosts.controller.js +13 -56
  58. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/content-hosts.routes.js +1 -1
  59. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/content-host-details-info.controller.js +6 -4
  60. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-hosts/details/views/content-host-info.html +2 -2
  61. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/content-views.routes.js +9 -0
  62. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-copy.html +3 -1
  63. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/docker-tags/details/views/docker-tag-info.html +27 -16
  64. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/docker-tags/docker-tags.controller.js +12 -0
  65. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/docker-tags/views/docker-tags.html +4 -0
  66. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/errata/details/erratum-content-hosts.controller.js +10 -4
  67. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/errata/errata.controller.js +1 -1
  68. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/host-collections/details/host-collection-details.controller.js +41 -6
  69. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/host-collections/details/views/host-collection-info.html +11 -5
  70. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/details/repositories/details/views/repository-manage-docker-manifests.html +4 -0
  71. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/products/discovery/discovery-create.controller.js +9 -11
  72. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/subscription-content-hosts.controller.js +4 -0
  73. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/details/views/subscription-content-hosts.html +1 -1
  74. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/manifest/manifest-import.controller.js +26 -20
  75. data/engines/bastion_katello/app/assets/javascripts/bastion_katello/subscriptions/manifest/views/manifest-import.html +16 -12
  76. data/lib/katello/tasks/delete_orphaned_content.rake +8 -1
  77. data/lib/katello/tasks/repository.rake +20 -0
  78. data/lib/katello/version.rb +1 -1
  79. metadata +6 -6
  80. data/app/controllers/katello/errors_controller.rb +0 -23
  81. data/app/controllers/katello/failed_authentication_controller.rb +0 -51
  82. data/app/controllers/katello/sort_column_list.rb +0 -19
  83. data/app/views/overrides/about/_support_documentation.html.erb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87cafa0ce4cb5fa431eb76d8fd7f7eb2b2c23f85
4
- data.tar.gz: c62487b569a5bffafeb677c9336db52ba0c17531
3
+ metadata.gz: 8751ffc813891b31dd245dcf1d489d100d1949ef
4
+ data.tar.gz: 4d862eeda9bf7bfa65290774380d19f6efd69ca6
5
5
  SHA512:
6
- metadata.gz: d1561efea66f466fd4632eb6370b6c2d6658f743134e33b2e64efde612b217146465c63f3fae99c34856d477979610238bab6e7871bcc3237b890ee4d962c740
7
- data.tar.gz: 3d7b4d701f24976c24aea87e2a437fd9fefc39ada515e694f0eb5758af5efd0cc6f274ac8f73b04f9c3f46a634f646bf78fa4d58c9f297e1f70426918b75ae3b
6
+ metadata.gz: b9b1d0659f08e44c3ccc28c322fa8ebfabc67fda376839b56a9abf55870f99946369cbbf1cde71ba32b0578486f7a3de3b82dccca3e3ae863aba479e6f2007b2
7
+ data.tar.gz: 14531bc8de473c9cb8aa0d4b500119a944a1feac7461801c0def52b08839dd6137a22eef63e9e0f597849777c2bdb13f32e7ff5cd43c92d9f1edf148bea59c8a
@@ -469,7 +469,7 @@ module Katello
469
469
  (User.consumer? || ::User.current.can?(:view_organizations, self))
470
470
  when "rhsm_proxy_consumer_certificates_path", "rhsm_proxy_consumer_releases_path", "rhsm_proxy_certificate_serials_path",
471
471
  "rhsm_proxy_consumer_entitlements_path", "rhsm_proxy_consumer_entitlements_post_path",
472
- "rhsm_proxy_consumer_entitlements_delete_path",
472
+ "rhsm_proxy_consumer_entitlements_delete_path", "rhsm_proxy_consumer_certificates_put_path",
473
473
  "rhsm_proxy_consumer_dryrun_path", "rhsm_proxy_consumer_owners_path",
474
474
  "rhsm_proxy_consumer_compliance_path"
475
475
  User.consumer? && current_user.uuid == params[:id]
@@ -44,6 +44,12 @@ module Katello
44
44
  :subtotal => collection.count }
45
45
  end
46
46
 
47
+ def empty_search_query?
48
+ search_options[0].blank?
49
+ end
50
+
51
+ # rubocop:disable Metrics/MethodLength
52
+ # rubocop:disable Metrics/PerceivedComplexity
47
53
  def scoped_search(query, default_sort_by, default_sort_order, options = {})
48
54
  resource = options[:resource_class] || resource_class
49
55
  includes = options.fetch(:includes, [])
@@ -51,8 +57,10 @@ module Katello
51
57
 
52
58
  total = scoped_search_total(query, group)
53
59
 
54
- query = query.pluck(:id) if query.respond_to?(:pluck)
55
- query = resource.search_for(*search_options).where("#{resource.table_name}.id" => query)
60
+ unless empty_search_query?
61
+ query = query.pluck(:id) if query.respond_to?(:pluck)
62
+ query = resource.search_for(*search_options).where("#{resource.table_name}.id" => query)
63
+ end
56
64
 
57
65
  query = query.select(group).group(group) if group
58
66
  sub_total = total.zero? ? 0 : scoped_search_total(query, group)
@@ -51,7 +51,7 @@ module Katello
51
51
  param :environment_id, Integer, :desc => N_('Id of the environment to limit the synchronization on')
52
52
  def sync
53
53
  find_environment if params[:environment_id]
54
- task = async_task(::Actions::Katello::CapsuleContent::Sync, capsule_content, :environment => @environment)
54
+ task = async_task(::Actions::Katello::CapsuleContent::Sync, capsule_content.capsule, :environment_id => @environment.try(:id))
55
55
  respond_for_async :resource => task
56
56
  end
57
57
 
@@ -16,5 +16,9 @@ module Katello
16
16
  def custom_index_relation(collection)
17
17
  collection.includes(:docker_tags)
18
18
  end
19
+
20
+ def default_sort
21
+ lambda { |query| query.default_sort }
22
+ end
19
23
  end
20
24
  end
@@ -7,8 +7,8 @@ module Katello
7
7
 
8
8
  def auto_complete_name
9
9
  page_size = Katello::Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
10
- tags = Katello::DockerTag.in_repositories(@repositories)
11
- col = "#{Katello::DockerTag.table_name}.name"
10
+ tags = Katello::DockerMetaTag.in_repositories(@repositories)
11
+ col = "#{Katello::DockerMetaTag.table_name}.name"
12
12
  tags = tags.where("#{Katello::DockerTag.table_name}.name ILIKE ?", "#{params[:term]}%").select(col).group(col).order(col).limit(page_size)
13
13
  render :json => tags.pluck(col)
14
14
  end
@@ -18,8 +18,7 @@ module Katello
18
18
  # group docker tags by name, repo, and product
19
19
  repos = Repository.readable
20
20
  repos = repos.in_organization(@organization) if @organization
21
- collection = Katello::DockerTag.in_repositories(repos).grouped
22
-
21
+ collection = Katello::DockerMetaTag.in_repositories(repos, true)
23
22
  respond(:collection => scoped_search(collection, "name", "DESC"))
24
23
  else
25
24
  super
@@ -33,7 +32,7 @@ module Katello
33
32
  end
34
33
 
35
34
  def resource_class
36
- DockerTag
35
+ DockerMetaTag
37
36
  end
38
37
  end
39
38
  end
@@ -14,6 +14,7 @@ module Katello
14
14
  param :errata_restrict_installable, :bool, :desc => N_("show only errata with one or more installable hosts")
15
15
  param_group :search, Api::V2::ApiController
16
16
  def index
17
+ params[:errata_restrict_applicable] = false if ::Foreman::Cast.to_bool(params[:errata_restrict_installable])
17
18
  super
18
19
  end
19
20
 
@@ -39,11 +40,11 @@ module Katello
39
40
  hosts = ::Host::Managed.authorized("view_hosts")
40
41
  hosts = hosts.where(:organization_id => params[:organization_id]) if params[:organization_id]
41
42
  if ::Foreman::Cast.to_bool(params[:errata_restrict_applicable])
42
- collection = collection.applicable_to_hosts(hosts)
43
+ collection = collection.where(:id => Erratum.applicable_to_hosts(hosts))
43
44
  end
44
45
 
45
46
  if ::Foreman::Cast.to_bool(params[:errata_restrict_installable])
46
- collection = collection.installable_for_hosts(hosts)
47
+ collection = collection.where(:id => Erratum.ids_installable_for_hosts(hosts))
47
48
  end
48
49
  collection
49
50
  end
@@ -21,7 +21,7 @@ module Katello
21
21
  param :host_id, :identifier, :required => true, :desc => N_("ID of the host")
22
22
  param_group :search, Api::V2::ApiController
23
23
  def index
24
- collection = scoped_search(index_relation.uniq, :name, :asc, :resource_class => ::Katello::InstalledPackage)
24
+ collection = scoped_search(index_relation, :name, :asc, :resource_class => ::Katello::InstalledPackage)
25
25
  respond_for_index(:collection => collection)
26
26
  end
27
27
 
@@ -236,8 +236,8 @@ module Katello
236
236
 
237
237
  def find_errata
238
238
  params[:errata_ids] ||= []
239
- @errata = Katello::Erratum.where(:uuid => params[:errata_ids])
240
- not_found = params[:errata_ids] - @errata.pluck(:uuid)
239
+ @errata = Katello::Erratum.where(:errata_id => params[:errata_ids])
240
+ not_found = params[:errata_ids] - @errata.pluck(:errata_id)
241
241
  fail _("Could not find all specified errata ids: %s") % not_found.join(', ') unless not_found.empty?
242
242
  end
243
243
 
@@ -389,7 +389,7 @@ module Katello
389
389
  param :id, :identifier, :required => true
390
390
  def gpg_key_content
391
391
  if @repository.gpg_key && @repository.gpg_key.content.present?
392
- render(:text => @repository.gpg_key.content, :layout => false)
392
+ render(:plain => @repository.gpg_key.content, :layout => false)
393
393
  else
394
394
  head(404)
395
395
  end
@@ -9,68 +9,21 @@ module Katello
9
9
 
10
10
  clear_helpers
11
11
 
12
- helper ::ApplicationHelper
13
12
  helper ::TaxonomyHelper
13
+ helper ::ApplicationHelper
14
+
14
15
  before_action :set_gettext_locale
15
16
  helper_method :current_organization
16
17
  before_action :require_org
17
- #before_filter :check_deleted_org
18
18
 
19
19
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
20
20
 
21
- after_action :flash_to_headers
22
-
23
21
  # Skipping Foreman's filter that clears the user
24
22
  # from the current thread. If this filter is enabled
25
23
  # Katello's rescue_from don't have access to User.current.
26
24
  skip_around_action :clear_thread
27
25
  after_action :clear_katello_thread
28
26
 
29
- #custom 404 (render_404) and 500 (render_error) pages
30
- # this is always in the top
31
- # order of these are important.
32
- rescue_from Exception do |exception|
33
- paranoia = false
34
- hide = false
35
-
36
- to_do = case exception
37
- when StandardError
38
- hide ? :handle : :raise
39
- when ScriptError
40
- paranoia ? :handle : :raise
41
- when SignalException, SystemExit, NoMemoryError
42
- :raise
43
- else
44
- Rails.logger.error 'Unknown child of Exception instead of StandardError detected: ' \
45
- "#{exception.message} (#{exception.class})"
46
- paranoia ? :handle : :raise
47
- end
48
-
49
- case to_do
50
- when :handle
51
- execute_rescue(exception) { |ex| render_error(ex) }
52
- when :raise
53
- fail exception
54
- end
55
- end
56
-
57
- rescue_from ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved do |e|
58
- notify.exception e
59
- log_exception e, :info
60
-
61
- respond_to do |f|
62
- f.html { render :text => e.to_s, :layout => !request.xhr?, :status => :unprocessable_entity }
63
- f.json { render :json => e.record.errors, :status => :unprocessable_entity }
64
- end
65
- execute_after_filters
66
- end
67
-
68
- rescue_from ActiveRecord::RecordNotFound do |e|
69
- notify.error e.message
70
- render :nothing => true, :status => :not_found
71
- execute_after_filters
72
- end
73
-
74
27
  rescue_from Errors::SecurityViolation do |exception|
75
28
  execute_rescue(exception) { |_ex| render_403 }
76
29
  end
@@ -79,6 +32,10 @@ module Katello
79
32
  execute_rescue(exception) { |ex| render_bad_parameters(ex) }
80
33
  end
81
34
 
35
+ rescue_from ::Katello::HttpErrors::BadRequest do |exception|
36
+ render_bad_parameters(exception)
37
+ end
38
+
82
39
  include Menu
83
40
 
84
41
  # Override Foreman authorized method to support permissions on meta controllers that handle multiple routes
@@ -94,86 +51,6 @@ module Katello
94
51
  'generic'
95
52
  end
96
53
 
97
- # 'default_label' is an action that is used to allow the UI to retrieve
98
- # a label that is generated by the server based upon a name provided. This action
99
- # is used by several controllers, but not all. For those controllers that do
100
- # use it, the controller will determine if access to it is allowed based on the
101
- # permissions required by that controller.
102
- def default_label
103
- if params[:name]
104
- render :text => Util::Model.labelize(params[:name])
105
- else
106
- render :nothing => true
107
- end
108
- end
109
-
110
- # this is intentionally dead code, it just mark some strings for gettext
111
- # so generate_label and default_label_assigned can use them
112
- def n_gettext_for_generate_label
113
- # the same string for repository, product, organization, environment (see BZ 886718)
114
- N_("A label was not provided during repository creation; therefore, a label of '%{label}' was " \
115
- "automatically assigned. If you would like a different label, please delete the " \
116
- "repository and recreate it with the desired label.")
117
- N_("A label was not provided during product creation; therefore, a label of '%{label}' was " \
118
- "automatically assigned. If you would like a different label, please delete the " \
119
- "product and recreate it with the desired label.")
120
- N_("A label was not provided during organization creation; therefore, a label of '%{label}' was " \
121
- "automatically assigned. If you would like a different label, please delete the " \
122
- "organization and recreate it with the desired label.")
123
- N_("A label was not provided during environment creation; therefore, a label of '%{label}' was " \
124
- "automatically assigned. If you would like a different label, please delete the " \
125
- "environment and recreate it with the desired label.")
126
- end
127
-
128
- # Generate a label using the name provided, returning the label and a string with text that may be
129
- # sent to the user (e.g. via a notice).
130
- def generate_label(object_name, object_type)
131
- # user didn't provide a label, so generate one using the name
132
- label = Util::Model.labelize(object_name)
133
- # if you modify this string you have to modify it in n_gettext_for_generate_label as well
134
- label_assigned_text = "A label was not provided during #{object_type} creation; therefore, a label of '%{label}' was " \
135
- "automatically assigned. If you would like a different label, please delete the " \
136
- "#{object_type} and recreate it with the desired label."
137
- label_assigned_text = _(label_assigned_text) % {:label => label}
138
- return label, label_assigned_text
139
- end
140
-
141
- # Generate a message that may be sent to the user (e.g. via a notice) to inform them that
142
- # a label was automatically assigned to the object.
143
- def default_label_assigned(new_object)
144
- object_type = new_object.class.name.downcase
145
- # if you modify this string you have to modify it in n_gettext_for_generate_label as well
146
- msg = "A label was not provided during #{object_type} creation; therefore, a label of '%{label}' was " \
147
- "automatically assigned. If you would like a different label, please delete the " \
148
- "#{object_type} and recreate it with the desired label."
149
- return _(msg) % {:label => new_object.label}
150
- end
151
-
152
- # Generate a message that may be sent to the user (e.g. via a notice) to inform them that
153
- # the label that they provided has been overriden to ensure uniqueness.
154
- def label_overridden(new_object, requested_label)
155
- object_type = new_object.class.name.downcase
156
- _("The label requested is already used by another %s; therefore, a unique label was " \
157
- "assigned. If you would like a different label, please delete the %s and recreate " \
158
- "it with a unique label. Requested label: %s, Assigned label: %s") %
159
- [object_type, object_type, requested_label, new_object.label]
160
- end
161
-
162
- def flash_to_headers
163
- return if @_response.nil? || @_response.response_code == 302
164
- return if flash.blank?
165
- [:error, :warning, :success, :message].each do |type|
166
- unless flash[type].nil? || flash[type].blank?
167
- @enc = CGI.escape(flash[type].gsub("\n", "<br \\>"))
168
- response.headers['X-Message'] = @enc.gsub("%2B", "&#43;")
169
- response.headers['X-Message-Type'] = type.to_s
170
- response.headers['X-Message-Request-Type'] = requested_action
171
- flash.delete(type) # clear the flash
172
- return
173
- end
174
- end
175
- end
176
-
177
54
  def current_organization
178
55
  if !session[:current_organization_id]
179
56
  @current_org = Organization.current
@@ -201,76 +78,14 @@ module Katello
201
78
  session[:current_organization_id] = org.try(:id)
202
79
  end
203
80
 
204
- def escape_html(input)
205
- CGI.escapeHTML(input)
206
- end
207
-
208
- helper_method :format_time
209
- #formats the date time if the dat is not nil
210
- def format_time(date, options = {})
211
- return I18n.l(date, options) if date
212
- ""
213
- end
214
-
215
- #convert date, time from UI to object
216
- helper_method :parse_calendar_date
217
- def parse_calendar_date(date_str, time_str = "")
218
- return nil if date_str.blank?
219
-
220
- datetime_str = [date_str,
221
- time_str.blank? ? '12:00 am' : time_str,
222
- DateTime.now.zone].join ' '
223
-
224
- DateTime.strptime(datetime_str, '%m/%d/%Y %I:%M %P %:z') rescue false
225
- end
226
-
227
- helper_method :no_env_available_msg
228
- def no_env_available_msg
229
- _("No environments are currently available in this organization. Please either add some to the organization or select an organization that has an environment to set user default.")
230
- end
231
-
232
- def render_correct_nav
233
- if self.respond_to?(:menu_definition) && self.menu_definition[params[:action]] == :admin_menu
234
- session[:menu_back] = true
235
- #the menu definition exists, return true
236
- render_admin_menu
237
- else
238
- #the menu definition does not exist, return false
239
- session[:menu_back] = false
240
- session[:notifications] = false
241
- #render_menu(1)
242
- end
243
- end
244
-
245
- # Parse the input provided and return the value of displayMessage. If displayMessage is not available, return "".
246
- # (Note: this can be used to pull the displayMessage from a Candlepin exception.)
247
- # This assumes that the input follows a syntax similar to:
248
- # "{\"displayMessage\":\"Import is older than existing data\"}"
249
- def self.parse_display_message(input)
250
- unless input.nil?
251
- if input.include? 'displayMessage'
252
- return JSON.parse(input)['displayMessage']
253
- end
254
- end
255
- input
256
- end
257
-
258
81
  private # why bother? methods below are not testable/tested
259
82
 
260
83
  def require_org
261
84
  unless session && current_organization
262
- execute_after_filters
263
85
  redirect_to '/select_organization?toState=' + request.path
264
86
  end
265
87
  end
266
88
 
267
- # TODO: this check can be removed once we start deleting sessions during org deletion
268
- def check_deleted_org
269
- if current_organization && current_organization.being_deleted?
270
- fail Errors::SecurityViolation, _("Current organization is being deleted, switch to a different one.")
271
- end
272
- end
273
-
274
89
  def require_user
275
90
  if current_user
276
91
  #don't redirect if the user is trying to set an org
@@ -284,38 +99,9 @@ module Katello
284
99
 
285
100
  return true
286
101
  else
287
- #user not logged
288
- notify.warning _("You must be logged in to access that page.")
289
-
290
102
  #save original uri and redirect to login page
291
103
  session[:original_uri] = request.fullpath
292
- execute_after_filters
293
- end
294
- end
295
-
296
- # render 403 page
297
- def render_403
298
- respond_to do |format|
299
- format.html { render :template => "katello/common/403", :layout => !request.xhr?, :status => 403 }
300
- format.atom { head 403 }
301
- format.xml { head 403 }
302
- format.json { head 403 }
303
104
  end
304
- return false
305
- end
306
-
307
- # render a 404 page
308
- def render_404(exception = nil)
309
- if exception
310
- logger.error _("Rendering 404:") + " #{exception.message}"
311
- end
312
- respond_to do |format|
313
- format.html { render :template => "katello/common/404", :layout => !request.xhr?, :status => 404 }
314
- format.atom { head 404 }
315
- format.xml { head 404 }
316
- format.json { head 404 }
317
- end
318
- User.current = nil
319
105
  end
320
106
 
321
107
  # render bad params to user
@@ -349,15 +135,13 @@ module Katello
349
135
 
350
136
  if exception
351
137
  log_exception exception
352
- notify.exception(message, exception)
353
138
  else
354
- notify.error message
355
139
  Rails.logger.warn message
356
140
  end
357
141
 
358
142
  respond_to do |format|
359
143
  format.html do
360
- render :template => 'katello/common/400', :layout => !request.xhr?, :status => status,
144
+ render :template => 'common/400', :layout => !request.xhr?, :status => status,
361
145
  :locals => {:message => message}
362
146
  end
363
147
  format.atom { head exception.status_code }
@@ -367,303 +151,27 @@ module Katello
367
151
  User.current = nil
368
152
  end
369
153
 
370
- # take care of 500 pages too
371
- def render_error(exception = nil)
372
- if exception
373
- logger.error _("Rendering 500:") + "#{exception.message}"
374
- notify.exception exception
375
- end
376
- respond_to do |format|
377
- format.html do
378
- render :template => "katello/common/500", :layout => "katello", :status => 500,
379
- :locals => {:error => exception}
380
- end
381
- format.atom { head 500 }
382
- format.xml { head 500 }
383
- format.json { head 500 }
384
- end
385
- User.current = nil
386
- end
387
-
388
- def requested_action
389
- unless controller_name.nil? || action_name.nil?
390
- controller_name + '___' + action_name
391
- end
392
- end
393
-
394
- # TODO: break up method
395
- # rubocop:disable MethodLength
396
- def setup_environment_selector(org, accessible)
397
- next_env = KTEnvironment.find(params[:next_env_id]) if params[:next_env_id]
398
-
399
- @paths = []
400
- @paths = org.promotion_paths.collect { |tmp_path| [org.library] + tmp_path }
401
-
402
- # reject any paths that don't have accessible envs
403
- @paths.reject! { |path| (path & accessible).empty? }
404
-
405
- @paths = [[org.library]] if @paths.empty?
406
-
407
- if @environment && !@environment.library?
408
- @paths.each do |path|
409
- path.each do |env|
410
- if (@path = path)
411
- return if env.id == @environment.id
412
- end
413
- end
414
- end
415
- elsif next_env
416
- @paths.each do |path|
417
- path.each do |env|
418
- if (@path = path)
419
- return if env.id == next_env.id
420
- end
421
- end
422
- end
423
- else
424
- @path = @paths.first
425
- @environment = @path.first
426
- end
427
- end
428
-
429
- def environment_path_element(perms_method = nil)
430
- lambda do |a_path|
431
- {:id => a_path.id,
432
- :name => a_path.name,
433
- :select => perms_method.nil? ? false : a_path.send(perms_method)}
434
- end
435
- end
436
-
437
- def library_path_element(perms = nil)
438
- if current_organization.library.send(perms)
439
- environment_path_element(perms).call(current_organization.library)
440
- end
441
- end
442
-
443
- def environment_paths(library, environment_path_element_generator)
444
- paths = current_organization.promotion_paths
445
- to_ret = []
446
- paths.each do |path|
447
- path = path.select { |env| env.readable? }
448
- path = path.collect { |env| environment_path_element_generator.call(env) if env.readable? }
449
-
450
- if library
451
- to_ret << [library] + path
452
- else
453
- to_ret << path
454
- end
455
- end
456
-
457
- if paths.empty? && library
458
- to_ret << [library]
459
- end
460
-
461
- to_ret
462
- end
463
-
464
- #verify if the specific object with the given id, matches a given search string
465
- def search_validate(obj_class, id, search, default = :name)
466
- if obj_class.respond_to?(:index)
467
- obj_class.index.refresh
468
- search = '*' if search.nil? || search == ''
469
- search = Util::Search.filter_input search
470
- query_options = {}
471
- query_options[:default_field] = default if default
472
-
473
- results = obj_class.search do
474
- query { string search, query_options }
475
- filter :terms, :id => [id]
476
- end
477
- results.total > 0
478
- end
479
- end
480
-
481
- # @param [Hash] search_options
482
- # @option search_options :default_field
483
- # The field that should be used by the search engine when a user performs
484
- # a search without specifying field.
485
- # @option search_options :filter
486
- # Filter to apply to search. Array of hashes. Each key/value within the hash
487
- # is OR'd, whereas each HASH itself is AND'd together
488
- # @option search_options [true, false] :load whether or not to load the active record object (defaults to false)
489
- def render_panel_direct(obj_class, panel_options, search, start, sort, search_options = {}) # rubocop:disable Metrics/MethodLength
490
- filters = search_options[:filter] || []
491
- load = search_options[:load] || false
492
- all_rows = false
493
- skip_render = search_options[:skip_render] || false
494
- page_size = search_options[:page_size] || current_user.page_size
495
-
496
- start ||= 0
497
-
498
- all_rows = true if (search.nil? || search == '')
499
- #search = Util::Search::filter_input search
500
-
501
- # set the query default field, if one was provided.
502
- query_options = {}
503
- query_options[:default_field] = search_options[:default_field] unless search_options[:default_field].blank?
504
-
505
- panel_options[:accessor] ||= "id"
506
- panel_options[:columns] = panel_options[:col]
507
- panel_options[:initial_action] ||= :edit
508
-
509
- @items = []
510
-
511
- begin
512
- results = obj_class.search(:load => false) do
513
- query do
514
- if all_rows
515
- all
516
- else
517
- string search, query_options
518
- end
519
- end
520
-
521
- sort { by sort[0], sort[1].to_s.downcase } if all_rows
522
-
523
- filters = [filters] unless filters.is_a?(Array)
524
- filters.each { |i| filter :terms, i } unless filters.empty?
525
-
526
- size page_size if page_size > 0
527
- from start
528
- end
529
-
530
- if load
531
- @items = obj_class.where(:id => results.collect { |r| r.id })
532
- #set total since @items will be just an array
533
- panel_options[:total_count] = results.empty? ? 0 : results.total
534
- if @items.length != results.length
535
- Rails.logger.error("Failed to retrieve all #{obj_class} search results " \
536
- "(#{@items.length}/#{results.length} found.)")
537
- end
538
- else
539
- @items = results
540
- end
541
-
542
- #get total count
543
- total = obj_class.search do
544
- query do
545
- all
546
- end
547
- filters.each { |i| filter :terms, i } unless filters.empty?
548
- size 1
549
- from 0
550
- end
551
- total_count = total.total
552
- end
553
-
554
- render_panel_results(@items, total_count, panel_options) unless skip_render
555
- return @items
556
- end
557
-
558
- def render_panel_results(results, total, options)
559
- options[:total_count] ||= results.empty? ? 0 : results.total
560
- options[:total_results] = total
561
- options[:collection] = results
562
- options[:columns] = options[:col]
563
- @items = results
564
-
565
- if options[:list_partial]
566
- rendered_html = render_to_string(:partial => options[:list_partial], :locals => options)
567
- elsif options[:render_list_proc]
568
- rendered_html = options[:render_list_proc].call(@items, options)
569
- else
570
- rendered_html = render_to_string(:partial => "katello/common/list_items", :locals => options)
571
- end
572
-
573
- render :json => {:html => rendered_html,
574
- :results_count => options[:total_count],
575
- :total_items => options[:total_results],
576
- :current_items => options[:collection].length}
577
- end
578
-
579
- def render_panel_items(items, options, search, start)
580
- @items = items
581
-
582
- options[:accessor] ||= "id"
583
- options[:columns] = options[:col]
584
- options[:initial_action] ||= :edit
585
-
586
- if start == "0"
587
- options[:total_count] = @items.count
588
- end
589
-
590
- # the caller may provide items either based on active record or a list within an array... in the case of an
591
- # array, it is assumed to be based upon results from a pulp/candlepin request, in which case search is
592
- # not currently supported
593
- if @items.is_a? ActiveRecord::Relation
594
- items_searched = @items.search_for(search)
595
- items_offset = items_searched.limit(current_user.page_size).offset(start)
596
- else
597
- items_searched = @items
598
- items_offset = items_searched[start.to_i...start.to_i + current_user.page_size]
599
- end
600
-
601
- options[:total_results] = items_searched.count
602
- options[:collection] ||= items_offset
603
-
604
- if options[:list_partial]
605
- rendered_html = render_to_string(:partial => options[:list_partial], :locals => options)
606
- else
607
- rendered_html = render_to_string(:partial => "katello/common/list_items", :locals => options)
608
- end
609
-
610
- render :json => {:html => rendered_html,
611
- :results_count => options[:total_count],
612
- :total_items => options[:total_results],
613
- :current_items => options[:collection].length}
614
- end
615
-
616
- def execute_after_filters
617
- flash_to_headers
618
- end
619
-
620
- def first_env_in_path(accessible_envs, include_library = false, organization = current_organization)
621
- return organization.library if include_library && accessible_envs.member?(organization.library)
622
- organization.promotion_paths.each do |path|
623
- path.each do |env|
624
- if accessible_envs.member?(env)
625
- return env
626
- end
627
- end
628
- end
629
- nil
630
- end
631
-
632
154
  def execute_rescue(exception, &renderer)
633
155
  log_exception exception
634
156
  if session[:user]
635
157
  User.current = User.find(session[:user])
636
158
  renderer.call(exception)
637
159
  User.current = nil
638
- execute_after_filters
639
160
  return false
640
161
  else
641
- notify.warning _("You must be logged in to access that page.")
642
- execute_after_filters
643
- if redirect_to main_app.login_users_path
644
- return false
645
- end
162
+ return false if redirect_to main_app.login_users_path
646
163
  end
647
164
  end
648
165
 
649
166
  def org_not_found_error
650
- execute_after_filters
651
167
  logout
652
- message = _("Your current organization is no longer valid. It is possible that either the organization has been deleted or your permissions revoked, please log back in to continue.")
653
- notify.warning message
654
- if redirect_to new_user_session_url
655
- return false
656
- end
168
+ return false if redirect_to new_user_session_url
657
169
  end
658
170
 
659
171
  def log_exception(exception, level = :error)
660
172
  logger.send level, "#{exception} (#{exception.class})\n#{exception.backtrace.join("\n")}" if exception
661
173
  end
662
174
 
663
- def default_notify_options
664
- {:organization => current_organization}
665
- end
666
-
667
175
  def clear_katello_thread
668
176
  [:user, :organization, :location].each do |key|
669
177
  Thread.current[key] = nil