Fixes #38727 - Make autocompletion honor permissions#10645
Fixes #38727 - Make autocompletion honor permissions#10645ofedoren merged 1 commit intotheforeman:developfrom
Conversation
b91d00d to
7c11d64
Compare
e28b481 to
b6efee0
Compare
73cb3fd to
132f7bc
Compare
132f7bc to
932512e
Compare
|
Does this solves the following issue, too? 2 organizations: org1 and org2. Both organizations have hosts. User U has access to hosts of organization org1. So the user has the permission to to view hosts etc but only on org1. Can you maybe add such a test case? |
|
So the situation you're asking about is:
The expectation is that User U should be able to view only hosts from org1, no matter what org the org selector is set to? Doesn't this work currently? |
Sorry, the issue was pretty old that I have mixed something up. Just have retested the case:
|
Unless I took a wrong detour somewhere, the issue can be simplified t othis
This pr doesn't help with that at all, that will need to be fixed in katello. |
Well, its even worse because the user is only in org1 but can see content of org2. |
|
I'm not sure this PR does anything... While it might be my setup, it didn't fix the issue described with reproducing steps even with Katello counterpart :/ Also, should this fix also affect search in Audits page? |
From the user's point of view that's indeed worse, but including fine-grained permissions in the mix shifts the focus to a slightly different place.
I aimed to address scoping on the immediate resource
The ones in redmine? I must admit I connected a bunch of issues to this post-mortem, maybe that wasn't the wisest thing to do
That depends, what's wrong with search in audits page? |
932512e to
3360c5a
Compare
|
Alright, so I tried going about it a bit differently, this seems to work as I'd expect for foreman resources. My katello dev env got eaten while I was on pto, it will take a while to get it back up. |
|
Interestingly enough, the new approach seems to also work for katello, or at least for katello resources which include the module? |
|
Agh, it's pain to test :/ The steps from #10645 (comment) have the same result with or without the patch. Also, it's for some reason not possible to select Also, I think it's still mixes up logic: permissions vs taxonomy scoping. It's kinda hard to say whether one cannot see a resource due to perms or taxonomy. In any case, this PR doesn't solve the bug described in the issue. I'd vote for rather different approach/fix or this fix is for a different issue. |
Odd, I'm getting different behaviour. Could you double check the permission in the role doesn't have the unlimited checkbox checked (which by a different bug gets set by default). Also, there's a test which fails without the code change and passes with it so there has to be some merit to it?
If you set the context to any-any, then it should be strictly a matter of permissions. |
|
This reminds me of theforeman/foreman_monitoring#99 where we found that scoped_search doesn't take constraints into account. |
|
Ok, alternative, taxonomy-less reproducer:
Autocomplete should offer you both domains without this patch and only foo with this patch |
|
Thanks, @adamruzicka for context. This patch indeed fixes your reproducer, but I'm afraid this is still true:
This could help with the original one, but in unexpected (requires more steps) way, but didn't try it though. |
3360c5a to
424c40c
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR makes autocompletion honor user permissions by implementing permission-based filtering for autocomplete suggestions. It adds a completer_scope method to the Authorizable concern that filters results based on view permissions, and includes a test to verify that users only see autocomplete options they have permission to view.
Key Changes:
- Added
completer_scopemethod toAuthorizableconcern to filter autocomplete results by view permissions - Added test coverage to verify permission-based filtering works correctly for autocomplete functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/models/concerns/authorizable.rb | Implements completer_scope method that filters results using view permissions |
| test/controllers/concerns/auto_complete_search_test.rb | Adds test to verify autocomplete respects user permissions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
app/models/concerns/authorizable.rb
Outdated
| Thread.current[:ignore_permission_check] = original_value | ||
| end | ||
|
|
||
| def completer_scope(options) |
There was a problem hiding this comment.
The options parameter is not used in the method implementation. Consider either removing it if it's not needed, or using it to provide additional filtering capabilities for the completer scope.
| def completer_scope(options) | |
| def completer_scope |
There was a problem hiding this comment.
It is a callback from scoped search. The argument is always passed so the method needs to accept it. I can prefix it with an underscore though
424c40c to
93eebae
Compare
ofedoren
left a comment
There was a problem hiding this comment.
Thanks, @adamruzicka !
Changing the scope a bit quite helped to push this further.
I confirm that the test fails without this patch, the fix itself is only tighten to autocompletion, thus shouldn't introduce some hidden issues.
An alternative to #10197