Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #22901 from jrafanie/drop_default_value_for" #22922

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/assigned_server_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AssignedServerRole < ApplicationRecord
belongs_to :miq_server
belongs_to :server_role

attribute :active, :default => false
default_value_for :active, false

delegate :master_supported?, :name, :to => :server_role

Expand Down
14 changes: 8 additions & 6 deletions app/models/blacklisted_event.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class BlacklistedEvent < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => "ems_id"

attribute :enabled, :default => true
after_validation :log_enabling, :if => :enabled_changed?, :unless => :new_record?
after_create :audit_creation
after_destroy :reload_all_server_settings, :audit_deletion
default_value_for :enabled, true
after_save :reload_all_server_settings
after_destroy :reload_all_server_settings, :audit_deletion
after_create :audit_creation

def audit_deletion
$audit_log.info("Blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] has been deleted by user [#{self.class.current_userid}]")
Expand All @@ -15,8 +14,11 @@ def audit_creation
$audit_log.info("Creating blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] by user [#{self.class.current_userid}]")
end

def log_enabling
$audit_log.info("Blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] had enabled changed to #{enabled} by user [#{self.class.current_userid}]")
def enabled=(value)
return if enabled == value

super
$audit_log.info("Blacklisted event [#{event_name}] for provider [#{provider_model}] with ID [#{ems_id}] had enabled changed to #{value} by user [#{self.class.current_userid}]")
end

def self.seed
Expand Down
8 changes: 4 additions & 4 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class Classification < ApplicationRecord

DEFAULT_NAMESPACE = "/managed".freeze

attribute :read_only, :default => false
attribute :syntax, :default => "string"
attribute :single_value, :default => false
attribute :show, :default => true
default_value_for :read_only, false
default_value_for :syntax, "string"
default_value_for :single_value, false
default_value_for :show, true

FIXTURE_FILE = FIXTURE_DIR.join("classifications.yml")

Expand Down
2 changes: 1 addition & 1 deletion app/models/cloud_database_flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CloudDatabaseFlavor < ApplicationRecord

virtual_total :total_cloud_databases, :cloud_databases

attribute :enabled, :default => true
default_value_for :enabled, true

scope :active, -> { where(:enabled => true) }
end
2 changes: 1 addition & 1 deletion app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Dialog < ApplicationRecord
# The following gets around a glob symbolic link issue
YAML_FILES_PATTERN = "{,*/**/}*.{yaml,yml}".freeze

attribute :system, :default => false
default_value_for :system, false
has_many :dialog_tabs, -> { order(:position) }, :dependent => :destroy
validate :validate_children

Expand Down
6 changes: 3 additions & 3 deletions app/models/dialog_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class DialogField < ApplicationRecord
validates :name, :exclusion => {:in => %w(action controller),
:message => "Field Name %{value} is reserved."}

attribute :required, :default => false
attribute :visible, :default => true
default_value_for :required, false
default_value_for(:visible) { true }
validates :visible, inclusion: { in: [ true, false ] }
attribute :load_values_on_init, :default => true
default_value_for :load_values_on_init, true

serialize :values
serialize :values_method_options, Hash
Expand Down
2 changes: 1 addition & 1 deletion app/models/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Endpoint < ApplicationRecord
belongs_to :resource, :polymorphic => true

attribute :verify_ssl, :default => OpenSSL::SSL::VERIFY_PEER
default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}
validates :port, :numericality => {:only_integer => true, :allow_nil => true, :greater_than => 0}
validates :url, :uniqueness_when_changed => true, :allow_blank => true, :unless => :allow_duplicate_url?
Expand Down
2 changes: 1 addition & 1 deletion app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def validate_zone_not_maintenance_when_ems_enabled?
alias_method :clusters, :ems_clusters # Used by web-services to return clusters as the property name
alias_attribute :to_s, :name

attribute :enabled, :default => true
default_value_for :enabled, true

# Move ems to maintenance zone and backup current one
# @param orig_zone [Integer] because of zone of child manager can be changed by parent manager's ensure_managers() callback
Expand Down
2 changes: 1 addition & 1 deletion app/models/flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Flavor < ApplicationRecord

virtual_total :total_vms, :vms

attribute :enabled, :default => true
default_value_for :enabled, true

alias_attribute :cpus, :cpu_total_cores
alias_attribute :cpu_cores, :cpu_cores_per_socket
Expand Down
2 changes: 1 addition & 1 deletion app/models/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GitRepository < ApplicationRecord

validates :url, :format => Regexp.union(URI.regexp(%w[http https file ssh]), /\A[-\w:.]+@.*:/), :allow_nil => false

attribute :verify_ssl, :default => OpenSSL::SSL::VERIFY_PEER
default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}

has_many :git_branches, :dependent => :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/manageiq/providers/cloud_manager/template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ManageIQ::Providers::CloudManager::Template < ::MiqTemplate
attribute :cloud, :default => true
default_value_for :cloud, true

virtual_column :image?, :type => :boolean

Expand Down
2 changes: 1 addition & 1 deletion app/models/manageiq/providers/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ManageIQ::Providers::CloudManager::Vm < ::Vm

has_many :host_aggregates, :through => :host

attribute :cloud, :default => true
default_value_for :cloud, true

virtual_column :ipaddresses, :type => :string_set, :uses => {:network_ports => :ipaddresses}
virtual_column :floating_ip_addresses, :type => :string_set, :uses => {:network_ports => :floating_ip_addresses}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ManageIQ::Providers::EmbeddedAutomationManager::ConfigurationScriptSource
validates :scm_type, :presence => true, :inclusion => {:in => %w[git]}
validates :scm_branch, :presence => true

attribute :scm_type, :default => "git"
attribute :scm_branch, :default => "master"
default_value_for :scm_type, "git"
default_value_for :scm_branch, "master"

belongs_to :git_repository, :autosave => true, :dependent => :destroy
before_validation :sync_git_repository
Expand Down
2 changes: 1 addition & 1 deletion app/models/manageiq/providers/infra_manager/template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ManageIQ::Providers::InfraManager::Template < MiqTemplate
attribute :cloud, :default => false
default_value_for :cloud, false

def self.display_name(number = 1)
n_('Template', 'Templates', number)
Expand Down
2 changes: 1 addition & 1 deletion app/models/manageiq/providers/infra_manager/vm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ManageIQ::Providers::InfraManager::Vm < ::Vm
attribute :cloud, :default => false
default_value_for :cloud, false

# Show certain non-generic charts
def cpu_mhz_available?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ManageIQ::Providers::PhysicalInfraManager::Vm < ::Vm
attribute :cloud, :default => false
default_value_for :cloud, false

def self.display_name(number = 1)
n_('Virtual Machine', 'Virtual Machines', number)
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_ae_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class MiqAeMethod < ApplicationRecord
include MiqAeYamlImportExportMixin
include RelativePathMixin

attribute :embedded_methods, :default => -> { [] }
default_value_for(:embedded_methods) { [] }
# switch back to validates :exclusion once rails 6.1 issue is fixed
# https://github.com/rails/rails/issues/41051
validate :embedded_methods_not_nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_approval.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class MiqApproval < ApplicationRecord
belongs_to :stamper, :class_name => "User"
belongs_to :miq_request

attribute :state, :default => "pending"
default_value_for :state, "pending"

def approver=(approver)
super
Expand Down
7 changes: 4 additions & 3 deletions app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class MiqGroup < ApplicationRecord

serialize :settings

attribute :group_type, :default => USER_GROUP
attribute :sequence, :default => -> { next_sequence }
default_value_for :group_type, USER_GROUP
default_value_for(:sequence) { next_sequence }

acts_as_miq_taggable
include CustomAttributeMixin
include ActiveVmAggregationMixin
Expand Down Expand Up @@ -80,7 +81,7 @@ def self.next_sequence
# https://github.com/rails/rails/pull/35280
#
# This was an attempt to fix "leaking scopes", however, in our case, we use
# this method both for our default value of :sequence, and it will get
# this method both for our +default_value_for(:sequence)+, and it will get
# used as part of +.create_tenant_group+.
#
# As such, we need both +.current_scope+ for when we want to scope down the
Expand Down
6 changes: 3 additions & 3 deletions app/models/miq_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def self.policy_modes
include YamlImportExportMixin
before_validation :default_name_to_guid, :on => :create

attribute :towhat, :default => 'Vm'
attribute :active, :default => true
attribute :mode, :default => 'control'
default_value_for :towhat, 'Vm'
default_value_for :active, true
default_value_for :mode, 'control'

# NOTE: If another class references MiqPolicy through an ActiveRecord association,
# particularly has_one and belongs_to, calling .conditions will result in
Expand Down
8 changes: 2 additions & 6 deletions app/models/miq_provision_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ class MiqProvisionRequest < MiqRequest
validates :source, :presence => true
validate :must_have_user

default_value_for :options, :number_of_vms => 1
default_value_for(:source_id) { |r| r.get_option(:src_vm_id) || r.get_option(:source_id) }
attribute :source_type, :default => "VmOrTemplate"
default_value_for :source_type, "VmOrTemplate"

virtual_column :provision_type, :type => :string

include MiqProvisionMixin
include MiqProvisionQuotaMixin

# Setup default coming back from the default serialized Hash
def options
super.tap { |s| s[:number_of_vms] = 1 unless s.key?(:number_of_vms) }
end

def self.request_task_class_from(attribs)
source_id = MiqRequestMixin.get_option(:src_vm_id, nil, attribs['options'])
vm_or_template = source_vm_or_template!(source_id)
Expand Down
7 changes: 4 additions & 3 deletions app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class MiqRequest < ApplicationRecord
serialize :options, Hash

default_value_for(:message) { |r| "#{r.class::TASK_DESCRIPTION} - Request Created" }
attribute :request_state, :default => 'pending'
default_value_for :options, {}
default_value_for :request_state, 'pending'
default_value_for(:request_type) { |r| r.request_types.first }
attribute :status, :default => 'Ok'
attribute :process, :default => true
default_value_for :status, 'Ok'
default_value_for :process, true

validates_inclusion_of :approval_state, :in => %w(pending_approval approved denied), :message => "should be 'pending_approval', 'approved' or 'denied'"
validates_inclusion_of :status, :in => %w(Ok Warn Error Timeout Denied)
Expand Down
6 changes: 4 additions & 2 deletions app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class MiqRequestTask < ApplicationRecord
serialize :phase_context, Hash
serialize :options, Hash

attribute :state, :default => 'pending'
attribute :status, :default => 'Ok'
default_value_for :phase_context, {}
default_value_for :options, {}
default_value_for :state, 'pending'
default_value_for :status, 'Ok'

delegate :request_class, :task_description, :to => :class

Expand Down
6 changes: 3 additions & 3 deletions app/models/miq_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class MiqSchedule < ApplicationRecord
ALLOWED_CLASS_METHOD_ACTIONS = %w[automation_request].freeze
IMPORT_CLASS_NAMES = %w[MiqSchedule].freeze

attribute :userid, :default => "system"
attribute :enabled, :default => true
attribute :zone_id, :default => -> { MiqServer.my_server.zone_id }
default_value_for :userid, "system"
default_value_for :enabled, true
default_value_for(:zone_id) { MiqServer.my_server.zone_id }

def set_start_time_and_prod_default
run_at # Internally this will correct :start_time to UTC
Expand Down
4 changes: 2 additions & 2 deletions app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class MiqServer < ApplicationRecord
before_destroy :validate_is_deleteable
after_destroy :destroy_linked_events_queue

attribute :name, :default => "EVM"
attribute :zone, :default => -> { Zone.default_zone }
default_value_for(:name, "EVM")
default_value_for(:zone) { Zone.default_zone }

scope :active_miq_servers, -> { where(:status => STATUSES_ACTIVE) }
scope :recently_active, -> { where(:last_heartbeat => 10.minutes.ago.utc...Time.now.utc) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_user_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MiqUserRole < ApplicationRecord

serialize :settings

attribute :read_only, :default => false
default_value_for :read_only, false

FIXTURE_PATH = File.join(FIXTURE_DIR, table_name)
FIXTURE_YAML = "#{FIXTURE_PATH}.yml"
Expand Down
4 changes: 2 additions & 2 deletions app/models/miq_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class MiqWidget < ApplicationRecord
include ReadOnlyMixin

attribute :enabled, :default => true
attribute :read_only, :default => false
default_value_for :enabled, true
default_value_for :read_only, false

DEFAULT_ROW_COUNT = 5
IMPORT_CLASS_NAMES = %w(MiqWidget).freeze
Expand Down
1 change: 1 addition & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Notification < ApplicationRecord
before_save :backup_subject_name

serialize :options, Hash
default_value_for(:options) { Hash.new }

validate :complete_bindings

Expand Down
2 changes: 1 addition & 1 deletion app/models/notification_recipient.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class NotificationRecipient < ApplicationRecord
belongs_to :notification
belongs_to :user
attribute :seen, :default => false
default_value_for :seen, false
virtual_column :details, :type => :string

scope :unseen, -> { where(:seen => false) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/orchestration_stack_retire_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class OrchestrationStackRetireTask < MiqRetireTask
attribute :request_type, :default => "orchestration_stack_retire"
default_value_for :request_type, "orchestration_stack_retire"

def self.base_model
OrchestrationStackRetireTask
Expand Down
4 changes: 2 additions & 2 deletions app/models/orchestration_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class OrchestrationTemplate < ApplicationRecord
has_many :stacks, :class_name => "OrchestrationStack"
has_one :picture, :dependent => :destroy, :as => :resource, :autosave => true

attribute :draft, :default => false
attribute :orderable, :default => true
default_value_for :draft, false
default_value_for :orderable, true

validates :md5,
:uniqueness_when_changed => {:scope => :draft, :message => "of content already exists (content must be unique)"},
Expand Down
2 changes: 1 addition & 1 deletion app/models/pxe_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PxeServer < ApplicationRecord

alias_attribute :description, :name

attribute :customization_directory, :default => ""
default_value_for :customization_directory, ""

serialize :visibility

Expand Down
8 changes: 4 additions & 4 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class Service < ApplicationRecord

validates :name, :presence => true

attribute :visible, :default => false
attribute :initiator, :default => 'user'
attribute :lifecycle_state, :default => 'unprovisioned'
attribute :retired, :default => false
default_value_for :visible, false
default_value_for :initiator, 'user'
default_value_for :lifecycle_state, 'unprovisioned'
default_value_for :retired, false

validates :visible, :inclusion => { :in => [true, false] }
validates :retired, :inclusion => { :in => [true, false] }
Expand Down
2 changes: 1 addition & 1 deletion app/models/service_reconfigure_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ServiceReconfigureRequest < MiqRequest
virtual_has_one :provision_dialog

default_value_for(:source_id) { |r| r.get_option(:src_id) }
attribute :source_type, :default => SOURCE_CLASS_NAME
default_value_for :source_type, SOURCE_CLASS_NAME

def my_role(_action = nil)
'ems_operations'
Expand Down
8 changes: 4 additions & 4 deletions app/models/service_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class ServiceResource < ApplicationRecord
belongs_to :resource, :polymorphic => true
belongs_to :source, :polymorphic => true

attribute :group_idx, :default => 0
attribute :scaling_min, :default => 1
attribute :scaling_max, :default => -1
attribute :provision_index, :default => 0
default_value_for :group_idx, 0
default_value_for :scaling_min, 1
default_value_for :scaling_max, -1
default_value_for :provision_index, 0

virtual_column :resource_name, :type => :string
virtual_column :resource_description, :type => :string
Expand Down
Loading