Skip to content

Fixes #39761 - Add un/assign compliance policy bulk action to hosts - #623

Open
kmalyjur wants to merge 5 commits into
theforeman:masterfrom
kmalyjur:assign-policy
Open

kmalyjur wants to merge 5 commits into
theforeman:masterfrom
kmalyjur:assign-policy

Conversation

@kmalyjur

@kmalyjur kmalyjur commented Sep 14, 2026 •

Copy link
Copy Markdown

QUESTION: As you can see, the new UI is now missing the table with hosts - do you think it's important and should be added? Also, in the new UI, after submitting the modal, the hosts are still selected in the table, so the "Remember hosts selection..." tick is not needed.

Change in the behaviour when assigning a policy that is already assigned:
--- Legacy: Error: cannot assign to centos-vm.usersys.redhat.com, all assigned policies must be deployed in the same way, check 'deploy by' for each assigned policy
--- Now: Successfully assigned compliance policy to selected hosts

Legacy UI:
image

New UI:
image

@kmalyjur
kmalyjur marked this pull request as draft September 14, 2026 13:24
@kmalyjur
kmalyjur force-pushed the assign-policy branch 2 times, most recently from 7f98f1f to 1ad2a77 Compare September 14, 2026 15:11
@kmalyjur
kmalyjur marked this pull request as ready for review September 14, 2026 15:12
Comment thread webpack/components/BulkActions/compliancePolicy/BulkCompliancePolicyMenuItems.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/BulkCompliancePolicyModal.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/index.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/BulkCompliancePolicyWrapper.js Outdated
Comment thread webpack/index.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/actions.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/actions.js Outdated
Comment thread webpack/components/BulkActions/compliancePolicy/index.js Outdated

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.

I would expect some permissons check for edit_hosts before showing it in menu

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.

Other cases do not show the item in menu when user do not have the permissions, please do it in same way, having item disabled could be confusing (some of the items are disabled when it needs selection etc)

Comment thread webpack/components/BulkActions/compliancePolicy/BulkCompliancePolicyModal.js Outdated
@kmalyjur

kmalyjur commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

@Lukshio thank you, updated. I'm just unsure about the permissions. (No component in the codebase checks the edit_hosts in the frontend.)
Also, what do you think about "As you can see, the new UI is now missing the table with hosts - do you think it's important and should be added?" We can ask Maria from UX about that.

@kmalyjur
kmalyjur requested a review from Lukshio September 16, 2026 13:10
@kmalyjur

Copy link
Copy Markdown
Author

fix false success commit:
Controller returned HTTP redirects for both success and errors and showed success even when validation failed.
Solution: Detect AJAX requests (request.xhr?) and return JSON with the correct status code instead of redirects.

@Lukshio Lukshio left a comment

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.

@Lukshio thank you, updated. I'm just unsure about the permissions. (No component in the codebase checks the edit_hosts in the frontend.)

We use permission check often e.g.
https://github.com/theforeman/foreman/blob/c74b70ed8ea3d2fbdb206a636d9c528578eddc01/webpack/assets/javascripts/react_app/components/HostsIndex/index.js#L52

Also, what do you think about "As you can see, the new UI is now missing the table with hosts - do you think it's important and should be added?" We can ask Maria from UX about that.

All updated modals are without tables, so I would leave it like that

fix false success commit:
Controller returned HTTP redirects for both success and errors and showed success even when validation failed.
Solution: Detect AJAX requests (request.xhr?) and return JSON with the correct status code instead of redirects.

I would introduce new API controller, because later the legacy page will be deleted and it will be cleaner variant.

Comment on lines +13 to +14
const hasPermission =
userPermissions.has('assign_policies') && userPermissions.has('edit_hosts');

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.

Please use consts from core

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

oops I meant to change it

export const fetchPolicies = () =>
APIActions.get({
url: foremanUrl('/api/v2/compliance/policies'),
key: POLICIES_KEY,

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
key: POLICIES_KEY,
key: POLICIES_KEY,
params: { per_page: 'all' },

i would include all, I think that otherwise it will use per_page from user settings

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.

Add please new test cases

ouiaId="bulk-compliance-policy-modal-confirm-button"
variant="primary"
onClick={handleConfirm}
isDisabled={policyId === ''}

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.

Add please condition to prevent double submit

ouiaId="bulk-compliance-policy-toggle"
onClick={onToggleClick}
isExpanded={policySelectOpen}
style={{ width: '500px' }}

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.

Do not use hardcoded values

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.

Other cases do not show the item in menu when user do not have the permissions, please do it in same way, having item disabled could be confusing (some of the items are disabled when it needs selection etc)

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.

Please add test for forbidden user

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants