Fixes #38416 - Hosts bulk action: Assign organization and Assign location#10591
Conversation
jeremylenz
left a comment
There was a problem hiding this comment.
Tested and seems to be working well. Some comments below :)
There was a problem hiding this comment.
In Foreman we normally call this file index.js.
There was a problem hiding this comment.
One file could have only one default export.
There was a problem hiding this comment.
The file can be called whatever, no matter what the export is.
There was a problem hiding this comment.
This tooltip is still in the wrong place. The question icon and tooltip should be next to "Fix on mismatch" and "Fail on mismatch."
There was a problem hiding this comment.
Each one of them has one tooltip? Or just one next to Fail on mismatch?
There was a problem hiding this comment.
Ideally there would be one tooltip next to Fix on mismatch, explaining Fix on mismatch, and one tooltip next to Fail on mismatch, explaining Fail on mismatch.
There was a problem hiding this comment.
| const BulkAssignLocatioModalScene = () => { | |
| const BulkAssignLocationModalScene = () => { |
210ed6c to
bd651a8
Compare
There was a problem hiding this comment.
Not insisting on this, but it may be a good chance to clean this up and rewrite clear_current_taxonomy and restore_current_taxonomy into a single method:
def without_taxonomy
context = nil # to ensure the variable exists
context = Foreman::ThreadSession::Context.get
Foreman::ThreadSession::Context.set(user: context[:user])
yield
ensure
Foreman::ThreadSession::Context.set(**context) if context
endThen inside assign_taxonomy itself:
without_taxonomy do
# ...
endThat way the scoping is clear and you can't forget the restore.
There was a problem hiding this comment.
I have not seen a good argument why you use @hosts.count instead of letting assign_taxonomy return the number of affected rows. I started that discussion in #10538 (comment) and thought you'd use the separation to easily implement that.
Please make the change I suggested. Summarizing what I said earlier:
@hosts.countwill always return the number of rows.update_allreturns the number of affected rows.- You can say:
0 <= affected <= number of rows. If you runupdate_alla second time the number of affected is 0.
There was a problem hiding this comment.
[17] pry(main)> Host.update_all(organization_id: 1)
=> 14
[18] pry(main)> Host.update_all(organization_id: 1)
=> 14
[19] pry(main)> Host.update_all(organization_id: 1)
=> 14
[20] pry(main)> Host.update_all(organization_id: 1)
=> 14
There was a problem hiding this comment.
Instead of showing how many hosts are updated in a popup, we could display how many hosts are selected in the modal itself. I prefer the modal approach.
I need the ForemanActionsBarContext.Provider change in #10560 to display the selected hosts in the modal. Any chance to merge that PR first?
There was a problem hiding this comment.
I'm still going to insist that you don't use @hosts.count but rather use the result of update_all. Making BulkHostsManager responsible for that is IMHO a cleaner abstraction and it saves a query. I don't understand why you resist that.
There was a problem hiding this comment.
@hosts.update_all(organization_id: 1) would always update all of them. That is @hosts.count if the command is successful.
Otherwise it would throw an error if it fails.
We don't need to do it as you suggested that is unnecessary.
There was a problem hiding this comment.
In other words, @hosts.count is the result of update_all here if it is successful.
There was a problem hiding this comment.
You can say: 0 <= affected <= number of rows. If you run update_all a second time the number of affected is 0.
This is not right. It is either @hosts.count or an error we would catch.
There was a problem hiding this comment.
The taxonomy will be untranslated now.
Also I think this should use render_error, probably with a 404 error. When you implement that, please also document it with error 404, 'the description here' so it ends up in the API documentation.
There was a problem hiding this comment.
I think the whole method will be easier if you rewrite this to separate API paths. So assign_organization and assign_location. Most lines within this are simply there to support 2 different types, but as you can see in the translations that very quickly gets messy.
There was a problem hiding this comment.
This ends up being a user visible message so it should be translated
32a8b1e to
05b6b5a
Compare
05b6b5a to
4c97321
Compare
|
Could we have some care here? Thanks! |
4c97321 to
0352619
Compare
|
@lfu Hi, I have tried getting the packit build of this PR, and I have found out that the ManageColumns button is missing in the "New UI" of the All hosts page |
|
@lfu in the packit build I am also missing the |
|
^^^Mentioned issues don't affect latest All hosts page redesign features though |
56caecd to
fcfd565
Compare
@jeremylenz That was the result when Is this one looking better? Somehow the position between the button and its label was never changed. |
b580b42 to
61dfa65
Compare
61dfa65 to
4030038
Compare
|
Tests failure not related. |
|
@jeremylenz @lfu, reminder to always use specific CSS rules, as this PR changes the position of all radio inputs in foreman + plugins
https://theforeman.org/handbook.html Added a fix here: #10967 |





Add
Assign organizationandAssign locationfor new hosts page.Replace #10538.
To test
Select hosts - Change associations - select Organization or Location from Kebab menu.
Some test cases.
Prepare a testing environment with hosts, both registered and unregistered. Multiple organizations and locations.
Move one host/multiple hosts from a current organization to another. Error message for registered hosts.
Move one host/multiple hosts from a current location to another.
Repeat above tests with Any Organization and Any Location context.
Registered hosts are not allowed to change organization. All other cases should work.
Tests for registered hosts need Katello/katello#11396.