Skip to content

Fixes #38416 - Hosts bulk action: Assign organization and Assign location#10591

Merged
jeremylenz merged 1 commit into
theforeman:developfrom
lfu:31030_org_loc_change
Jul 22, 2025
Merged

Fixes #38416 - Hosts bulk action: Assign organization and Assign location#10591
jeremylenz merged 1 commit into
theforeman:developfrom
lfu:31030_org_loc_change

Conversation

@lfu
Copy link
Copy Markdown
Contributor

@lfu lfu commented Jul 2, 2025

Add Assign organization and Assign location for 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.

@lfu
Copy link
Copy Markdown
Contributor Author

lfu commented Jul 2, 2025

org org1 loc1

@lfu
Copy link
Copy Markdown
Contributor Author

lfu commented Jul 2, 2025

cc @ekohl @jeremylenz

@lfu lfu force-pushed the 31030_org_loc_change branch from 97ea348 to 8d4d08f Compare July 3, 2025 11:49
Copy link
Copy Markdown
Contributor

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

Tested and seems to be working well. Some comments below :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In Foreman we normally call this file index.js.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One file could have only one default export.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The file can be called whatever, no matter what the export is.

Comment on lines 32 to 34
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This tooltip is still in the wrong place. The question icon and tooltip should be next to "Fix on mismatch" and "Fail on mismatch."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Each one of them has one tooltip? Or just one next to Fail on mismatch?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const BulkAssignLocatioModalScene = () => {
const BulkAssignLocationModalScene = () => {

@lfu lfu force-pushed the 31030_org_loc_change branch 3 times, most recently from 210ed6c to bd651a8 Compare July 7, 2025 22:07
@lfu lfu force-pushed the 31030_org_loc_change branch from bd651a8 to b74b8d5 Compare July 8, 2025 15:23
@lfu lfu force-pushed the 31030_org_loc_change branch from b74b8d5 to 32a8b1e Compare July 8, 2025 16:42
ekohl
ekohl previously requested changes Jul 11, 2025
Comment on lines 125 to 154
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
end

Then inside assign_taxonomy itself:

without_taxonomy do
  # ...
end

That way the scoping is clear and you can't forget the restore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.count will always return the number of rows.
  • update_all returns the number of affected rows.
  • You can say: 0 <= affected <= number of rows. If you run update_all a second time the number of affected is 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In other words, @hosts.count is the result of update_all here if it is successful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread app/services/bulk_hosts_manager.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This ends up being a user visible message so it should be translated

@lfu
Copy link
Copy Markdown
Contributor Author

lfu commented Jul 16, 2025

Could we have some care here? Thanks!

@lfu lfu force-pushed the 31030_org_loc_change branch from 4c97321 to 0352619 Compare July 17, 2025 19:18
@LadislavVasina1
Copy link
Copy Markdown
Contributor

LadislavVasina1 commented Jul 21, 2025

@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

@LadislavVasina1
Copy link
Copy Markdown
Contributor

@lfu in the packit build I am also missing the Manage content option from the bulk actions, thus ManageContent/(Packages, Errata ,Repository sets, content source, content view environments) are missing

@LadislavVasina1
Copy link
Copy Markdown
Contributor

^^^Mentioned issues don't affect latest All hosts page redesign features though

Copy link
Copy Markdown
Contributor

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

Tested again and still works well, just a couple remaining issues

  1. Please rebase and fix lint failures
  2. Tooltips and radio buttons are not vertically aligned with text:
image

@lfu lfu force-pushed the 31030_org_loc_change branch 2 times, most recently from 56caecd to fcfd565 Compare July 21, 2025 18:10
@lfu
Copy link
Copy Markdown
Contributor Author

lfu commented Jul 21, 2025

  1. Tooltips and radio buttons are not vertically aligned with text:

@jeremylenz That was the result when alignItems: 'center'.

With alignItems: 'baseline':
baseline

Is this one looking better? Somehow the position between the button and its label was never changed.
Could you please help fine tune this?

@lfu lfu force-pushed the 31030_org_loc_change branch 2 times, most recently from b580b42 to 61dfa65 Compare July 21, 2025 20:46
@lfu lfu force-pushed the 31030_org_loc_change branch from 61dfa65 to 4030038 Compare July 21, 2025 21:32
@lfu
Copy link
Copy Markdown
Contributor Author

lfu commented Jul 22, 2025

Tests failure not related.

Copy link
Copy Markdown
Contributor

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

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

Thanks @lfu ! LGTM

@jeremylenz jeremylenz dismissed ekohl’s stale review July 22, 2025 14:58

comments were addressed

@jeremylenz jeremylenz merged commit e6d3aaa into theforeman:develop Jul 22, 2025
150 of 157 checks passed
@MariaAga
Copy link
Copy Markdown
Member

MariaAga commented Apr 29, 2026

@jeremylenz @lfu, reminder to always use specific CSS rules, as this PR changes the position of all radio inputs in foreman + plugins

Use specific css selectors to avoid conflicts with other plugins or the core.

https://theforeman.org/handbook.html

Added a fix here: #10967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants