Skip to content
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

Merged
merged 2 commits into from Sep 24, 2021

Conversation

ares
Copy link
Member

@ares ares commented Sep 7, 2021

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.

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.
@theforeman-bot
Copy link
Member

Issues: #33025

@ares
Copy link
Member Author

ares commented Sep 7, 2021

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

: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
Copy link
Member

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

Suggested change
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => :organization
scoped_search :relation => :organization, :on => :name, :complete_value => true, :rename => :organization

@ares
Copy link
Member Author

ares commented Sep 15, 2021

updated

@evgeni
Copy link
Member

evgeni commented Sep 15, 2021

no packaging ack needed.

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ares ! Nice addition.
It could be demoed together with #8767 ? :)

@ezr-ondrej ezr-ondrej merged commit f0c0fa5 into theforeman:develop Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants