New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #33025 - allow filtering hosts by user id #8767
Conversation
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.
Issues: #33025 |
rubocop complains about the line I haven't touched, I added a second commit that fixes the spacing, but of course is unrelated, it should be kept separate on merge if we decide to cherry-pick the first definition |
app/models/report.rb
Outdated
: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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've missed one and now rubocop doesn't like it when it's not aligned with others
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => :organization | |
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => :organization |
updated |
no packaging ack needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.