Revision 3061e381
Added by Ohad Levy over 11 years ago
- ID 3061e381a1eedeaa66f141fa198c39e12f84c05b
app/models/fact_value.rb | ||
---|---|---|
:conditions => ["fact_names.name = ?",:_timestamp]
|
||
|
||
scope :my_facts, lambda {
|
||
return { :conditions => "" } if User.current.admin? # Admin can see all hosts
|
||
|
||
{:conditions => sanitize_sql_for_conditions(
|
||
[" (fact_values.host_id in (?))",Host.my_hosts.pluck(:id)])}
|
||
if User.current.admin? and Organization.current.nil? and Location.current.nil?
|
||
{ :conditions => "" }
|
||
else
|
||
#TODO: Remove pluck after upgrade to newer rails as it would be
|
||
#done via INNER select automatically
|
||
where(:fact_values => {:host_id => Host.my_hosts.pluck(:id)})
|
||
end
|
||
}
|
||
|
||
scope :distinct, { :select => 'DISTINCT "fact_values.value"' }
|
app/models/report.rb | ||
---|---|---|
|
||
# returns reports for hosts in the User's filter set
|
||
scope :my_reports, lambda {
|
||
return { :conditions => "" } if User.current.admin? # Admin can see all hosts
|
||
|
||
conditions = sanitize_sql_for_conditions([" (reports.host_id in (?))", Host.my_hosts.pluck(:id)])
|
||
conditions.sub!(/\s*\(\)\s*/, "")
|
||
conditions.sub!(/^(?:\(\))?\s?(?:and|or)\s*/, "")
|
||
conditions.sub!(/\(\s*(?:or|and)\s*\(/, "((")
|
||
{:conditions => conditions}
|
||
if User.current.admin? and Organization.current.nil? and Location.current.nil?
|
||
{ :conditions => "" }
|
||
else
|
||
#TODO: Remove pluck after upgrade to newer rails as it would be
|
||
#done via INNER select automatically
|
||
where(:reports => {:host_id => Host.my_hosts.pluck(:id)})
|
||
end
|
||
}
|
||
|
||
# returns recent reports
|
Also available in: Unified diff
fixes #2084 - All Facts and Reports are visible regardless of selected Org/Location for admin users