Revision 8915e45f
Added by Marek Hulán over 2 years ago
app/models/report.rb | ||
---|---|---|
has_many :messages, :through => :logs
|
||
has_many :sources, :through => :logs
|
||
has_one :hostgroup, :through => :host
|
||
has_one :host_owner, through: :host, source: :owner, source_type: 'User'
|
||
|
||
has_one :organization, :through => :host
|
||
has_one :location, :through => :host
|
||
... | ... | |
def self.inherited(child)
|
||
child.instance_eval do
|
||
scoped_search :relation => :host, :on => :name, :complete_value => true, :rename => :host
|
||
scoped_search :relation => :host_owner,
|
||
:on => :id,
|
||
:complete_value => true,
|
||
:rename => :host_owner_id,
|
||
:only_explicit => true,
|
||
:validator => ->(value) { ScopedSearch::Validators::INTEGER.call(value) },
|
||
:value_translation => ->(value) { value == 'current_user' ? User.current.id : value },
|
||
:special_values => %w[current_user]
|
||
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => :organization
|
||
scoped_search :relation => :location, :on => :name, :complete_value => true, :rename => :location
|
||
scoped_search :relation => :messages, :on => :value, :rename => :log, :only_explicit => true
|
Also available in: Unified diff
Fixes #33025 - allow filtering hosts by user id
Users would like to set filters so users can only see reports of hosts
they own.
For that we can define an association on a Report based on the Host
ownership. Then we can add a scoped search definition that could be used
in Filter definition. The resulting scoped search term that can be used
on any Report subclass is
```
host_owner_id = current_user
```
Instead of `current_user`, a specific user ID can be used too.
This will not take user group ownership into the consideration due to
the complexity, especially when tree structure of user groups is
considered.