Skip to content

Commit

Permalink
Fixes #33996 - Clean up deprecated methods
Browse files Browse the repository at this point in the history
Cleans up all methods that have been marked for removal in 3.2 or older.
  • Loading branch information
tbrisker authored and ezr-ondrej committed Dec 1, 2021
1 parent cf26068 commit b5eb5ca
Show file tree
Hide file tree
Showing 17 changed files with 6 additions and 177 deletions.
49 changes: 0 additions & 49 deletions app/helpers/application_helper.rb
Expand Up @@ -159,19 +159,6 @@ def auto_complete_controller_name
controller.respond_to?(:auto_complete_controller_name) ? controller.auto_complete_controller_name : controller_name
end

def auto_complete_search(name, val, options = {})
Foreman::Deprecation.deprecation_warning('2.5', 'use #auto_complete_f, possibly with #form_with if you need to avoid of object scope')
options.merge!(
{
url: options[:full_path] || (options[:path] || send("#{auto_complete_controller_name}_path")) + "/auto_complete_#{name}",
controller: options[:path] || auto_complete_controller_name,
search_query: '',
use_key_shortcuts: options[:use_key_shortcuts] || false,
}
)
Tags::ReactInput.new(nil, name, self, options.merge(value: val, type: 'autocomplete', only_input: true)).render
end

def sort(field, permitted: [], **kwargs)
kwargs[:url_options] ||= current_url_params(permitted: permitted)
super(field, kwargs)
Expand All @@ -198,37 +185,6 @@ def edit_select(object, property, options = {})
edit_inline(object, property, options.merge({:type => "select"}))
end

def flot_pie_chart(name, title, data, options = {})
Foreman::Deprecation.deprecation_warning('3.1', '#flot_pie_chart is now rendered by react Donut chart with default configuration. '\
'Please render the Donut chart component directly.')
data = data.map { |k, v| [k.to_s.humanize, v] } if data.is_a?(Hash)
react_component('ChartBox', type: 'donut',
status: 'RESOLVED',
title: title,
chart: {
data: data,
search: options[:search] ? hosts_path(search: options[:search]) : nil,
})
end

def flot_chart(name, xaxis_label, yaxis_label, data, options = {})
Foreman::Deprecation.deprecation_warning('3.1', '#flot_chart is rendering its react version by default now. '\
'Please move to rendering React Component directly.')
data = data.map { |k, v| {:label => k.to_s.humanize, :data => v} } if data.is_a?(Hash)
time = ['time'].concat(data[0][:data].map { |d| d.first })
data = data.map { |d_hash| [d_hash[:label]].concat(d_hash[:data].map { |d| d.second }) }
data.unshift(time)
react_component('AreaChart', id: name, xAxisLabel: xaxis_label, yAxisLabel: yaxis_label, data: data)
end

def flot_bar_chart(name, xaxis_label, yaxis_label, data, options = {})
Foreman::Deprecation.deprecation_warning('3.1', '#flot_bar_chart is rendering its react version now. '\
'Please move to rendering React Component directly.')
content_tag(:div, id: name) do
react_component('BarChart', data: data, xAxisLabel: xaxis_label, yAxisLabel: yaxis_label)
end
end

def select_action_button(title, options = {}, *args)
# the no-buttons code is needed for users with less permissions
args = args.flatten.select(&:present?)
Expand Down Expand Up @@ -403,11 +359,6 @@ def user_set?(field)
params[:host] && params[:host][:hostgroup_id] && params[:host][field]
end

def notifications
Foreman::Deprecation.deprecation_warning('3.1', 'notifications method is deprecated, and instead, toasts alerts are handled in the root of the React app.')
nil
end

def toast_notifications_data
selected_toast_notifications = flash.select { |key, _| key != 'inline' }

Expand Down
7 changes: 0 additions & 7 deletions app/helpers/reactjs_helper.rb
@@ -1,12 +1,5 @@
require 'webpack-rails'
module ReactjsHelper
def mount_react_component(name, selector, data = [], opts = {})
Foreman::Deprecation.deprecation_warning('2.5', 'use #react_component instead of #mount_react_component')
javascript_tag defer: 'defer' do
"$(tfm.reactMounter.mount('#{name}', '#{selector}', #{data}, #{opts[:flatten_data] || false}));".html_safe
end
end

# Mount react component in views
# Params:
# +name+:: the component name from the componentRegistry
Expand Down
7 changes: 1 addition & 6 deletions app/models/host/managed.rb
Expand Up @@ -162,7 +162,7 @@ def build_hooks
property :comment, String, desc: 'Returns comment/description of this host'
end
class Jail < ::Safemode::Jail
allow :id, :name, :created_at, :diskLayout, :puppetmaster, :puppet_server, :puppet_ca_server, :operatingsystem, :os, :ptable, :hostgroup,
allow :id, :name, :created_at, :diskLayout, :puppet_server, :puppet_ca_server, :operatingsystem, :os, :ptable, :hostgroup,
:url_for_boot, :hostgroup, :compute_resource, :domain, :ip, :ip6, :mac, :shortname, :architecture,
:model, :certname, :capabilities, :provider, :subnet, :subnet6, :token, :location, :organization, :provision_method,
:image_build?, :pxe_build?, :otp, :realm, :nil?, :indent, :primary_interface,
Expand All @@ -171,11 +171,6 @@ class Jail < ::Safemode::Jail
:multiboot, :jumpstart_path, :install_path, :miniroot, :medium, :bmc_nic, :templates_used, :owner, :owner_type,
:ssh_authorized_keys, :pxe_loader, :global_status, :get_status, :puppetca_token, :last_report, :build?, :smart_proxies, :host_param,
:virtual, :ram, :sockets, :cores, :params, :pxe_loader_efi?, :comment

def puppetmaster
Foreman::Deprecation.deprecation_warning('3.0', 'Host#puppetmaster is deprecated, please use host_puppet_server macro instead')
@source.puppet_server
end
end

scope :recent, lambda { |interval = Setting[:outofsync_interval]|
Expand Down
7 changes: 1 addition & 6 deletions app/models/hostgroup.rb
Expand Up @@ -108,16 +108,11 @@ class Hostgroup < ApplicationRecord
property :title, String, desc: 'Returns full title of this host group, e.g. Base/CentOS 7'
end
class Jail < Safemode::Jail
allow :id, :name, :diskLayout, :puppetmaster, :puppet_server, :operatingsystem, :architecture,
allow :id, :name, :diskLayout, :puppet_server, :operatingsystem, :architecture,
:ptable, :url_for_boot, :params, :puppet_proxy, :puppet_ca_server,
:os, :arch, :domain, :subnet, :subnet6, :hosts, :realm,
:root_pass, :description, :pxe_loader, :title,
:children, :parent

def puppetmaster
Foreman::Deprecation.deprecation_warning('3.0', 'Hostgroup#puppetmaster is deprecated, please use host_puppet_server macro instead')
@source.puppet_server
end
end

# TODO: add a method that returns the valid os for a hostgroup
Expand Down
5 changes: 0 additions & 5 deletions app/models/message.rb
Expand Up @@ -8,11 +8,6 @@ def to_s
value
end

# DEPRECATED: use Rails method (no warning because this is called many times)
def self.find_or_create(value)
find_or_create_by(value: value)
end

def skip_strip_attrs
['value']
end
Expand Down
5 changes: 0 additions & 5 deletions app/models/source.rb
Expand Up @@ -8,11 +8,6 @@ def to_s
value
end

# DEPRECATED: use Rails method (no warning because this is called many times)
def self.find_or_create(value)
find_or_create_by(value: value)
end

def skip_strip_attrs
['value']
end
Expand Down
20 changes: 0 additions & 20 deletions app/models/template_input.rb
Expand Up @@ -35,26 +35,6 @@ def input_type_instance
Foreman.input_types_registry.get(input_type).new if input_type
end

def user_template_input?
Foreman::Deprecation.deprecation_warning('2.5', 'use #input_type or #input_type_instance to determine input type')
input_type == 'user'
end

def fact_template_input?
Foreman::Deprecation.deprecation_warning('2.5', 'use #input_type or #input_type_instance to determine input type')
input_type == 'fact'
end

def variable_template_input?
Foreman::Deprecation.deprecation_warning('2.5', 'use #input_type or #input_type_instance to determine input type')
input_type == 'variable'
end

def puppet_parameter_template_input?
Foreman::Deprecation.deprecation_warning('2.5', 'use #input_type or #input_type_instance to determine input type')
input_type == 'puppet_parameter'
end

def preview(scope)
resolver(scope).preview
end
Expand Down
9 changes: 0 additions & 9 deletions app/registries/foreman/plugin.rb
Expand Up @@ -77,11 +77,6 @@ def global_registry(name, registry)
end
end

def medium_providers
Foreman::Deprecation.deprecation_warning('2.5', 'Plugin.medium_providers is deprecated, use Plugin.medium_providers_registry instead')
medium_providers_registry
end

def def_field(*names)
class_eval do
names.each do |name|
Expand Down Expand Up @@ -579,10 +574,6 @@ def add_histogram_telemetry(name, description, instance_labels = [], buckets = F
Foreman::Telemetry.instance.add_histogram(name, description, instance_labels, buckets)
end

def medium_providers
self.class.medium_providers
end

def smart_proxy_reference(hash)
@smart_proxy_references << ProxyReferenceRegistry.new_reference(hash)
end
Expand Down
15 changes: 0 additions & 15 deletions app/services/fact_parser.rb
Expand Up @@ -7,21 +7,6 @@ class FactParser
VLANS = /\A([a-z0-9]+)\.([0-9]+)\Z/
VIRTUAL_NAMES = /#{ALIASES}|#{VLANS}|#{VIRTUAL}|#{BRIDGES}|#{BONDS}/

def self.parser_for(type)
Foreman::Deprecation.deprecation_warning('3.2', 'FactParser.parser_for() is deprecated, use FactParserRegistry[] instead')
Foreman::Plugin.fact_parser_registry[type]
end

def self.parsers
Foreman::Deprecation.deprecation_warning('3.2', 'FactParser.parsers is deprecated, use FactParserRegistry.parsers instead')
Foreman::Plugin.fact_parser_registry.parsers
end

def self.register_fact_parser(key, klass, default = false)
Foreman::Deprecation.deprecation_warning('3.2', 'FactParser.register_fact_parser() is deprecated, use FactParserRegistry.register() instead')
Foreman::Plugin.fact_parser_registry.register(key, klass, default)
end

attr_reader :facts

# facts are hash of fresh data coming from fact upload in following format
Expand Down
4 changes: 2 additions & 2 deletions app/services/report_importer.rb
Expand Up @@ -92,8 +92,8 @@ def import_log_messages
msg = log['log']['messages']['message']
src = log['log']['sources']['source']

message = Message.find_or_create msg
source = Source.find_or_create src
message = Message.find_or_create_by(value: msg)
source = Source.find_or_create_by(value: src)

# Symbols get turned into strings via the JSON API, so convert back here if it matches
# and expected log level. Log objects can't be created without one, so raise if not
Expand Down
8 changes: 1 addition & 7 deletions test/models/host_jail_test.rb
Expand Up @@ -2,7 +2,7 @@

class HostJailTest < ActiveSupport::TestCase
def test_jail_should_include_these_methods
allowed = [:name, :diskLayout, :puppetmaster, :puppet_server, :puppet_ca_server, :operatingsystem, :os, :ptable, :hostgroup,
allowed = [:name, :diskLayout, :puppet_server, :puppet_ca_server, :operatingsystem, :os, :ptable, :hostgroup,
:organization, :url_for_boot, :hostgroup, :compute_resource, :domain, :ip, :mac, :shortname, :architecture,
:model, :certname, :capabilities, :provider, :subnet, :token, :location, :organization, :provision_method, :image_build?,
:pxe_build?, :otp, :realm, :nil?, :indent, :sp_name, :sp_ip, :sp_mac, :sp_subnet, :facts,
Expand All @@ -12,10 +12,4 @@ def test_jail_should_include_these_methods
assert Host::Managed::Jail.allowed?(m), "Method #{m} is not available in Host::Managed::Jail while should be allowed."
end
end

test '#puppetmaster should be deprecated' do
Foreman::Deprecation.expects(:deprecation_warning)
host = FactoryBot.build_stubbed(:host)
host.to_jail.puppetmaster
end
end
11 changes: 0 additions & 11 deletions webpack/assets/javascripts/bundle.js
Expand Up @@ -28,16 +28,6 @@ import * as lookupKeys from './foreman_lookup_keys';
import './foreman_overrides';
import './bundle_novnc';

const numFieldsDeprecationOnly = {
initAll: () => {
window.tfm.tools.deprecate(
'initAll()',
'does nothing as of now, please stop calling it',
'3.2'
);
},
};

// Set the public path for dynamic imports
if (process.env.NODE_ENV !== 'production') {
/* eslint-disable-next-line */
Expand All @@ -53,7 +43,6 @@ window.tfm = Object.assign(window.tfm || {}, {
hosts,
httpProxies,
toastNotifications,
numFields: numFieldsDeprecationOnly,
reactMounter,
editor,
nav,
Expand Down
9 changes: 0 additions & 9 deletions webpack/assets/javascripts/foreman_navigation.js
Expand Up @@ -5,7 +5,6 @@ import URI from 'urijs';
import { push } from 'connected-react-router';
import store from './react_app/redux';
import * as LayoutActions from './react_app/components/Layout/LayoutActions';
import { deprecate } from './react_app/common/DeprecationService';

export const visit = url => {
window.location.href = url;
Expand Down Expand Up @@ -33,14 +32,6 @@ export const hideLoading = () => {
store.dispatch(LayoutActions.hideLoading());
};

export const changeLocation = loc => {
deprecate('changeLocation', 'Context', '2.6');
};

export const changeOrganization = org => {
deprecate('changeOrganization', 'Context', '2.6');
};

export const changeActive = active => {
store.dispatch(LayoutActions.changeActiveMenu({ title: active }));
};
Expand Down
@@ -1,21 +1,12 @@
import { get, snakeCase } from 'lodash';
import { snakeCase } from 'lodash';
import { noop } from '../../common/helpers';
import { deprecate } from '../../common/DeprecationService';

export const selectLayout = state => state.layout;

export const selectMenuItems = state => selectLayout(state).items;
export const selectActiveMenu = state => selectLayout(state).activeMenu;
export const selectIsLoading = state => selectLayout(state).isLoading;
export const selectIsCollapsed = state => selectLayout(state).isCollapsed;
export const selectCurrentLocation = state => {
deprecate('selectCurrentLocation', 'useForemanLocation hook', 2.5);
return get(selectLayout(state), 'currentLocation');
};
export const selectCurrentOrganization = state => {
deprecate('selectCurrentOrganization', 'useForemanOrganization hook', 2.5);
return get(selectLayout(state), 'currentOrganization');
};

export const patternflyMenuItemsSelector = (
state,
Expand Down
Expand Up @@ -50,9 +50,6 @@ const fixtures = {

'should return isLoading from selector': () => selectIsLoading(state),
'should return isCollapsed from selector': () => selectIsCollapsed(state),
'should return location from selector': () => selectCurrentLocation(state),
'should return organization from selector': () =>
selectCurrentOrganization(state),
};

describe('Layout selectors', () => testSelectorsSnapshotWithFixtures(fixtures));
Expand Up @@ -126,7 +126,3 @@ exports[`Layout selectors should return empty array of items 1`] = `Array []`;
exports[`Layout selectors should return isCollapsed from selector 1`] = `false`;

exports[`Layout selectors should return isLoading from selector 1`] = `true`;

exports[`Layout selectors should return location from selector 1`] = `"loc1"`;

exports[`Layout selectors should return organization from selector 1`] = `"org1"`;

This file was deleted.

0 comments on commit b5eb5ca

Please sign in to comment.