foreman/app/models/taxonomies/location.rb @ be33e6e9
611f5bff | Amos Benari | class Location < Taxonomy
|
|
8b737c9c | Joseph Magen | extend FriendlyId
|
|
friendly_id :title
|
|||
611f5bff | Amos Benari | include Foreman::ThreadSession::LocationModel
|
|
e768c976 | Tomas Strachota | include Parameterizable::ByIdName
|
|
611f5bff | Amos Benari | ||
has_and_belongs_to_many :organizations
|
|||
3f77babd | Joseph Mitchell Magen | has_many_hosts :dependent => :nullify
|
|
611f5bff | Amos Benari | ||
998e1438 | Ori Rabin | has_many :location_parameters, :class_name => 'LocationParameter', :foreign_key => :reference_id, :dependent => :destroy, :inverse_of => :location
|
|
7e1f0c79 | Daniel Lobato | has_many :default_users, :class_name => 'User', :foreign_key => :default_location_id
|
|
32ced385 | Ori Rabin | accepts_nested_attributes_for :location_parameters, :allow_destroy => true
|
|
998e1438 | Ori Rabin | include ParameterValidators
|
|
2de7832d | Ohad Levy | ||
bb3572ff | Daniel Lobato | scope :completer_scope, ->(opts) { my_locations }
|
|
611f5bff | Amos Benari | ||
scope :my_locations, lambda {
|
|||
96144a47 | Daniel Lobato | conditions = User.current.admin? ? {} : sanitize_sql_for_conditions([" (taxonomies.id in (?))", User.current.location_and_child_ids])
|
|
where(conditions)
|
|||
}
|
|||
afa59582 | Ohad Levy | ||
feacea35 | Amos Benari | def dup
|
|
afa59582 | Ohad Levy | new = super
|
|
new.organizations = organizations
|
|||
new
|
|||
end
|
|||
1fa008a4 | Joseph Magen | def lookup_value_match
|
|
832c0925 | Joseph Magen | "location=#{title}"
|
|
1fa008a4 | Joseph Magen | end
|
|
def sti_name
|
|||
_("location")
|
|||
end
|
|||
611f5bff | Amos Benari | end
|