Skip to content

Commit

Permalink
Set model validation lengths based upon react form maxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Nov 11, 2024
1 parent 50ff2d0 commit d59848f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/models/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def self.new(*args, &block)
include OwnershipMixin
include TenancyMixin

validates :name, :presence => true, :length => {:maximum => 128}

belongs_to :tenant

# TODO: DELETE ME!!!!
Expand Down
2 changes: 2 additions & 0 deletions app/models/cloud_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CloudTenant < ApplicationRecord
has_many :flavors, :through => :cloud_tenant_flavors
has_many :cloud_volume_types, :through => :ext_management_system

validates :name, :length => {:maximum => 128}

alias_method :direct_cloud_networks, :cloud_networks

acts_as_miq_taggable
Expand Down
2 changes: 2 additions & 0 deletions app/models/cloud_volume_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CloudVolumeSnapshot < ApplicationRecord

virtual_total :total_based_volumes, :based_volumes

validates :description, :length => {:maximum => 50}

def self.class_by_ems(ext_management_system)
ext_management_system&.class_by_ems(:CloudVolumeSnapshot)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/generic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GenericObject < ApplicationRecord
has_one :picture, :through => :generic_object_definition
has_many :custom_button_events, :foreign_key => :target_id, :dependent => :destroy

validates :name, :presence => true
validates :name, :presence => true, :length => {:maximum => 255}

delegate :property_attribute_defined?,
:property_defined?,
Expand Down
1 change: 1 addition & 0 deletions app/models/miq_alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MiqAlert < ApplicationRecord
serialize :options

validates :description, :presence => true, :uniqueness_when_changed => true, :length => {:maximum => 255}
validates :notes, :length => {:maximum => 512}
validate :validate_automate_expressions
validate :validate_single_expression
validates :severity, :inclusion => {:in => SEVERITIES}
Expand Down
2 changes: 2 additions & 0 deletions app/models/pxe_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class PxeImage < ApplicationRecord
belongs_to :pxe_server
belongs_to :pxe_menu

validates :name, :length => {:maximum => 255}

has_many :customization_templates, :through => :pxe_image_type

acts_as_miq_taggable
Expand Down
2 changes: 2 additions & 0 deletions app/models/time_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class TimeProfile < ApplicationRecord
default_value_for :days, ALL_DAYS
default_value_for :hours, ALL_HOURS

validates :description, :length => {:maximum => 128}

has_many :miq_reports
has_many :metric_rollups

Expand Down
5 changes: 4 additions & 1 deletion app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ class VmOrTemplate < ApplicationRecord
POWER_OPS = %w[start stop suspend reset shutdown_guest standby_guest reboot_guest]
REMOTE_REGION_TASKS = POWER_OPS + %w[retire_now]

validates_presence_of :name, :location
# NOTE: different react forms set a maxLength of 50 or 128
validates :name, :presence => true, :length => {:maximum => 128}
validates :description, :presence => true, :length => {:maximum => 100}
validates :location, :presence => true
validates :vendor, :inclusion => {:in => VENDOR_TYPES.keys}

has_one :operating_system, :dependent => :destroy
Expand Down
5 changes: 2 additions & 3 deletions app/models/zone.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Zone < ApplicationRecord
validates_presence_of :name, :description
validates :name, :unique_within_region => true

serialize :settings, Hash
validates :name, :unique_within_region => true, :presence => true, :length => {:maximum => 50}
validates :description, :presence => true, :length => {:maximum => 50}

belongs_to :log_file_depot, :class_name => "FileDepot"

Expand Down

0 comments on commit d59848f

Please sign in to comment.