Skip to content

Commit

Permalink
require tenant to be set on models
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Oct 16, 2015
1 parent 4e1f457 commit 8f477c3
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/ext_management_system.rb
Expand Up @@ -57,6 +57,7 @@ def self.supported_types_and_descriptions_hash
:presence => true,
:uniqueness => {:scope => [:tenant_id], :case_sensitive => false},
:if => :hostname_required?
validates :tenant_id, :presence => true

# TODO: Remove all callers of address
alias_attribute :address, :hostname
Expand Down
2 changes: 1 addition & 1 deletion app/models/miq_group.rb
Expand Up @@ -18,7 +18,7 @@ class MiqGroup < ActiveRecord::Base

delegate :self_service?, :limited_self_service?, :to => :miq_user_role, :allow_nil => true

validates_presence_of :description, :guid
validates_presence_of :description, :guid, :tenant_id
validates_uniqueness_of :description, :guid

before_destroy do |g|
Expand Down
1 change: 1 addition & 0 deletions app/models/miq_request.rb
Expand Up @@ -21,6 +21,7 @@ class MiqRequest < ActiveRecord::Base

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)
validates :tenant_id, :presence => true

validate :validate_class, :validate_request_type

Expand Down
1 change: 1 addition & 0 deletions app/models/miq_request_task.rb
Expand Up @@ -19,6 +19,7 @@ class MiqRequestTask < ActiveRecord::Base
delegate :request_class, :task_description, :to => :class

validates_inclusion_of :status, :in => %w( Ok Warn Error Timeout )
validates :tenant_id, :presence => true

include MiqRequestMixin
include TenancyMixin
Expand Down
1 change: 1 addition & 0 deletions app/models/provider.rb
Expand Up @@ -9,6 +9,7 @@ class Provider < ActiveRecord::Base
belongs_to :tenant
belongs_to :zone
has_many :managers, :class_name => "ExtManagementSystem"
validates :tenant_id, :presence => true

default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}
Expand Down
1 change: 1 addition & 0 deletions app/models/service.rb
Expand Up @@ -39,6 +39,7 @@ class Service < ActiveRecord::Base
virtual_column :has_parent, :type => :boolean

validates_presence_of :name
validates :tenant_id, :presence => true

def add_resource(rsc, options = {})
raise MiqException::Error, "Vm <#{rsc.name}> is already connected to a service." if rsc.kind_of?(Vm) && !rsc.service.nil?
Expand Down
2 changes: 2 additions & 0 deletions app/models/service_template.rb
Expand Up @@ -23,6 +23,8 @@ class ServiceTemplate < ActiveRecord::Base

has_many :dialogs, -> { uniq }, :through => :resource_actions

validates :tenant_id, :presence => true

virtual_has_many :custom_buttons
virtual_column :type_display, :type => :string
virtual_column :template_valid, :type => :boolean
Expand Down
4 changes: 2 additions & 2 deletions app/models/service_template_catalog.rb
@@ -1,8 +1,8 @@
class ServiceTemplateCatalog < ActiveRecord::Base
include ReportableMixin
include TenancyMixin
validates_presence_of :name
validates :name, :uniqueness => {:scope => :tenant_id}
validates :name, :uniqueness => {:scope => :tenant_id}, :presence => true
validates :tenant_id, :presence => true

belongs_to :tenant
has_many :service_templates, :dependent => :nullify
Expand Down
1 change: 1 addition & 0 deletions app/models/tenant_quota.rb
Expand Up @@ -35,6 +35,7 @@ class TenantQuota < ActiveRecord::Base
validates :unit, :value, :presence => true
validates :value, :numericality => {:greater_than => 0}
validates :warn_value, :numericality => {:greater_than => 0}, :if => "warn_value.present?"
validates :tenant_id, :presence => true

scope :cpu_allocated, -> { where(:name => :cpu_allocated) }
scope :mem_allocated, -> { where(:name => :mem_allocated) }
Expand Down
1 change: 1 addition & 0 deletions app/models/vm_or_template.rb
Expand Up @@ -179,6 +179,7 @@ class VmOrTemplate < ActiveRecord::Base
virtual_has_one :service, :class_name => 'Service'

before_validation :set_tenant_from_group
validates :tenant_id, :presence => true

alias_method :datastores, :storages # Used by web-services to return datastores as the property name

Expand Down
2 changes: 1 addition & 1 deletion lib/miq_automation_engine/models/miq_ae_namespace.rb
Expand Up @@ -7,7 +7,7 @@ class MiqAeNamespace < ActiveRecord::Base
has_many :ae_namespaces, :class_name => "MiqAeNamespace", :foreign_key => :parent_id, :dependent => :destroy
has_many :ae_classes, -> { includes([:ae_methods, :ae_fields, :ae_instances]) }, :class_name => "MiqAeClass", :foreign_key => :namespace_id, :dependent => :destroy

validates_presence_of :name
validates_presence_of :name, :tenant_id
validates_format_of :name, :with => /\A[A-Za-z0-9_\.\-\$]+\z/i
validates_uniqueness_of :name, :scope => :parent_id

Expand Down

0 comments on commit 8f477c3

Please sign in to comment.